spec/client_spec.rb in em-http-request-1.0.2 vs spec/client_spec.rb in em-http-request-1.0.3
- old
+ new
@@ -186,10 +186,23 @@
EventMachine.stop
}
}
end
+ it "should perform successful PATCH" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/').patch :body => "data"
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response.should match(/data/)
+ EventMachine.stop
+ }
+ }
+ end
+
it "should escape body on POST" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/').post :body => {:stuff => 'string&string'}
http.errback { failed(http) }
@@ -212,11 +225,11 @@
http.response.should match(/key1=1&key2\[0\]=2&key2\[1\]=3/)
EventMachine.stop
}
}
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
http.errback { failed(http) }
@@ -341,10 +354,24 @@
EventMachine.stop
}
}
end
+ it "should return raw headers in a hash" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/echo_headers').get
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header.raw['Set-Cookie'].should match('test=yes')
+ http.response_header.raw['X-Forward-Host'].should match('proxy.local')
+ EventMachine.stop
+ }
+ }
+ end
+
it "should detect deflate encoding" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/deflate').get :head => {"accept-encoding" => "deflate"}
@@ -360,23 +387,45 @@
end
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"
+
+ EventMachine.stop
+ }
}
+ end
- http.errback { failed(http) }
- http.callback {
- http.response_header.status.should == 200
- http.response_header["CONTENT_ENCODING"].should == "gzip"
- http.response.should == "compressed"
+ it "should stream gzip responses" do
+ expected_response = Zlib::GzipReader.open(File.dirname(__FILE__) + "/fixtures/gzip-sample.gz") { |f| f.read }
+ actual_response = ''
- EventMachine.stop
+ 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 == ''
+
+ actual_response.should == expected_response
+
+ EventMachine.stop
+ }
+ http.stream do |chunk|
+ actual_response << chunk
+ end
}
- }
end
it "should not decode the response when configured so" do
EventMachine.run {
@@ -631,10 +680,13 @@
}
}
end
it "should get the body without Content-Length" do
+ pending "blocked on new http_parser.rb release"
+ # https://github.com/igrigorik/em-http-request/issues/168
+
EventMachine.run {
@s = StubServer.new("HTTP/1.1 200 OK\r\n\r\nFoo")
http = EventMachine::HttpRequest.new('http://127.0.0.1:8081/').get
http.errback { failed(http) }
@@ -704,9 +756,27 @@
http.errback { failed(http) }
http.callback {
http.response.should match('google')
EventMachine.stop
}
+ }
+ end
+
+ it "should reconnect if connection was closed between requests" do
+ EventMachine.run {
+ conn = EM::HttpRequest.new('http://127.0.0.1:8090/', :inactivity_timeout => 0.5)
+ req = conn.get :keepalive => true
+
+ req.callback do
+ EM.add_timer(1) do
+ req = conn.get
+
+ req.callback do
+ req.response_header.status.should == 200
+ EventMachine.stop
+ end
+ end
+ end
}
end
it 'should handle malformed Content-Type header repetitions' do
EventMachine.run {