Question

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/")

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top