Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Setting correct 'Referer' header for $http

It looks like when you send off a request using the $http service, the referer header is set to the base url without the angular $location information.

How do you go about appending the $location.path() to that header for all requests?

Our API calls will log that referer header when an error occurs; however, it would be very helpful if we could store the user's actual location ("stackoverflow.com/#/question/1234" opposed to just "stackoverflow.com/")

like image 719
John Avatar asked Mar 24 '14 16:03

John


1 Answers

I ended up just doing something like this:

$httpProvider.interceptors.push(function ($location) {
    return {
        request: function (config) {
            config.headers["RefererFullUrl"] = $location.absUrl();
            return config;
        }
    };
});

It doesn't look like the browsers are too happy if you try to change the 'referer' url, so I'm just naming it something else, and looking for that header specifically on the server

like image 98
John Avatar answered Sep 28 '22 07:09

John