Skip to content

Commit

Permalink
Merge pull request #174 from sonroyaalmerol/check-redirect
Browse files Browse the repository at this point in the history
Immediately close response body on client disconnect
  • Loading branch information
sonroyaalmerol authored Oct 10, 2024
2 parents 2f436e9 + 948c04d commit f802ae2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion proxy/stream_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func Handler(w http.ResponseWriter, r *http.Request) {
cancel()
}

_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
}
Expand Down
8 changes: 7 additions & 1 deletion utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ func CustomHttpRequest(method string, url string) (*http.Response, error) {
userAgent := GetEnv("USER_AGENT")

// Create a new HTTP client with a custom User-Agent header
client := &http.Client{}
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// Follow redirects while preserving the custom User-Agent header
req.Header.Set("User-Agent", userAgent)
return nil
},
}

req, err := http.NewRequest(method, url, nil)
if err != nil {
Expand Down

0 comments on commit f802ae2

Please sign in to comment.