-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathredirects.go
More file actions
19 lines (15 loc) · 587 Bytes
/
redirects.go
File metadata and controls
19 lines (15 loc) · 587 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package requests
import "net/http"
// CheckRedirectPolicy is a function suitable for use as CheckRedirect on an http.Client.
type CheckRedirectPolicy = func(req *http.Request, via []*http.Request) error
// MaxFollow returns a CheckRedirectPolicy that follows a maximum of n redirects.
func MaxFollow(n int) CheckRedirectPolicy {
return func(req *http.Request, via []*http.Request) error {
if len(via) > n {
return http.ErrUseLastResponse
}
return nil
}
}
// NoFollow is a CheckRedirectPolicy that does not follow redirects.
var NoFollow CheckRedirectPolicy = MaxFollow(0)