redirecthandler

package
v0.1.34 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRedirectHandler

func SetupRedirectHandler(client *http.Client, followRedirects bool, maxRedirects int, log logger.Logger) error

SetupRedirectHandler configures the HTTP client for redirect handling based on the client configuration.

Types

type MaxRedirectsError

type MaxRedirectsError struct {
	MaxRedirects int
}

MaxRedirectsError represents an error when the maximum number of redirects is reached.

func (*MaxRedirectsError) Error

func (e *MaxRedirectsError) Error() string

MaxRedirectsError defines an error for when the maximum number of redirects is reached.

type RedirectHandler

type RedirectHandler struct {
	Logger             logger.Logger                // Logger instance for logging.
	MaxRedirects       int                          // Maximum allowed redirects to prevent infinite loops.
	VisitedURLs        map[string]int               // Tracks visited URLs to detect loops.
	VisitedURLsMutex   sync.RWMutex                 // Mutex for safe concurrent access to VisitedURLs.
	SensitiveHeaders   []string                     // Headers to be removed on cross-domain redirects.
	PermanentRedirects map[string]string            // Cache for permanent redirects
	PermRedirectsMutex sync.RWMutex                 // Mutex for safe concurrent access to PermanentRedirects
	RedirectHistories  map[*http.Request][]*url.URL // Map to track redirect history for each request
}

RedirectHandler contains configurations for handling HTTP redirects.

func NewRedirectHandler

func NewRedirectHandler(logger logger.Logger, maxRedirects int) *RedirectHandler

NewRedirectHandler creates a new instance of RedirectHandler.

func (*RedirectHandler) AddSensitiveHeader

func (r *RedirectHandler) AddSensitiveHeader(header string)

AddSensitiveHeader allows adding configurable sensitive headers.

func (*RedirectHandler) GetRedirectHistory

func (r *RedirectHandler) GetRedirectHistory(req *http.Request) []*url.URL

GetRedirectHistory returns the redirect history for a given request.

func (*RedirectHandler) WithRedirectHandling

func (r *RedirectHandler) WithRedirectHandling(client *http.Client)

WithRedirectHandling applies the redirect handling policy to an http.Client.

type RedirectLoopError

type RedirectLoopError struct {
	URL string
}

RedirectLoopError represents an error when a redirect loop is detected.

func (*RedirectLoopError) Error

func (e *RedirectLoopError) Error() string

RedirectLoopError defines an error for when a redirect loop is detected.

Jump to

Keyboard shortcuts

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