Permalink
Browse files

encoding-support related fixes:

- CURLOPT_ENCODING value corrected
- initialization corrected
- specs added to make sure it works properly
  • Loading branch information...
1 parent 8f284b6 commit dc59505531cfe96a677fd4e816635b4e6015b727 @morhekil morhekil committed Jul 16, 2010
Showing with 27 additions and 3 deletions.
  1. +3 −2 lib/typhoeus/easy.rb
  2. +10 −0 spec/servers/app.rb
  3. +14 −1 spec/typhoeus/easy_spec.rb
View
@@ -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,
@@ -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)
View
@@ -2,6 +2,7 @@
require 'rubygems'
require 'sinatra'
require 'json'
+require 'zlib'
@@fail_count = 0
get '/fail/:number' do
@@ -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
View
@@ -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.