Permalink
Browse files

redirects should go through proxy - closes #167

  • Loading branch information...
igrigorik committed Feb 1, 2012
1 parent ce50f32 commit add8ad4f6ee85fe55659272ade91a93ba805e2d9
Showing with 32 additions and 12 deletions.
  1. +0 −1 lib/em-http/client.rb
  2. +3 −9 lib/em-http/http_client_options.rb
  3. +7 −1 lib/em-http/http_connection.rb
  4. +22 −1 spec/http_proxy_spec.rb
View
@@ -133,7 +133,6 @@ def normalize_body(body)
def build_request
head = @req.headers ? munge_header_keys(@req.headers) : {}
- proxy = @req.proxy
if @req.http_proxy?
head['proxy-authorization'] = @req.proxy[:authorization] if @req.proxy[:authorization]
@@ -12,7 +12,6 @@ def initialize(uri, options, method)
@method = method.to_s.upcase
@headers = options[:head] || {}
- @proxy = options[:proxy] || {}
@query = options[:query]
@path = options[:path]
@@ -45,13 +44,8 @@ def set_uri(uri)
@uri.port ||= 80
end
- if !@proxy.empty?
- @host = @proxy[:host]
- @port = @proxy[:port]
- else
- @host = @uri.host
- @port = @uri.port
- end
+ @host = @uri.host
+ @port = @uri.port
end
-end
+end
@@ -173,7 +173,13 @@ def unbind(reason)
begin
@conn.set_deferred_status :unknown
- @conn.reconnect(r.req.host, r.req.port)
+
+ if @connopts.proxy
+ @conn.reconnect(@connopts.host, @connopts.port)
+ else
+ @conn.reconnect(r.req.host, r.req.port)
+ end
+
@conn.callback { r.connection_completed }
rescue EventMachine::ConnectionError => e
@clients.pop.close(e.message)
View
@@ -48,6 +48,27 @@
}
}
end
+
+ it "should use HTTP proxy while redirecting" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect', proxy).get :redirects => 1
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+
+ http.response_header['X_THE_REQUESTED_URI'].should == 'http://127.0.0.1:8090/gzip'
+ http.response_header['X_THE_REQUESTED_URI'].should_not == '/redirect'
+
+ http.response_header["CONTENT_ENCODING"].should == "gzip"
+ http.response.should == "compressed"
+ http.last_effective_url.to_s.should == 'http://127.0.0.1:8090/gzip'
+ http.redirects.should == 1
+
+ EventMachine.stop
+ }
+ }
+ end
end
-end
+end

0 comments on commit add8ad4

Please sign in to comment.