aff2b6e4eb
As mentioned in https://gitlab.com/gitlab-org/gitlab-ee/issues/9035#note_129093444, Rails 5 switched ActionDispatch::Request so that it no longer inherits Rack::Request directly. A middleware that uses Rack::Request to read the environment may see stale request parameters if another middleware modifies the environment via ActionDispatch::Request. To be safe, we should be using ActionDispatch::Request everywhere.
23 lines
376 B
Ruby
23 lines
376 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
class RequestContext
|
|
class << self
|
|
def client_ip
|
|
Gitlab::SafeRequestStore[:client_ip]
|
|
end
|
|
end
|
|
|
|
def initialize(app)
|
|
@app = app
|
|
end
|
|
|
|
def call(env)
|
|
req = ActionDispatch::Request.new(env)
|
|
|
|
Gitlab::SafeRequestStore[:client_ip] = req.ip
|
|
|
|
@app.call(env)
|
|
end
|
|
end
|
|
end
|