mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.87k stars 840 forks source link

Can't get response.headers("authorization") with setFullResponse(true) #1263

Open Ouadie opened 8 years ago

Ouadie commented 8 years ago

I added Restangular.setFullResponse(true); and I can't get all the headers from the response.

Here is my config:

angular.module('MyWebsite')
 .factory('MyWebsiteApiRestangular', function (Restangular, transformersFactory, store) {
    return Restangular.withConfig(function(RestangularConfigurer) {
        RestangularConfigurer.setBaseUrl('http://127.0.0.1/MyWebsite'); 
        RestangularConfigurer.setDefaultHeaders({Authorization: 'Bearer ' + store.get('token')});

        RestangularConfigurer.setFullResponse(true);

        RestangularConfigurer.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
            var token = response.headers("authorization");
            // ...
        });

        // ...

And here is the response of my web server: OPTIONS http://127.0.0.1/MyWebsite/item/1

access-control-allow-methods: GET, POST, PUT, DELETE access-control-allow-headers: ACCEPT, AUTHORIZATION access-control-allow-origin: http://127.0.0.1/MyWebsite

GET http://127.0.0.1/MyWebsite/item/1

Authorization: Bearer ThisIsMyToken Access-Control-Allow-Origin: http://localhost:9000

0redd commented 8 years ago

I have the same problem, is it a restangular issue?

shiruken1 commented 8 years ago

Same here, although I'm getting response.headers is not a function. Response.headers returns undefined.