README
¶
gentleman/redirect

gentleman's plugin to easily define HTTP request redirect policy and settings.
Installation
go get -u gopkg.in/h2non/gentleman.v2/plugins/redirect
API
See godoc reference.
Example
package main
import (
"fmt"
"gopkg.in/h2non/gentleman.v2"
"gopkg.in/h2non/gentleman.v2/plugins/redirect"
)
func main() {
// Create a new client
cli := gentleman.New()
// Define the maximum number of redirects
cli.Use(redirect.Limit(20))
// Perform the request
res, err := cli.Request().URL("http://httpbin.org/headers").Send()
if err != nil {
fmt.Printf("Request error: %s\n", err)
return
}
if !res.Ok {
fmt.Printf("Invalid server response: %d\n", res.StatusCode)
return
}
fmt.Printf("Status: %d\n", res.StatusCode)
fmt.Printf("Body: %s", res.String())
}
License
MIT - Tomas Aparicio
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrRedirectLimitExceeded is the error returned when the request responded // with too many redirects ErrRedirectLimitExceeded = errors.New("gentleman: Request exceeded redirect count") // RedirectLimit defines the maximum number of redirects to follow in a request RedirectLimit = 10 // SensitiveHeaders is a map of sensitive HTTP headers that a user // doesn't want passed on a redirect. This is the global variable SensitiveHeaders = []string{ "WWW-Authenticate", "Authorization", "Proxy-Authorization", } )
Functions ¶
Types ¶
type Options ¶
type Options struct { // Limit is the acceptable amount of redirects that we should expect // before returning an error be default this is set to 30. You can change this // globally by modifying the `Limit` variable Limit int // Trusted is a flag that will enable all headers to be // forwarded to the redirect location. Otherwise, the headers specified in // `SensitiveHeaders` will be removed from the request Trusted bool // SensitiveHeaders is a map of sensitive HTTP headers that a user // doesn't want passed on a redirect SensitiveHeaders []string }
Options store the redirect policy options
Click to show internal directories.
Click to hide internal directories.