Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: return 502 Bad Gateway on round-trip error #489

Closed
wants to merge 2 commits into from

Conversation

mmatczuk
Copy link

@mmatczuk mmatczuk commented Nov 8, 2022

Currently, it's not possible to distinguish target server internal error from using a wrong server or server being down. This patch changes status code 500 to 502 in case we cannot get a response from upstream.

Below snippets from the HTTP specification:

The HyperText Transfer Protocol (HTTP) 502 Bad Gateway
server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502

vs.

The HyperText Transfer Protocol (HTTP) 500 Internal Server Error
server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
This error response is a generic "catch-all" response. Usually, this indicates the server cannot find a better 5xx error code to response. Sometimes, server administrators log error responses like the 500 status code with more details about the request to prevent the error from happening again in the future.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500

Fixes #51

Currently, it's not possible to distinguish target server internal error from using a wrong server or server being down.
This patch changes status code 500 to 502 in case we cannot get a response from upstream.

Below snippets from the HTTP specification:

> The HyperText Transfer Protocol (HTTP) 502 Bad Gateway
> server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502

vs.

> The HyperText Transfer Protocol (HTTP) 500 Internal Server Error
> server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
> This error response is a generic "catch-all" response. Usually, this indicates the server cannot find a better 5xx error code to response. Sometimes, server administrators log error responses like the 500 status code with more details about the request to prevent the error from happening again in the future.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500

Fixes elazarl#51
This patch allows to distinguish between status codes
* 502 - network error, failed to dial
* 504 - network error, dial timeout
* 500 - other error

Relates to elazarl#51
mmatczuk added a commit to saucelabs/forwarder that referenced this pull request Nov 8, 2022
My fork is hosting patches I sent upstream to fix issues.

It contains patches from
* elazarl/goproxy#488
* elazarl/goproxy#489
@mmatczuk
Copy link
Author

mmatczuk commented Nov 9, 2022

I'm closing this PR, I'd open a new one with a better implementation.

@mmatczuk mmatczuk closed this Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Status code on unresolvable hosts.
1 participant