Skip to content

Commit

Permalink
http: unify error handling with https
Browse files Browse the repository at this point in the history
If response is nil call httpError like in https code.
  • Loading branch information
mmatczuk committed Nov 9, 2022
1 parent 4cfa244 commit a696aef
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ func (proxy *ProxyHttpServer) handleHttp(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)
} else {
errorString = "error read response " + r.URL.Host
ctx.Logf(errorString)
http.Error(w, errorString, 500)
hij, ok := w.(http.Hijacker)
if !ok {
panic("httpserver does not support hijacking")
}

proxyClient, _, e := hij.Hijack()
if e != nil {
panic("Cannot hijack connection " + e.Error())
}
httpError(proxyClient, ctx, ctx.Error)
return
}

ctx.Logf("Copying response to client %v [%d]", resp.Status, resp.StatusCode)
// http.ResponseWriter will take care of filling the correct response length
// Setting it now, might impose wrong value, contradicting the actual new
Expand Down

0 comments on commit a696aef

Please sign in to comment.