2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-06 07:48:46 -05:00
|
|
|
module Gitlab
|
|
|
|
class RequestContext
|
|
|
|
class << self
|
|
|
|
def client_ip
|
2018-09-20 18:40:15 -04:00
|
|
|
Gitlab::SafeRequestStore[:client_ip]
|
2017-02-06 07:48:46 -05:00
|
|
|
end
|
2019-10-17 14:08:05 -04:00
|
|
|
|
|
|
|
def start_thread_cpu_time
|
|
|
|
Gitlab::SafeRequestStore[:start_thread_cpu_time]
|
|
|
|
end
|
2017-02-06 07:48:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2019-03-12 14:22:29 -04:00
|
|
|
# We should be using ActionDispatch::Request instead of
|
|
|
|
# Rack::Request to be consistent with Rails, but due to a Rails
|
|
|
|
# bug described in
|
2019-09-18 10:02:45 -04:00
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/58573#note_149799010
|
2019-03-12 14:22:29 -04:00
|
|
|
# hosts behind a load balancer will only see 127.0.0.1 for the
|
|
|
|
# load balancer's IP.
|
|
|
|
req = Rack::Request.new(env)
|
2017-02-06 07:48:46 -05:00
|
|
|
|
2018-09-20 18:40:15 -04:00
|
|
|
Gitlab::SafeRequestStore[:client_ip] = req.ip
|
2017-02-06 07:48:46 -05:00
|
|
|
|
2019-10-17 14:08:05 -04:00
|
|
|
Gitlab::SafeRequestStore[:start_thread_cpu_time] = Gitlab::Metrics::System.thread_cpu_time
|
|
|
|
|
2017-02-06 07:48:46 -05:00
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
2017-02-16 05:21:30 -05:00
|
|
|
end
|