From 6b3b1a429aea4af25f49b954262696d435265552 Mon Sep 17 00:00:00 2001 From: Eric Wendelin Date: Mon, 2 Apr 2012 18:47:26 -0600 Subject: [PATCH] Adding streaming gzip tests --- spec/client_spec.rb | 10 ++++++++-- spec/external_spec.rb | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 65de5248..8e7c9953 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -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 { @@ -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 diff --git a/spec/external_spec.rb b/spec/external_spec.rb index 53cda1ac..31cf9593 100644 --- a/spec/external_spec.rb +++ b/spec/external_spec.rb @@ -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