Skip to content
Browse files

Expose raw response headers

Useful for use in a reverse proxy
  • Loading branch information...
1 parent f090f4b commit 1aab16193b9f0827aa63b09d36a73cd060626fca Daniel Farrell committed
Showing with 23 additions and 0 deletions.
  1. +1 −0 lib/em-http/client.rb
  2. +3 −0 lib/em-http/http_header.rb
  3. +14 −0 spec/client_spec.rb
  4. +5 −0 spec/stallion.rb
View
1 lib/em-http/client.rb
@@ -218,6 +218,7 @@ def on_decoded_body_data(data)
end
def parse_response_header(header, version, status)
+ @response_header.raw = header
header.each do |key, val|
@response_header[key.upcase.gsub('-','_')] = val
end
View
3 lib/em-http/http_header.rb
@@ -11,6 +11,9 @@ class HttpResponseHeader < Hash
# The status code (as a string!)
attr_accessor :http_status
+ # Raw headers
+ attr_accessor :raw
+
# E-Tag
def etag
self[HttpClient::ETAG]
View
14 spec/client_spec.rb
@@ -356,6 +356,20 @@ def failed(http=nil)
}
end
+ it "should return raw headers in a hash" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/echo_headers').get
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header.raw['Set-Cookie'].should match('test=yes')
+ http.response_header.raw['X-Forward-Host'].should match('proxy.local')
+ EventMachine.stop
+ }
+ }
+ end
+
it "should detect deflate encoding" do
EventMachine.run {
View
5 spec/stallion.rb
@@ -85,6 +85,11 @@ def self.call(env)
stable.response["Last-Modified"] = "Fri, 13 Aug 2010 17:31:21 GMT"
stable.response.write stable.request.query_string
+ elsif stable.request.path_info == '/echo_headers'
+ stable.response["Set-Cookie"] = "test=yes"
+ stable.response["X-Forward-Host"] = "proxy.local"
+ stable.response.write stable.request.query_string
+
elsif stable.request.path_info == '/echo_content_length'
stable.response.write stable.request.content_length

0 comments on commit 1aab161

Please sign in to comment.
Something went wrong with that request. Please try again.