Redirects do not go through specified proxy #167

Closed
tomekr opened this Issue Jan 31, 2012 · 3 comments

2 participants

@tomekr

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.

@igrigorik
Owner

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

@tomekr

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
      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/redirect'
          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

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

rspec spec/http_proxy_spec.rb 
.F..

Failures:

  1) EventMachine::HttpRequest connections via should use HTTP proxy while redirecting
     Failure/Error: http.response_header['X_THE_REQUESTED_URI'].should == 'http://127.0.0.1:8090/redirect'
       expected: "http://127.0.0.1:8090/redirect"
            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
@igrigorik
Owner

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