@@ -17,17 +17,18 @@ var (
1717)
1818
1919type (
20- // RedirectPolicy to regulate the redirects in the resty client.
20+ // RedirectPolicy to regulate the redirects in the Resty client.
2121 // Objects implementing the [RedirectPolicy] interface can be registered as
2222 //
23- // Apply function should return nil to continue the redirect journey, otherwise
23+ // Apply function should return nil to continue the redirect journey; otherwise
2424 // return error to stop the redirect.
2525 RedirectPolicy interface {
2626 Apply (req * http.Request , via []* http.Request ) error
2727 }
2828
29- // The [RedirectPolicyFunc] type is an adapter to allow the use of ordinary functions as [RedirectPolicy].
30- // If f is a function with the appropriate signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls f.
29+ // The [RedirectPolicyFunc] type is an adapter to allow the use of ordinary
30+ // functions as [RedirectPolicy]. If `f` is a function with the appropriate
31+ // signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls `f`.
3132 RedirectPolicyFunc func (* http.Request , []* http.Request ) error
3233)
3334
@@ -36,7 +37,7 @@ func (f RedirectPolicyFunc) Apply(req *http.Request, via []*http.Request) error
3637 return f (req , via )
3738}
3839
39- // NoRedirectPolicy is used to disable redirects in the HTTP client
40+ // NoRedirectPolicy is used to disable redirects in the Resty client
4041//
4142// resty.SetRedirectPolicy(NoRedirectPolicy())
4243func NoRedirectPolicy () RedirectPolicy {
@@ -45,7 +46,7 @@ func NoRedirectPolicy() RedirectPolicy {
4546 })
4647}
4748
48- // FlexibleRedirectPolicy is convenient method to create No of redirect policy for HTTP client .
49+ // FlexibleRedirectPolicy method is convenient for creating several redirect policies for Resty clients .
4950//
5051// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20))
5152func FlexibleRedirectPolicy (noOfRedirect int ) RedirectPolicy {
@@ -58,8 +59,8 @@ func FlexibleRedirectPolicy(noOfRedirect int) RedirectPolicy {
5859 })
5960}
6061
61- // DomainCheckRedirectPolicy is convenient method to define domain name redirect rule in resty client .
62- // Redirect is allowed for only mentioned host in the policy.
62+ // DomainCheckRedirectPolicy method is convenient for defining domain name redirect rules in Resty clients .
63+ // Redirect is allowed only for the host mentioned in the policy.
6364//
6465// resty.SetRedirectPolicy(DomainCheckRedirectPolicy("host1.com", "host2.org", "host3.net"))
6566func DomainCheckRedirectPolicy (hostnames ... string ) RedirectPolicy {
@@ -79,10 +80,6 @@ func DomainCheckRedirectPolicy(hostnames ...string) RedirectPolicy {
7980 return fn
8081}
8182
82- //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
83- // Package Unexported methods
84- //_______________________________________________________________________
85-
8683func getHostname (host string ) (hostname string ) {
8784 if strings .Index (host , ":" ) > 0 {
8885 host , _ , _ = net .SplitHostPort (host )
@@ -91,10 +88,11 @@ func getHostname(host string) (hostname string) {
9188 return
9289}
9390
94- // By default Golang will not redirect request headers
95- // after go throwing various discussion comments from thread
91+ // By default, Golang will not redirect request headers.
92+ // After reading through the various discussion comments from the thread -
9693// https://github.com/golang/go/issues/4800
97- // Resty will add all the headers during a redirect for the same host
94+ // Resty will add all the headers during a redirect for the same host and
95+ // adds library user-agent if the Host is different.
9896func checkHostAndAddHeaders (cur * http.Request , pre * http.Request ) {
9997 curHostname := getHostname (cur .URL .Host )
10098 preHostname := getHostname (pre .URL .Host )
0 commit comments