Skip to content

Commit

Permalink
Use Utils::HeaderHash to add to existing headers. Fixes #1222.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 5, 2020
1 parent d4bb198 commit f43537a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rack/runtime.rb
Expand Up @@ -20,9 +20,11 @@ def initialize(app, name = nil)
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

Expand Down
6 changes: 6 additions & 0 deletions test/spec_runtime.rb
Expand Up @@ -11,6 +11,12 @@ def request
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)
Expand Down

0 comments on commit f43537a

Please sign in to comment.