Redirects do not go through specified proxy #167

tomekr opened this Issue Jan 31, 2012 · 3 comments

2 participants


Hi there,

I am proxying em-http requests through Burp and it looks like the first request goes through to the proxy but any redirects do not. I noticed specs to test that redirects still pass through any Middleware but i didn't find anything for proxies.


Hmm, that's an interesting gotcha.. Do you have a test case to reproduce this? Shouldn't be too hard to address.


I believe this test should be passing. I combined the it "should follow location redirects" test from redirect_spec.rb and it "should send absolute URIs to the proxy server" from http_proxy_spec.rb. looks like:

    it "should use HTTP proxy while redirecting" do {
        http ='', 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.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.redirects.should == 1


and added that test to the http_proxy_spec.rb file. Here is the output:

rspec spec/http_proxy_spec.rb 


  1) EventMachine::HttpRequest connections via should use HTTP proxy while redirecting
     Failure/Error: http.response_header['X_THE_REQUESTED_URI'].should == ''
       expected: ""
            got: nil (using ==)
     # ./spec/http_proxy_spec.rb:29:in `block (5 levels) in <top (required)>'
     # ./lib/em-http/client.rb:113:in `unbind'
     # ./lib/em-http/client.rb:71:in `on_request_complete'
     # ./lib/em-http/http_connection.rb:124:in `block in post_init'
     # ./lib/em-http/http_connection.rb:139:in `call'
     # ./lib/em-http/http_connection.rb:139:in `<<'
     # ./lib/em-http/http_connection.rb:139:in `receive_data'
     # ./lib/em-http/http_connection.rb:21:in `receive_data'
     # ./spec/http_proxy_spec.rb:22:in `block (3 levels) in <top (required)>'

Finished in 0.03316 seconds
4 examples, 1 failure

Failed examples:

rspec ./spec/http_proxy_spec.rb:21 # EventMachine::HttpRequest connections via should use HTTP proxy while redirecting
@igrigorik igrigorik closed this in add8ad4 Feb 1, 2012

In theory, that should do the trick.. but need to sleep on it first :-)

Let me know if that fixes it on your end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment