Skip to content

Commit

Permalink
Merge pull request #34 from fullstorydev/VAL-7571/suppress-noisy-rela…
Browse files Browse the repository at this point in the history
…y-error

Suppresse relay error for 0 content-length responses
  • Loading branch information
ScottLNorvell authored Jun 21, 2023
2 parents 3e6d531 + c7dcef5 commit a6084e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/dist

/.vscode
/.idea
8 changes: 7 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 @@ -137,7 +138,12 @@ func (handler *Handler) handleHttp(clientResponse http.ResponseWriter, clientReq
} else if targetResponse.ContentLength < 0 {
clientResponse.WriteHeader(targetResponse.StatusCode)
if _, err := io.CopyN(clientResponse, targetResponse.Body, handler.config.MaxBodySize); err != nil {
logger.Printf("Error relaying response body with unknown content-length: %s", err)
// 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/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 a6084e6

Please sign in to comment.