Skip to content

Commit

Permalink
catch EOF errors, log all else
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottLNorvell committed Jun 20, 2023
1 parent d5e967e commit c7dcef5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion relay/traffic/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package traffic
import (
"bytes"
"crypto/tls"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -139,7 +140,10 @@ func (handler *Handler) handleHttp(clientResponse http.ResponseWriter, clientReq
if _, err := io.CopyN(clientResponse, targetResponse.Body, handler.config.MaxBodySize); err != nil {
// NOTE: it is highly likely the server would come back without a content-length especially with
// mobile traffic. In this case, full copy happens but we get an EOF error that can be safely
// ignored. See this example: https://go.dev/play/p/8T3kbRfk_vO
// ignored. See this example: https://go.dev/play/p/xotsgkwhJis
if !errors.Is(err, io.EOF) {
logger.Printf("Error relaying response body with unknown content-length: %s", err)
}
}
} else {
clientResponse.WriteHeader(targetResponse.StatusCode)
Expand Down

0 comments on commit c7dcef5

Please sign in to comment.