Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for igrigorik/em-http-request issue #173

  • Loading branch information...
commit a7eb84eb941d5200eb218796457a3fedf5185cf2 1 parent dd1ead8
@eriwen eriwen authored
View
1  .gitignore
@@ -6,3 +6,4 @@ Gemfile.lock
misc
gems/
vendor/
+.idea
View
36 spec/client_spec.rb
@@ -214,7 +214,7 @@ def failed(http=nil)
}
}
end
-
+
it "should set content-length to 0 on posts with empty bodies" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/echo_content_length_from_header').post
@@ -362,18 +362,34 @@ def failed(http=nil)
it "should detect gzip encoding" do
EventMachine.run {
- http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/gzip').get :head => {
- "accept-encoding" => "gzip, compressed"
- }
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/gzip').get :head => {"accept-encoding" => "gzip, compressed"}
- http.errback { failed(http) }
- http.callback {
- http.response_header.status.should == 200
- http.response_header["CONTENT_ENCODING"].should == "gzip"
- http.response.should == "compressed"
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header["CONTENT_ENCODING"].should == "gzip"
+ http.response.should == "compressed"
- EventMachine.stop
+ EventMachine.stop
+ }
}
+ end
+
+ it "should handle gzip responses larger than 2048 bytes" do
+ expected_response = Zlib::GzipReader.open(File.dirname(__FILE__) + "/fixtures/gzip-sample.gz") { |f| f.read }
+
+ EventMachine.run {
+
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/gzip-large').get :head => {"accept-encoding" => "gzip, compressed"}
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header["CONTENT_ENCODING"].should == "gzip"
+ http.response.should == expected_response
+
+ EventMachine.stop
+ }
}
end
View
16 spec/external_spec.rb
@@ -96,6 +96,22 @@
}
end
+ it "should detect gzip encoding" do
+ pending "need an endpoint which supports gzip"
+ EventMachine.run {
+ options = {:head => {"accept-encoding" => "gzip"}}
+ http = EventMachine::HttpRequest.new('https://stream.twitter.com/1/statuses/sample.json').get options
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header["CONTENT_ENCODING"].should == "gzip"
+
+ EventMachine.stop
+ }
+ }
+ end
+
context "keepalive" do
it "should default to non-keepalive" do
EventMachine.run {
View
BIN  spec/fixtures/gzip-sample.gz
Binary file not shown
View
8 spec/stallion.rb
@@ -90,7 +90,7 @@ def self.call(env)
elsif stable.request.path_info == '/echo_content_length_from_header'
stable.response.write "content-length:#{stable.request.env["CONTENT_LENGTH"]}"
-
+
elsif stable.request.head? && stable.request.path_info == '/'
stable.response.status = 200
@@ -180,6 +180,12 @@ def self.call(env)
stable.response.write io.string
stable.response["Content-Encoding"] = "gzip"
+ elsif stable.request.path_info == '/gzip-large'
+ contents = File.open(File.dirname(__FILE__) + "/fixtures/gzip-sample.gz", 'r') { |f| f.read }
+
+ stable.response.write contents
+ stable.response["Content-Encoding"] = "gzip"
+
elsif stable.request.path_info == '/deflate'
deflater = Zlib::Deflate.new(
Zlib::DEFAULT_COMPRESSION,
Please sign in to comment.
Something went wrong with that request. Please try again.