Skip to content

Commit

Permalink
encoding-support related fixes:
Browse files Browse the repository at this point in the history
- CURLOPT_ENCODING value corrected
- initialization corrected
- specs added to make sure it works properly
  • Loading branch information
morhekil committed Jul 16, 2010
1 parent 8f284b6 commit dc59505
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/typhoeus/easy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Easy
:CURLOPT_PROXY => 10004,
:CURLOPT_VERIFYPEER => 64,
:CURLOPT_NOBODY => 44,
:CURLOPT_ENCODING => 102,
:CURLOPT_ENCODING => 10000 + 102,
:CURLOPT_SSLCERT => 10025,
:CURLOPT_SSLCERTTYPE => 10086,
:CURLOPT_SSLKEY => 10087,
Expand All @@ -57,7 +57,8 @@ def initialize
@method = :get
@headers = {}

set_option(OPTION_VALUES[:CURLOPT_ENCODING], 'zlib') if supports_zlib?
# Enable encoding/compression support
set_option(OPTION_VALUES[:CURLOPT_ENCODING], '')
end

def headers=(hash)
Expand Down
10 changes: 10 additions & 0 deletions spec/servers/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rubygems'
require 'sinatra'
require 'json'
require 'zlib'

@@fail_count = 0
get '/fail/:number' do
Expand Down Expand Up @@ -48,6 +49,15 @@
throw(:halt, [401, "Not authorized\n"]) if !is_ntlm_auth
end

get '/gzipped' do
req_env = request.env.to_json
z = Zlib::Deflate.new
gzipped_env = z.deflate(req_env, Zlib::FINISH)
z.close
response['Content-Encoding'] = 'gzip'
gzipped_env
end

get '/**' do
sleep params["delay"].to_i if params.has_key?("delay")
request.env.merge!(:body => request.body.read).to_json
Expand Down
15 changes: 14 additions & 1 deletion spec/typhoeus/easy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,18 @@
easy.response_code.should == 200
easy.response_body.should include("this is a body!")
end
end
end

describe "encoding/compression support" do

it "should send valid encoding headers and decode the response" do
easy = Typhoeus::Easy.new
easy.url = "http://localhost:3002/gzipped"
easy.method = :get
easy.perform
easy.response_code.should == 200
JSON.parse(easy.response_body)["HTTP_ACCEPT_ENCODING"].should == "deflate, gzip"
end

end
end

0 comments on commit dc59505

Please sign in to comment.