Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers not send #40

Closed
zash80 opened this issue May 2, 2013 · 7 comments
Closed

Headers not send #40

zash80 opened this issue May 2, 2013 · 7 comments
Assignees

Comments

@zash80
Copy link

zash80 commented May 2, 2013

Having following service:

angular.module('app.services', []).
    factory('TestService', ['Restangular', function (restangular) {
        var testResource = restangular.all('tests');

        return {
            getTests: function () {
                return testsResource.getList({}, {'name': 'value'});
            },
            getTest: function (testID) {
                return restangular.one('tests', testID).get({}, {'name': 'value'});
            }
        };
    }]);

If calling getTests or getTest I assume the header is set but it isn't. Am I doing something wrong?

@mgonto
Copy link
Owner

mgonto commented May 2, 2013

Hey,

What Angular version are you using?

Headers support in $resource was added since version 1.1.4, so if you're using a version before that one, headers won't be sent as Restangular depends on $resource.

Check angular/angular.js#965

Thanks!

@ghost ghost assigned mgonto May 2, 2013
@mgonto
Copy link
Owner

mgonto commented May 3, 2013

Otherwise, if all the headers are always the same, you can use $httpProvider which works since always :)

https://github.com/mgonto/restangular#i-need-to-send-one-header-in-every-restangular-request-how-do-i-do-this

@zash80
Copy link
Author

zash80 commented May 3, 2013

I was using angular 1.0.6 and also tried the second option to mention. I now switched to 1.1.4 and it works smoothly. Thanks for pointing this out.

@zash80 zash80 closed this as completed May 3, 2013
@mgonto
Copy link
Owner

mgonto commented May 3, 2013

No problem! Thanks for using the library :)

@LarryEitel
Copy link

I am using latest 1.1.4. Here is a stub of .config. Trying without success to send a custom header.

angular.module('restangular-sample', [ 'restangular' ])
    .config(['RestangularProvider', '$httpProvider', 
        function(RestangularProvider, $httpProvider) {
            $httpProvider.defaults.headers.get = {};
            $httpProvider.defaults.headers.get['Authorization'] = 'Basic admin@orgtec.com:xxxxxx';

            RestangularProvider.setBaseUrl('http://exi.xchg.com/api');
            RestangularProvider.setListTypeIsArray(false);
            RestangularProvider.setResponseExtractor(function(response, operation, what) {
                if (operation === 'get') {
                    return response;
                } else if (operation === 'getList') {
                    return response._items;
                }
            });
        } ]);

I look at fiddler to see what was sent and it added:

Access-Control-Request-Headers: accept, authorization, origin
Access-Control-Request-Method: GET

And it turned the method from GET to OPTION.

@mgonto
Copy link
Owner

mgonto commented May 9, 2013

That's actually Angular's code, not mine, so I don't know why it's not working for you in that case. You should open an Issue in Angular's GitHub.

Otherwise, You can try sending the headers in every Restangular request:

$scope.venue = Restangular.one("venues", $scope.venueId).get(params, {'x-gonto': 'hey'});

That will send the header x-gonto only for that particular request. Anyway, $httpProvider.defaults.headers.... should work as well.

@mgonto
Copy link
Owner

mgonto commented May 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants