Skip to content

Commit

Permalink
Fix regression in middleware to support pre-Rack 3.x header key format (
Browse files Browse the repository at this point in the history
  • Loading branch information
abrom authored Jan 31, 2025
1 parent db1c420 commit ff760bb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/grover/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def ignore_request?
end

def html_content?(headers)
headers['content-type'] =~ %r{text/html|application/xhtml\+xml}
headers[lower_case_headers? ? 'content-type' : 'Content-Type'] =~ %r{text/html|application/xhtml\+xml}
end

def update_response(response, headers)
Expand Down Expand Up @@ -155,11 +155,12 @@ def fetch_cover_pdf(path)

def assign_headers(headers, body, content_type)
# Do not cache results
headers.delete 'etag'
headers.delete 'cache-control'
headers.delete(lower_case_headers? ? 'etag' : 'ETag')
headers.delete(lower_case_headers? ? 'cache-control' : 'Cache-Control')

headers['content-length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers['content-type'] = content_type
headers[lower_case_headers? ? 'content-length' : 'Content-Length'] =
(body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers[lower_case_headers? ? 'content-type' : 'Content-Type'] = content_type
end

def configure_env_for_grover_request(env)
Expand Down Expand Up @@ -223,5 +224,11 @@ def scrub_env!(env)
env.delete 'CONTENT_LENGTH'
env.delete 'RAW_POST_DATA'
end

def lower_case_headers?
return @lower_case_headers if defined? @lower_case_headers

@lower_case_headers = Gem::Version.new(Rack.release) >= Gem::Version.new('3')
end
end
end

0 comments on commit ff760bb

Please sign in to comment.