Skip to content

Commit

Permalink
Adding streaming gzip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eriwen committed Apr 3, 2012
1 parent 1e930c6 commit 6b3b1a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions spec/client_spec.rb
Expand Up @@ -388,8 +388,9 @@ def failed(http=nil)
}
end

it "should handle gzip responses larger than 2048 bytes" do
it "should stream gzip responses" do
expected_response = Zlib::GzipReader.open(File.dirname(__FILE__) + "/fixtures/gzip-sample.gz") { |f| f.read }
actual_response = ''

EventMachine.run {

Expand All @@ -399,10 +400,15 @@ def failed(http=nil)
http.callback {
http.response_header.status.should == 200
http.response_header["CONTENT_ENCODING"].should == "gzip"
http.response.should == expected_response
http.response.should == ''

actual_response.should == expected_response

EventMachine.stop
}
http.stream do |chunk|
actual_response << chunk
end
}
end

Expand Down
12 changes: 9 additions & 3 deletions spec/external_spec.rb
Expand Up @@ -96,19 +96,25 @@
}
end

it "should detect gzip encoding" do
pending "need an endpoint which supports gzip"
it "should stream chunked gzipped data" do
EventMachine.run {
options = {:head => {"accept-encoding" => "gzip"}}
http = EventMachine::HttpRequest.new('https://stream.twitter.com/1/statuses/sample.json').get options
# GitHub sends chunked gzip, time for a little Inception ;)
http = EventMachine::HttpRequest.new('https://github.com/igrigorik/em-http-request/commits/master').get options

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

EventMachine.stop
}

body = ''
http.stream do |chunk|
body << chunk
end
}
end

Expand Down

0 comments on commit 6b3b1a4

Please sign in to comment.