Permalink
Browse files

reset host override on connect

  • Loading branch information...
1 parent 215531f commit 59c67084ba084e402ce6df75e57ef9ced628892a @igrigorik igrigorik committed Aug 21, 2010
Showing with 30 additions and 10 deletions.
  1. +1 −1 lib/em-http/http_options.rb
  2. +29 −9 spec/request_spec.rb
@@ -14,7 +14,7 @@ def initialize(method, uri, options)
else
# optional host for cases where you may have
# pre-resolved the host, or you need an override
- @host = options[:host] || uri.host
+ @host = options.delete(:host) || uri.host
@port = uri.port
end
View
@@ -68,17 +68,37 @@ def failed
}
end
- it "should accept optional host override" do
- EventMachine.run {
- http = EventMachine::HttpRequest.new('http://google.com:8080/').get :host => '127.0.0.1'
+ context "host override" do
- http.errback { failed }
- http.callback {
- http.response_header.status.should == 200
- http.response.should match(/Hello/)
- EventMachine.stop
+ it "should accept optional host" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://google.com:8080/').get :host => '127.0.0.1'
+
+ http.errback { failed }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response.should match(/Hello/)
+ EventMachine.stop
+ }
}
- }
+ end
+
+ it "should reset host on redirect" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/redirect').get :redirects => 1, :host => '127.0.0.1'
+
+ http.errback { failed }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response_header["CONTENT_ENCODING"].should == "gzip"
+ http.response.should == "compressed"
+ http.last_effective_url.to_s.should == 'http://127.0.0.1:8080/gzip'
+ http.redirects.should == 1
+
+ EM.stop
+ }
+ }
+ end
end
it "should perform successfull GET with a URI passed as argument" do

0 comments on commit 59c6708

Please sign in to comment.