Skip to content

Commit

Permalink
normalize headers from a proxied request so that rack doesnt choke on…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
nhemsley committed Feb 21, 2014
1 parent 43daaea commit 8b8601a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/rack/proxy.rb
Expand Up @@ -24,6 +24,13 @@ def extract_http_request_headers(env)
headers.merge!("X-Forwarded-For" => x_forwarded_for)
end

def normalize_headers(headers)
mapped = headers.map do|k, v|
[k, if v.is_a? Array then v.first else v end]
end
Hash[mapped]
end

protected

def reconstruct_header_name(name)
Expand Down Expand Up @@ -97,7 +104,7 @@ def perform_request(env)
end
end

headers = (target_response.respond_to?(:headers) && target_response.headers) || target_response.to_hash
headers = (target_response.respond_to?(:headers) && target_response.headers) || self.class.normalize_headers(target_response.to_hash)
body = target_response.body
body = [body] unless body.respond_to?(:each)

Expand Down

0 comments on commit 8b8601a

Please sign in to comment.