Skip to content

Commit

Permalink
Simplify HTTP header extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs authored and ian-plosker committed Sep 10, 2011
1 parent 56cb86a commit 83fbecf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/webmachine/adapters/mongrel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def self.run

class Handler < ::Mongrel::HttpHandler
def process(wreq, wres)
header = Webmachine::Headers.new
header.replace(http_headers wreq)
header = http_headers(wreq.params, Webmachine::Headers.new)

request = Webmachine::Request.new(wreq.params["REQUEST_METHOD"],
URI.parse(wreq.params["REQUEST_URI"]),
Expand Down Expand Up @@ -62,11 +61,13 @@ def process(wreq, wres)
end
end

def http_headers(wreq)
wreq.params.select{ |k,v| k.start_with? "HTTP_" }.inject({}) { |h, (k,v)|
h[k.sub(/^HTTP_/, "").sub("_", "-")] = v
def http_headers(env, headers)
env.inject(headers) do |h,(k,v)|
if k =~ /^HTTP_(\w+)$/
h[$1.tr("_", "-")] = v
end
h
}
end
end
end
end
Expand Down

0 comments on commit 83fbecf

Please sign in to comment.