reverseproxy

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XForwardedProto  = "X-Forwarded-Proto"
	XForwardedFor    = "X-Forwarded-For"
	XForwardedHost   = "X-Forwarded-Host"
	XForwardedPort   = "X-Forwarded-Port"
	XForwardedServer = "X-Forwarded-Server"
	XRealIP          = "X-Real-Ip"
)

X-* Header names.

View Source
const (
	// ContentLength is the Content-Length header.
	ContentLength = "Content-Length"
)

Variables

XHeaders X-* headers.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler interface {
	ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
}

ErrorHandler is an interface for handling errors.

var DefaultHandler ErrorHandler = &defaultHandler{}

DefaultHandler is the default error handler.

type ErrorHandlerFunc

type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)

ErrorHandlerFunc is an adapter to allow the use of ordinary functions as error handlers. If f is a function with the appropriate signature, ErrorHandlerFunc(f) is a ErrorHandler that calls f.

func (ErrorHandlerFunc) ServeHTTP

func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error)

ServeHTTP calls f(w, r).

type Forwarder

type Forwarder struct {
	*httputil.ReverseProxy
	// contains filtered or unexported fields
}

Forwarder is a reverse proxy that forwards http requests to another server.

func New

func New(opts ...Option) (*Forwarder, error)

New returns a new reverse proxy that forwards to the given url. If passHostHeader is true, the Host header will be copied from the request to the forwarded request. Otherwise, the Host header will be set to the host portion of the url.

type HeaderRewriter

type HeaderRewriter struct {
	TrustForwardHeader bool
	Hostname           string
}

HeaderRewriter re-sets the X-Forwarded-* headers and sets X-Real-IP header.

func NewHeaderRewriter

func NewHeaderRewriter() *HeaderRewriter

NewHeaderRewriter creates a new HeaderRewriter.

func (*HeaderRewriter) Rewrite

func (rw *HeaderRewriter) Rewrite(req *http.Request)

Rewrite request headers.

type Option

type Option func(*Forwarder)

Option is a functional option for the forwarder.

func WithErrorHandler

func WithErrorHandler(e ErrorHandlerFunc) Option

WithErrorHandler sets the error handler for the forwarder.

func WithFlushInterval

func WithFlushInterval(interval time.Duration) Option

WithFlushInterval sets the flush interval for the forwarder.

func WithLogger

func WithLogger(logger logrus.FieldLogger) Option

WithLogger sets the logger for the forwarder. It uses the logger.Writer() method to get the io.Writer to use for the stdlib logger.

func WithPassHostHeader

func WithPassHostHeader() Option

WithPassHostHeader sets whether the Host header should be passed to the forwarded request.

func WithResponseModifier

func WithResponseModifier(m func(*http.Response) error) Option

WithResponseModifier sets the response modifier for the forwarder.

func WithRewriter

func WithRewriter(h Rewriter) Option

WithRewriter sets the header rewriter for the forwarder.

func WithRoundTripper

func WithRoundTripper(transport http.RoundTripper) Option

WithRoundTripper sets the round tripper for the forwarder.

type Rewriter

type Rewriter interface {
	Rewrite(*http.Request)
}

Rewriter is an interface for rewriting http requests.

Jump to

Keyboard shortcuts

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