Skip to content

Commit

Permalink
flush stream to client also on error path (#1560)
Browse files Browse the repository at this point in the history
* flush stream to client also on error path in defer of ServeHTTP
* fix access log test in case we flush we get a text body with the error message as data

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Oct 21, 2020
1 parent e496419 commit 5a92e9f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {

logging.LogAccess(entry, additionalData)
}
// This flush is required in I/O error
lw.Flush()
}()

// Change /foo/../bar to /bar for matching and passing upstream
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ func TestAccessLogOnFailedRequest(t *testing.T) {
return
}

expected := fmt.Sprintf(`"GET / HTTP/1.1" %d %d "-" "Go-http-client/1.1"`, http.StatusBadGateway, rsp.ContentLength)
expected := fmt.Sprintf(`"GET / HTTP/1.1" %d %d "-" "Go-http-client/1.1"`, http.StatusBadGateway, len(http.StatusText(http.StatusBadGateway))+1)
if !strings.Contains(output, expected) || !strings.Contains(output, proxyURL.Host) {
t.Error("failed to log access", output, expected)
t.Log(output)
Expand Down

0 comments on commit 5a92e9f

Please sign in to comment.