rails/turbolinks — pull request #183 by reednj77 (2013-02-13 01:31:53+00:00)
Title: Reflect X-XHR-Referer in request.referer - closes #169

This is an implementation of the idea proposed in #169. It ensures that `request.referer` returns the expected url.

The existing `referer` method is defined on Rack::Request:

```ruby
module Rack
class Request
def referer
@env['HTTP_REFERER']
end
alias referrer referer
end
end
```

This patch defines a `referer` method on ActionDispatch::Request that will return the value of the `X-XHR-Referer` request header if it exists and falls back to the original method if it doesn't:

```ruby
module ActionDispatch
class Request < Rack::Request
def referer
self.headers['X-XHR-Referer'] || super
end
alias referrer referer
end
end
```