v2.0.5+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 5 Imported by: 0


gentleman/redirect Build Status GoDoc API Go Report Card

gentleman's plugin to easily define HTTP request redirect policy and settings.


go get -u


See godoc reference.


package main

import (

func main() {
  // Create a new client
  cli := gentleman.New()

  // Define the maximum number of redirects

  // Perform the request
  res, err := cli.Request().URL("").Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())


MIT - Tomas Aparicio




This section is empty.


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{


func Config

func Config(opts Options) p.Plugin

Config defines in the request http.Client the redirect policy based on the given options.

func Limit

func Limit(limit int) p.Plugin

Limit defines in the maximum number of redirects that http.Client should follow.


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

	// TrustedHostSuffixes is a list of host suffixes that will be forwarded all
	// headers. Hosts not in the list will have the headers specified in
	// `SensitiveHeaders` removed. If `Trusted` is set, this value is ignored.
	// Using suffixes can create some unexpected collisions. For instance, a
	// suffix of `` will match a URL with ``. Consider
	// always including a leading `.` to only match your true trusted hosts if
	// practical, e.g. ``.
	TrustedHostSuffixes []string

	// 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL