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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,29 @@ func (proxy *ProxyHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
resp = proxy.filterResponse(resp, ctx)

if resp == nil {
var errorString string
if ctx.Error != nil {
errorString = "error read response " + r.URL.Host + " : " + ctx.Error.Error()
ctx.Logf(errorString)
http.Error(w, ctx.Error.Error(), 500)
var (
errorString string
code int
)

if e, ok := ctx.Error.(net.Error); ok {
if e.Timeout() {
errorString = "timed out connecting to remote host: " + e.Error()
code = http.StatusGatewayTimeout
} else {
errorString = "failed to connect to remote host: " + e.Error()
code = http.StatusBadGateway
}
} else if ctx.Error != nil {
errorString = "failed to read response from remote host: " + e.Error()
code = http.StatusInternalServerError
} else {
errorString = "error read response " + r.URL.Host
ctx.Logf(errorString)
http.Error(w, errorString, 500)
errorString = "failed to read response from remote host: " + r.URL.Host
code = http.StatusInternalServerError
}

ctx.Logf(errorString)
http.Error(w, errorString, code)
return
}
ctx.Logf("Copying response to client %v [%d]", resp.Status, resp.StatusCode)
Expand Down