Skip to content

Commit

Permalink
Added a no_decoding option to prevent automatically inflating the G…
Browse files Browse the repository at this point in the history
…Zip or Deflate response.
  • Loading branch information
mathieuravaux committed May 9, 2011
1 parent 2712fbe commit e6bdf47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/em-http/client.rb
Expand Up @@ -257,7 +257,7 @@ def parse_response_header(header, version, status)
@state = :body
end

if decoder_class = HttpDecoders.decoder_for_encoding(response_header[CONTENT_ENCODING])
if !@req.no_decoding && decoder_class = HttpDecoders.decoder_for_encoding(response_header[CONTENT_ENCODING])
begin
@content_decoder = decoder_class.new do |s| on_decoded_body_data(s) end
rescue HttpDecoders::DecoderError
Expand Down
3 changes: 2 additions & 1 deletion lib/em-http/http_client_options.rb
@@ -1,7 +1,7 @@
class HttpClientOptions
attr_reader :uri, :method, :host, :port, :proxy
attr_reader :headers, :file, :body, :query, :path
attr_reader :keepalive, :pass_cookies
attr_reader :keepalive, :pass_cookies, :no_decoding

attr_accessor :followed, :redirects

Expand All @@ -21,6 +21,7 @@ def initialize(uri, options, method)

@pass_cookies = options[:pass_cookies]
@pass_cookies = true if @pass_cookies.nil?
@no_decoding = options[:no_decoding] || false

set_uri(uri)
end
Expand Down
20 changes: 20 additions & 0 deletions spec/client_spec.rb
Expand Up @@ -324,6 +324,26 @@ def failed(http=nil)
}
end

it "should not decode the response when configured so" do
EventMachine.run {

http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/gzip').get :head => {
"accept-encoding" => "gzip, compressed"
}, :no_decoding => true

http.errback { failed(http) }
http.callback {
http.response_header.status.should == 200
http.response_header["CONTENT_ENCODING"].should == "gzip"

raw = http.response
Zlib::GzipReader.new(StringIO.new(raw)).read.should == "compressed"

EventMachine.stop
}
}
end

it "should timeout after 0.1 seconds of inactivity" do
EventMachine.run {
t = Time.now.to_i
Expand Down

0 comments on commit e6bdf47

Please sign in to comment.