debian-mirror-gitlab/lib/gitlab/request_context.rb

36 lines
896 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
class RequestContext
class << self
def client_ip
2018-12-05 23:21:45 +05:30
Gitlab::SafeRequestStore[:client_ip]
2017-08-17 22:00:37 +05:30
end
2019-12-21 20:55:43 +05:30
def start_thread_cpu_time
Gitlab::SafeRequestStore[:start_thread_cpu_time]
end
2017-08-17 22:00:37 +05:30
end
def initialize(app)
@app = app
end
def call(env)
2019-05-03 19:53:19 +05:30
# We should be using ActionDispatch::Request instead of
# Rack::Request to be consistent with Rails, but due to a Rails
# bug described in
2019-12-04 20:38:33 +05:30
# https://gitlab.com/gitlab-org/gitlab-foss/issues/58573#note_149799010
2019-05-03 19:53:19 +05:30
# hosts behind a load balancer will only see 127.0.0.1 for the
# load balancer's IP.
req = Rack::Request.new(env)
2017-08-17 22:00:37 +05:30
2018-12-05 23:21:45 +05:30
Gitlab::SafeRequestStore[:client_ip] = req.ip
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
Gitlab::SafeRequestStore[:start_thread_cpu_time] = Gitlab::Metrics::System.thread_cpu_time
2017-08-17 22:00:37 +05:30
@app.call(env)
end
end
end