@@ -17,17 +17,18 @@ var (
17
17
)
18
18
19
19
type (
20
- // RedirectPolicy to regulate the redirects in the resty client.
20
+ // RedirectPolicy to regulate the redirects in the Resty client.
21
21
// Objects implementing the [RedirectPolicy] interface can be registered as
22
22
//
23
- // Apply function should return nil to continue the redirect journey, otherwise
23
+ // Apply function should return nil to continue the redirect journey; otherwise
24
24
// return error to stop the redirect.
25
25
RedirectPolicy interface {
26
26
Apply (req * http.Request , via []* http.Request ) error
27
27
}
28
28
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`.
31
32
RedirectPolicyFunc func (* http.Request , []* http.Request ) error
32
33
)
33
34
@@ -36,7 +37,7 @@ func (f RedirectPolicyFunc) Apply(req *http.Request, via []*http.Request) error
36
37
return f (req , via )
37
38
}
38
39
39
- // NoRedirectPolicy is used to disable redirects in the HTTP client
40
+ // NoRedirectPolicy is used to disable redirects in the Resty client
40
41
//
41
42
// resty.SetRedirectPolicy(NoRedirectPolicy())
42
43
func NoRedirectPolicy () RedirectPolicy {
@@ -45,7 +46,7 @@ func NoRedirectPolicy() RedirectPolicy {
45
46
})
46
47
}
47
48
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 .
49
50
//
50
51
// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20))
51
52
func FlexibleRedirectPolicy (noOfRedirect int ) RedirectPolicy {
@@ -58,8 +59,8 @@ func FlexibleRedirectPolicy(noOfRedirect int) RedirectPolicy {
58
59
})
59
60
}
60
61
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.
63
64
//
64
65
// resty.SetRedirectPolicy(DomainCheckRedirectPolicy("host1.com", "host2.org", "host3.net"))
65
66
func DomainCheckRedirectPolicy (hostnames ... string ) RedirectPolicy {
@@ -79,10 +80,6 @@ func DomainCheckRedirectPolicy(hostnames ...string) RedirectPolicy {
79
80
return fn
80
81
}
81
82
82
- //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
83
- // Package Unexported methods
84
- //_______________________________________________________________________
85
-
86
83
func getHostname (host string ) (hostname string ) {
87
84
if strings .Index (host , ":" ) > 0 {
88
85
host , _ , _ = net .SplitHostPort (host )
@@ -91,10 +88,11 @@ func getHostname(host string) (hostname string) {
91
88
return
92
89
}
93
90
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 -
96
93
// 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.
98
96
func checkHostAndAddHeaders (cur * http.Request , pre * http.Request ) {
99
97
curHostname := getHostname (cur .URL .Host )
100
98
preHostname := getHostname (pre .URL .Host )
0 commit comments