Documentation
¶
Index ¶
- Constants
- Variables
- func CreateOnHTMLRewriteResponse(fn func(origin []byte, res *http.Response) ([]byte, error)) func(*http.Response) error
- func CreateOnInjectScriptsResponse(fn func(origin []byte, res *http.Response) string) func(*http.Response) error
- func NewHTTPError(status int, message string) error
- func ParseHostPort(rawHost string) (string, string)
- type BufferPool
- type Config
- type HTTPError
- type Proxy
- type SingleTargetConfig
Constants ¶
const HeaderXForwardedFor = "X-Forwarded-For"
HeaderXForwardedFor is the header name for X-Forwarded-For
const HeaderXForwardedHost = "X-Forwarded-Host"
HeaderXForwardedHost is the header name for X-Forwarded-Host
const HeaderXForwardedPort = "X-Forwarded-Port"
HeaderXForwardedPort is the header name for X-Forwarded-Port
const HeaderXForwardedProto = "X-Forwarded-Proto"
HeaderXForwardedProto is the header name for X-Forwarded-Proto
Variables ¶
var Version = "1.3.2"
Version is the version of this package.
Functions ¶
func CreateOnHTMLRewriteResponse ¶ added in v1.2.1
func CreateOnHTMLRewriteResponse(fn func(origin []byte, res *http.Response) ([]byte, error)) func(*http.Response) error
CreateOnHTMLRewriteResponse create a function to rewrite html response
func CreateOnInjectScriptsResponse ¶ added in v1.2.1
func CreateOnInjectScriptsResponse(fn func(origin []byte, res *http.Response) string) func(*http.Response) error
CreateOnInjectScriptsResponse create a function to inject scripts
func NewHTTPError ¶
NewHTTPError creates a new HTTPError.
func ParseHostPort ¶
ParseHostPort parses host and port from a string in the form host[:port].
Types ¶
type BufferPool ¶
A BufferPool is an interface for getting and returning temporary byte slices for use by io.CopyBuffer.
type Config ¶
type Config struct {
// IsAnonymouse is a flag to indicate whether the proxy is anonymouse.
// which means the proxy will not add headers:
// X-Forwarded-For
// X-Forwarded-Proto
// X-Forwarded-Host
// X-Forwarded-Port
// Default is false.
IsAnonymouse bool
// OnRequest is a function that will be called before the request is sent.
OnRequest func(req *http.Request) error
// OnResponse is a function that will be called after the response is received.
OnResponse func(res *http.Response) error
// OnError is a function that will be called when an error occurs.
OnError func(err error, rw http.ResponseWriter, req *http.Request)
}
Config is the configuration for the Proxy.
type HTTPError ¶
type HTTPError struct {
// contains filtered or unexported fields
}
HTTPError is an error that wraps an HTTP status code.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a Powerful HTTP Proxy, inspired by Go Reverse Proxy.
func NewSingleTarget ¶
func NewSingleTarget(target string, cfg ...*SingleTargetConfig) *Proxy
NewSingleTarget creates a new SingleTarget Proxy.
type SingleTargetConfig ¶
type SingleTargetConfig struct {
Rewrites rewriter.Rewriters
Scheme string
Query url.Values
RequestHeaders http.Header
ResponseHeaders http.Header
OnRequest func(req *http.Request) error
OnResponse func(res *http.Response) error
//
IsAnonymouse bool
}
SingleTargetConfig is the configuration for SingleTarget.