Skip to content

Commit

Permalink
Use factory proc to construct transform headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cyu committed Mar 17, 2023
1 parent 8e9701c commit a53de88
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/rack/cors/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def to_headers(env)
'access-control-max-age' => max_age.to_s
}
h['access-control-allow-credentials'] = 'true' if credentials
defined?(Rack::Utils::HeaderHash) ? Rack::Utils::HeaderHash.new(h) : h
header_proc.call(h)
end

protected
Expand Down Expand Up @@ -127,6 +127,16 @@ def compile(path)
raise TypeError, path
end
end

def header_proc
@header_proc ||= begin
if defined?(Rack::Headers)
->(h) { h }
else
->(h) { Rack::Utils::HeaderHash.new(h) }
end
end
end
end
end
end

0 comments on commit a53de88

Please sign in to comment.