Documentation ¶
Index ¶
- Constants
- Variables
- type ErrorHandler
- type ErrorHandlerFunc
- type Forwarder
- type HeaderRewriter
- type Option
- func WithErrorHandler(e ErrorHandlerFunc) Option
- func WithFlushInterval(interval time.Duration) Option
- func WithLogger(logger logrus.FieldLogger) Option
- func WithPassHostHeader() Option
- func WithResponseModifier(m func(*http.Response) error) Option
- func WithRewriter(h Rewriter) Option
- func WithRoundTripper(transport http.RoundTripper) Option
- type Rewriter
Constants ¶
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.
const (
// ContentLength is the Content-Length header.
ContentLength = "Content-Length"
)
Variables ¶
var XHeaders = []string{ XForwardedProto, XForwardedFor, XForwardedHost, XForwardedPort, XForwardedServer, XRealIP, }
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.
type HeaderRewriter ¶
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 ¶
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 ¶
WithResponseModifier sets the response modifier for the forwarder.
func WithRewriter ¶
WithRewriter sets the header rewriter for the forwarder.
func WithRoundTripper ¶
func WithRoundTripper(transport http.RoundTripper) Option
WithRoundTripper sets the round tripper for the forwarder.