Skip to content

Commit

Permalink
Allow indifferent access to response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdrkeene committed Sep 15, 2011
1 parent d881de9 commit 72eeebc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/em-http/http_header.rb
Expand Up @@ -52,5 +52,9 @@ def compressed?
def location
self[HttpClient::LOCATION]
end

def [](key)
super(key) || super(key.upcase.gsub('-','_'))
end
end
end
30 changes: 30 additions & 0 deletions spec/client_spec.rb
Expand Up @@ -687,4 +687,34 @@ def failed(http=nil)
}
}
end

it "should allow indifferent access to headers" do
EventMachine.run {
response =<<-HTTP.gsub(/^ +/, '').strip
HTTP/1.0 200 OK
Content-Type: text/plain; charset=utf-8
X-Custom-Header: foo
Content-Length: 5
Connection: close
Hello
HTTP

@s = StubServer.new(response)
http = EventMachine::HttpRequest.new('http://127.0.0.1:8081/').get
http.errback { failed(http) }
http.callback {
http.response_header["Content-Type"].should == "text/plain; charset=utf-8"
http.response_header["CONTENT_TYPE"].should == "text/plain; charset=utf-8"

http.response_header["Content-Length"].should == "5"
http.response_header["CONTENT_LENGTH"].should == "5"

http.response_header["X-Custom-Header"].should == "foo"
http.response_header["X_CUSTOM_HEADER"].should == "foo"

EventMachine.stop
}
}
end
end

0 comments on commit 72eeebc

Please sign in to comment.