ncr / rack-proxy

A request/response rewriting HTTP proxy. A Rack app.
MIT License
269 stars 94 forks source link

Connection refused errors should return response with 502 status code #58

Open andrewhavens opened 7 years ago

andrewhavens commented 7 years ago

I'm working with a gem that uses rack-proxy as a dependency. However, requests that fail to connect are resulting in errors being raised:

Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:6003 (Connection refused - connect(2) for "127.0.0.1" port 6003)
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:878:in `connect'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:858:in `start'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-proxy-0.6.0/lib/rack/http_streaming_response.rb:70:in `session'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-proxy-0.6.0/lib/rack/http_streaming_response.rb:59:in `response'
/Users/andrew/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-proxy-0.6.0/lib/rack/http_streaming_response.rb:21:in `code'

Since rack-proxy is making the request, it should be responsible for forwarding along the correct status code. In this case, it seems like returning a 502 status code is appropriate.

gogolok commented 7 years ago

👍

maca commented 6 years ago

:+1: