summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-02-05 17:18:33 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-02-05 17:18:33 +1300
commitf43537ac70d29b7ef6572c9c16dc717aa3eaa319 (patch)
tree6e11f77203bcbcf9f7f4327f1bb727fa2499b519
parentd4bb19862643f7ec8d47d5a4fc716aff8af63e69 (diff)
downloadrack-f43537ac70d29b7ef6572c9c16dc717aa3eaa319.tar.gz
Use `Utils::HeaderHash` to add to existing headers. Fixes #1222.
-rw-r--r--lib/rack/runtime.rb4
-rw-r--r--test/spec_runtime.rb6
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/rack/runtime.rb b/lib/rack/runtime.rb
index a0f8ac7f..d9b2d8ed 100644
--- a/lib/rack/runtime.rb
+++ b/lib/rack/runtime.rb
@@ -20,9 +20,11 @@ module Rack
def call(env)
start_time = Utils.clock_time
status, headers, body = @app.call(env)
+ headers = Utils::HeaderHash[headers]
+
request_time = Utils.clock_time - start_time
- unless headers.has_key?(@header_name)
+ unless headers.key?(@header_name)
headers[@header_name] = FORMAT_STRING % request_time
end
diff --git a/test/spec_runtime.rb b/test/spec_runtime.rb
index 10c0c382..e4fc3f95 100644
--- a/test/spec_runtime.rb
+++ b/test/spec_runtime.rb
@@ -11,6 +11,12 @@ describe Rack::Runtime do
Rack::MockRequest.env_for
end
+ it "works even if headers is an array" do
+ app = lambda { |env| [200, [['Content-Type', 'text/plain']], "Hello, World!"] }
+ response = runtime_app(app).call(request)
+ response[1]['X-Runtime'].must_match(/[\d\.]+/)
+ end
+
it "sets X-Runtime is none is set" do
app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, "Hello, World!"] }
response = runtime_app(app).call(request)