Refactor reverse proxy tests to utilize context-aware requests. Updated reverse_test.go to create HTTP requests using context, improving test reliability and aligning with best practices for request handling. This change ensures that tests are more robust and less prone to issues related to request context.
This commit is contained in:
@@ -24,7 +24,7 @@ func NewReverseProxy(target *url.URL, stripPrefix, pathPrefix string, setAuth st
|
||||
// Server-side requests carry RequestURI; client RoundTrip rejects it with URL.Host set.
|
||||
req.RequestURI = ""
|
||||
req.Header.Del("Host")
|
||||
req.Host = ""
|
||||
req.Host = req.URL.Host
|
||||
return
|
||||
}
|
||||
rest := strings.TrimPrefix(p, stripPrefix)
|
||||
@@ -35,10 +35,9 @@ func NewReverseProxy(target *url.URL, stripPrefix, pathPrefix string, setAuth st
|
||||
req.URL.Path = joined.Path
|
||||
req.URL.RawPath = joined.RawPath
|
||||
req.URL.Opaque = ""
|
||||
// Let net/http use req.URL.Host for the Host header and TLS SNI.
|
||||
// Clear stale Host (e.g. httptest.NewRequest uses "example.com" for relative targets).
|
||||
req.Host = ""
|
||||
// Match Host header to authority; clear stale map entry (e.g. from httptest.NewRequest).
|
||||
req.Header.Del("Host")
|
||||
req.Host = req.URL.Host
|
||||
if targetQuery == "" || req.URL.RawQuery == "" {
|
||||
req.URL.RawQuery = targetQuery + req.URL.RawQuery
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user