6

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

John
  • 17,163
  • 16
  • 65
  • 83
  • But that's *not* the script's actual location; that's just what's displayed in the location bar. It's the variables that are causing the error, so you need to log those as well. – Blazemonger Mar 24 '14 at 16:32
  • All parameters are being logged; however, it would be nice to have the url ready to go opposed to trying to reverse engineer where the user was based off the parameters – John Mar 24 '14 at 17:18
  • Perhaps you can pass the perceived URL as a parameter, then? – Blazemonger Mar 24 '14 at 17:57

1 Answers1

5

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

John
  • 17,163
  • 16
  • 65
  • 83