Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-10-30 23:06:08 +0300
committerMike Greiling <mike@pixelcog.com>2017-10-30 23:14:25 +0300
commit5445f839e8a1f8bb6ff1a3cf68c3b5d59f3681bc (patch)
treef1b1218c382c1577b0db813d3a6603f507e5b5e8 /lib/gitlab/testing
parente0ca65c5144d4f6de91e3c808437bd85c0323b14 (diff)
allow inspect_request to inject request headers in order to test Sendfile requests in jobs_spec.rb
Diffstat (limited to 'lib/gitlab/testing')
-rw-r--r--lib/gitlab/testing/request_inspector_middleware.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/gitlab/testing/request_inspector_middleware.rb b/lib/gitlab/testing/request_inspector_middleware.rb
index a5ac800c735..27fff061c7d 100644
--- a/lib/gitlab/testing/request_inspector_middleware.rb
+++ b/lib/gitlab/testing/request_inspector_middleware.rb
@@ -5,9 +5,11 @@ module Gitlab
class RequestInspectorMiddleware
@@log_requests = Concurrent::AtomicBoolean.new(false)
@@logged_requests = Concurrent::Array.new
+ @@inject_headers = Concurrent::Hash.new
# Resets the current request log and starts logging requests
- def self.log_requests!
+ def self.log_requests!(headers = {})
+ @@inject_headers.replace(headers)
@@logged_requests.replace([])
@@log_requests.value = true
end
@@ -29,6 +31,7 @@ module Gitlab
return @app.call(env) unless @@log_requests.true?
url = env['REQUEST_URI']
+ env.merge! http_headers_env(@@inject_headers) if @@inject_headers.any?
request_headers = env_http_headers(env)
status, headers, body = @app.call(env)
@@ -53,6 +56,13 @@ module Gitlab
.flatten]
end
+ def http_headers_env(headers)
+ Hash[*headers
+ .collect {|k, v| [k.split('-').collect(&:upcase).join('_'), v]}
+ .collect {|k, v| [k.prepend('HTTP_'), v]}
+ .flatten]
+ end
+
def log_request(response)
@@logged_requests.push(response)
end