elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
6.06k stars 1.1k forks source link

httpError: write error string as body in 502 response #448

Closed omribahumi closed 1 year ago

omribahumi commented 3 years ago

When CONNECT fails, other than getting a 502 response, there's no indication of the failure reason.

This pull request will:

  1. Print the dial failure reason to the Go log output
  2. Return the error in the 502 response body

I couldn't test this with curl as it suppresses the body for 5xx responses for some reason. Not sure if this is because this is a 502 in response to the CONNECT call.

Before:

% echo $'CONNECT nodns.boo HTTP/1.1\r\n' | nc localhost 8080
HTTP/1.1 502 Bad Gateway

After:

% echo $'CONNECT nodns.boo HTTP/1.1\r\n' | nc localhost 8080
HTTP/1.1 502 Bad Gateway
Content-Type: text/plain
Content-Length: 40

dial tcp: lookup nodns.boo: no such host
nkns165 commented 1 year ago

@elazarl It looks like a good change, why don't you merge it? I'd love to have this warning log.

elazarl commented 1 year ago

@nkns165 I'm worried it'd log too much for some people, maybe we need a better tunable logs.

nkns165 commented 1 year ago

Thank you so much...!