@@ -8,7 +8,7 @@ package resty
88import (
99 "errors"
1010 "fmt"
11- "net "
11+ "maps "
1212 "net/http"
1313 "strings"
1414)
@@ -76,8 +76,8 @@ func RedirectDomainCheckPolicy(hostnames ...string) RedirectPolicy {
7676 }
7777
7878 return RedirectPolicyFunc (func (req * http.Request , via []* http.Request ) error {
79- if ok := hosts [getHostname (req .URL .Host )]; ! ok {
80- return errors .New ("redirect is not allowed as per DomainCheckRedirectPolicy" )
79+ if ok := hosts [strings . ToLower (req .URL .Host )]; ! ok {
80+ return errors .New ("resty: redirect is not allowed as per DomainCheckRedirectPolicy" )
8181 }
8282 checkHostAndAddHeaders (req , via [0 ])
8383 return nil
@@ -123,14 +123,6 @@ func RedirectHeaderStripSensitivePolicy(applyDefault bool, headers ...string) Re
123123 })
124124}
125125
126- func getHostname (host string ) (hostname string ) {
127- if strings .Index (host , ":" ) > 0 {
128- host , _ , _ = net .SplitHostPort (host )
129- }
130- hostname = strings .ToLower (host )
131- return
132- }
133-
134126// By default, Golang will not redirect request headers.
135127// After reading through the various discussion comments from the thread -
136128// https://github.com/golang/go/issues/4800
@@ -143,12 +135,10 @@ func getHostname(host string) (hostname string) {
143135// (e.g. those set via [Client.SetHeaderAuthorizationKey]) are forwarded
144136// verbatim unless explicitly removed. See https://github.com/go-resty/resty/issues/1128.
145137func checkHostAndAddHeaders (cur * http.Request , pre * http.Request ) {
146- curHostname := getHostname (cur .URL .Host )
147- preHostname := getHostname (pre .URL .Host )
138+ curHostname := strings . ToLower (cur .URL .Host )
139+ preHostname := strings . ToLower (pre .URL .Host )
148140 if strings .EqualFold (curHostname , preHostname ) {
149- for key , val := range pre .Header {
150- cur .Header [key ] = val
151- }
141+ maps .Copy (cur .Header , pre .Header )
152142 } else {
153143 // Cross-domain redirect: strip sensitive headers that Go's
154144 // net/http does not know about (custom auth, token, api-key, etc.).
0 commit comments