Documentation ΒΆ
Overview ΒΆ
Taken from $GOROOT/src/pkg/net/http/chunked needed to write https responses to client.
Index ΒΆ
- Variables
- func ConnError(w net.Conn)
- func RemoveProxyHeaders(r *http.Request)
- func ResetClientHeaders(r *http.Request)
- type Context
- func (ctx *Context) Next(req *http.Request) (*http.Response, error)
- func (ctx *Context) RoundTrip(req *http.Request) (*http.Response, error)
- func (ctx *Context) Use(middleware ...Middleware)
- func (ctx *Context) UseFunc(fns ...MiddlewareFunc)
- func (ctx *Context) WithRequest(req *http.Request) *Context
- type CounterEncryptorRand
- type Filter
- type FilterFunc
- type FilterGroup
- type ForwardHandler
- func (forward *ForwardHandler) OnRequest(filters ...Filter) *ReqFilterGroup
- func (forward *ForwardHandler) OnResponse(filters ...Filter) *RespFilterGroup
- func (forward *ForwardHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (forward *ForwardHandler) Transport() *http.Transport
- func (forward *ForwardHandler) Use(middleware ...Middleware)
- func (forward *ForwardHandler) UseFunc(fus ...MiddlewareFunc)
- type Handle
- type HttpProxy
- func (proxy *HttpProxy) OnRequest(filters ...Filter) *ReqFilterGroup
- func (proxy *HttpProxy) OnResponse(filters ...Filter) *RespFilterGroup
- func (proxy *HttpProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (proxy *HttpProxy) Transport() *http.Transport
- func (proxy *HttpProxy) Use(middleware ...Middleware)
- func (proxy *HttpProxy) UseFunc(fus ...MiddlewareFunc)
- type Middleware
- type MiddlewareFunc
- type MitmHandler
- func (mitm *MitmHandler) OnRequest(filters ...Filter) *ReqFilterGroup
- func (mitm *MitmHandler) OnResponse(filters ...Filter) *RespFilterGroup
- func (mitm *MitmHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (mitm *MitmHandler) TLSConfigFromCA(host string) (*tls.Config, error)
- func (mitm *MitmHandler) Transport() *http.Transport
- func (mitm *MitmHandler) Use(middleware ...Middleware)
- func (mitm *MitmHandler) UseFunc(fus ...MiddlewareFunc)
- type ReqFilterGroup
- type RequestHandle
- type RequestHandleFunc
- type RespFilterGroup
- type ResponseHandle
- type ResponseHandleFunc
- type ReverseHandler
- func (reverse *ReverseHandler) OnRequest(filters ...Filter) *ReqFilterGroup
- func (reverse *ReverseHandler) OnResponse(filters ...Filter) *RespFilterGroup
- func (reverse *ReverseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (reverse *ReverseHandler) Transport() *http.Transport
- func (reverse *ReverseHandler) Use(middleware ...Middleware)
- func (reverse *ReverseHandler) UseFunc(fus ...MiddlewareFunc)
- type TunnelHandler
- func (tunnel *TunnelHandler) ConnectDial(network, addr string) (net.Conn, error)
- func (tunnel *TunnelHandler) OnRequest(filters ...Filter) *ReqFilterGroup
- func (tunnel *TunnelHandler) OnResponse(filters ...Filter) *RespFilterGroup
- func (tunnel *TunnelHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (tunnel *TunnelHandler) Transport() *http.Transport
- func (tunnel *TunnelHandler) Use(middleware ...Middleware)
- func (tunnel *TunnelHandler) UseFunc(fus ...MiddlewareFunc)
- type WebsocketHandler
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( // http request is nil RequestNilErr = errors.New("request is nil") // http request method not support MethodNotSupportErr = errors.New("request method not support") // http request is websocket RequestWebsocketUpgradeErr = errors.New("websocket upgrade") )
var ( HttpTunnelOk = []byte("HTTP/1.0 200 Connection Established\r\n\r\n") HttpTunnelFail = []byte("HTTP/1.1 502 Bad Gateway\r\n\r\n") )
var DefaultTransport = &http.Transport{ DialContext: (&net.Dialer{ Timeout: 15 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, ForceAttemptHTTP2: true, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, Proxy: http.ProxyFromEnvironment, }
Default http.Transport option
var (
HttpMitmOk = []byte("HTTP/1.0 200 Connection Established\r\n\r\n")
)
Functions ΒΆ
func RemoveProxyHeaders ΒΆ
Hop-by-hop headers. These are removed when sent to the backend. As of RFC 7230, hop-by-hop headers are required to appear in the Connection header field. These are the headers defined by the obsoleted RFC 2616 (section 13.5.1) and are used for backward compatibility.
func ResetClientHeaders ΒΆ
ResetClientHeaders These Headers must be reset when a client Request is issued to reuse a Request
Types ΒΆ
type Context ΒΆ
type Context struct { // context.Context Context context.Context // Request context-dependent requests Request *http.Request // Response is associated with Request Response *http.Response // Transport is used for global HTTP requests, and it will be reused. Transport *http.Transport // In some cases it is not always necessary to remove the proxy headers. // For example, cascade proxy KeepProxyHeaders bool // In some cases it is not always necessary to reset the headers. KeepClientHeaders bool // KeepDestinationHeaders indicates the proxy should retain any headers // present in the http.Response before proxying KeepDestinationHeaders bool // contains filtered or unexported fields }
Context for the request which contains Middleware, Transport, and other values
func (*Context) Next ΒΆ
Next to exec middlewares Execute the next middleware as a linked list. "ctx.Next(req)" eg:
func Handle(req *http.Request, ctx *Context) (*http.Response, error) { // You can do anything to modify the http.Request ... resp, err := ctx.Next(req) // You can do anything to modify the http.Response ... return resp, err }
Alternatively, you can simply return the response without executing `ctx.Next()`, which will interrupt subsequent middleware execution.
func (*Context) RoundTrip ΒΆ
RoundTrip implements the RoundTripper interface.
For higher-level HTTP client support (such as handling of cookies and redirects), see Get, Post, and the Client type.
Like the RoundTripper interface, the error types returned by RoundTrip are unspecified.
func (*Context) Use ΒΆ
func (ctx *Context) Use(middleware ...Middleware)
Use registers an Middleware to proxy
func (*Context) UseFunc ΒΆ
func (ctx *Context) UseFunc(fns ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type CounterEncryptorRand ΒΆ
type CounterEncryptorRand struct {
// contains filtered or unexported fields
}
func NewCounterEncryptorRand ΒΆ
func NewCounterEncryptorRand(key interface{}, seed []byte) (r CounterEncryptorRand, err error)
func (*CounterEncryptorRand) Read ΒΆ
func (c *CounterEncryptorRand) Read(b []byte) (n int, err error)
func (*CounterEncryptorRand) Seed ΒΆ
func (c *CounterEncryptorRand) Seed(b []byte)
type Filter ΒΆ
Filter is an request interceptor
func FilterHostIs ΒΆ
FilterHostIs returns a Filter, testing whether the host to which the request is directed to equal to one of the given strings
func FilterHostMatches ΒΆ
FilterHostMatches for request.Host
func FilterUrlHasPrefix ΒΆ
FilterUrlHasPrefix returns a Filter checking wether the destination URL the proxy client has requested has the given prefix, with or without the host. For example FilterUrlHasPrefix("host/x") will match requests of the form 'GET host/x', and will match requests to url 'http://host/x'
func FilterUrlIs ΒΆ
FilterUrlIs returns a Filter, testing whether or not the request URL is one of the given strings with or without the host prefix. FilterUrlIs("google.com/","foo") will match requests 'GET /' to 'google.com', requests `'GET google.com/' to any host, and requests of the form 'GET foo'.
func FilterUrlMatches ΒΆ
FilterUrlMatches returns a Filter testing whether the destination URL of the request matches the given regexp, with or without prefix
type FilterFunc ΒΆ
A wrapper that would convert a function to a Filter interface type
type FilterGroup ΒΆ
type FilterGroup interface {
Handle()
}
type ForwardHandler ΒΆ
type ForwardHandler struct { Ctx *Context BufferPool httputil.BufferPool }
ForwardHandler The forward proxy type. Implements http.Handler.
func NewForwardHandler ΒΆ
func NewForwardHandler() *ForwardHandler
NewForwardHandler Create a forward proxy
func NewForwardHandlerWithContext ΒΆ
func NewForwardHandlerWithContext(ctx *Context) *ForwardHandler
NewForwardHandlerWithContext Create a ForwardHandler with Context
func (*ForwardHandler) OnRequest ΒΆ
func (forward *ForwardHandler) OnRequest(filters ...Filter) *ReqFilterGroup
OnRequest filter requests through Filters
func (*ForwardHandler) OnResponse ΒΆ
func (forward *ForwardHandler) OnResponse(filters ...Filter) *RespFilterGroup
OnResponse filter response through Filters
func (*ForwardHandler) ServeHTTP ΒΆ
func (forward *ForwardHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function. You can use it alone
func (*ForwardHandler) Transport ΒΆ
func (forward *ForwardHandler) Transport() *http.Transport
Transport
func (*ForwardHandler) Use ΒΆ
func (forward *ForwardHandler) Use(middleware ...Middleware)
Use registers an Middleware to proxy
func (*ForwardHandler) UseFunc ΒΆ
func (forward *ForwardHandler) UseFunc(fus ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type Handle ΒΆ
type Handle interface { RequestHandle ResponseHandle }
type HttpProxy ΒΆ
type HttpProxy struct { // Handles Connect requests use the TunnelHandler by default HandleConnect http.Handler // HTTP requests use the ForwardHandler by default HttpHandler http.Handler // HTTP requests use the ReverseHandler by default ReverseHandler http.Handler // Client request Context Ctx *Context }
The basic proxy type. Implements http.Handler.
func NewHttpProxy ΒΆ
func NewHttpProxy() *HttpProxy
func (*HttpProxy) OnRequest ΒΆ
func (proxy *HttpProxy) OnRequest(filters ...Filter) *ReqFilterGroup
OnRequest filter requests through Filters
func (*HttpProxy) OnResponse ΒΆ
func (proxy *HttpProxy) OnResponse(filters ...Filter) *RespFilterGroup
OnResponse filter response through Filters
func (*HttpProxy) ServeHTTP ΒΆ
func (proxy *HttpProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function.
func (*HttpProxy) Use ΒΆ
func (proxy *HttpProxy) Use(middleware ...Middleware)
Use registers an Middleware to proxy
func (*HttpProxy) UseFunc ΒΆ
func (proxy *HttpProxy) UseFunc(fus ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type Middleware ΒΆ
type Middleware interface { // Handle execute the next middleware as a linked list. "ctx.Next(req)" // eg: // func Handle(req *http.Request, ctx *Context) (*http.Response, error) { // // You can do anything to modify the http.Request ... // resp, err := ctx.Next(req) // // You can do anything to modify the http.Response ... // return resp, err // } // // Alternatively, you can simply return the response without executing `ctx.Next()`, // which will interrupt subsequent middleware execution. Handle(req *http.Request, ctx *Context) (*http.Response, error) }
Middleware will "tamper" with the request coming to the proxy server
type MiddlewareFunc ΒΆ
MiddlewareFunc A wrapper that would convert a function to a Middleware interface type
type MitmHandler ΒΆ
type MitmHandler struct { Ctx *Context BufferPool httputil.BufferPool Certificate tls.Certificate // CertContainer is certificate storage container CertContainer cert.Container }
MitmHandler The Man-in-the-middle proxy type. Implements http.Handler.
func NewMitmHandler ΒΆ
func NewMitmHandler() *MitmHandler
NewMitmHandler Create a mitmHandler, use default cert.
func NewMitmHandlerWithCert ΒΆ
func NewMitmHandlerWithCert(ctx *Context, certPEMBlock, keyPEMBlock []byte) (*MitmHandler, error)
NewMitmHandlerWithCert Create a MitmHandler with cert pem block
func NewMitmHandlerWithCertFile ΒΆ
func NewMitmHandlerWithCertFile(ctx *Context, certFile, keyFile string) (*MitmHandler, error)
NewMitmHandlerWithCertFile Create a MitmHandler with cert file
func NewMitmHandlerWithContext ΒΆ
func NewMitmHandlerWithContext(ctx *Context) *MitmHandler
NewMitmHandlerWithContext Create a MitmHandler, use default cert.
func (*MitmHandler) OnRequest ΒΆ
func (mitm *MitmHandler) OnRequest(filters ...Filter) *ReqFilterGroup
OnRequest filter requests through Filters
func (*MitmHandler) OnResponse ΒΆ
func (mitm *MitmHandler) OnResponse(filters ...Filter) *RespFilterGroup
OnResponse filter response through Filters
func (*MitmHandler) ServeHTTP ΒΆ
func (mitm *MitmHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function. You can use it alone
func (*MitmHandler) TLSConfigFromCA ΒΆ
func (mitm *MitmHandler) TLSConfigFromCA(host string) (*tls.Config, error)
func (*MitmHandler) Use ΒΆ
func (mitm *MitmHandler) Use(middleware ...Middleware)
Use registers a Middleware to proxy
func (*MitmHandler) UseFunc ΒΆ
func (mitm *MitmHandler) UseFunc(fus ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type ReqFilterGroup ΒΆ
type ReqFilterGroup struct {
// contains filtered or unexported fields
}
ReqFilterGroup ReqCondition is a request filter group
func (*ReqFilterGroup) Do ΒΆ
func (cond *ReqFilterGroup) Do(h RequestHandle)
type RequestHandle ΒΆ
type RequestHandleFunc ΒΆ
A wrapper that would convert a function to a RequestHandle interface type
func (RequestHandleFunc) HandleRequest ΒΆ
func (f RequestHandleFunc) HandleRequest(req *http.Request, ctx *Context) (*http.Request, *http.Response)
RequestHandle.Handle(req, ctx) <=> RequestHandleFunc(req, ctx)
type RespFilterGroup ΒΆ
type RespFilterGroup struct {
// contains filtered or unexported fields
}
RespFilterGroup ReqCondition is a response filter group
func (*RespFilterGroup) Do ΒΆ
func (cond *RespFilterGroup) Do(h ResponseHandle)
type ResponseHandle ΒΆ
type ResponseHandleFunc ΒΆ
A wrapper that would convert a function to a ResponseHandle interface type
func (ResponseHandleFunc) HandleResponse ΒΆ
func (f ResponseHandleFunc) HandleResponse(resp *http.Response, err error, ctx *Context) (*http.Response, error)
ResponseHandle.Handle(resp, ctx) <=> ResponseHandleFunc(resp, ctx)
type ReverseHandler ΒΆ
type ReverseHandler struct { Ctx *Context BufferPool httputil.BufferPool }
ReverseHandler is a reverse proxy server implementation
func NewReverseHandler ΒΆ
func NewReverseHandler() *ReverseHandler
NewReverseHandler Create a reverse proxy
func (*ReverseHandler) OnRequest ΒΆ
func (reverse *ReverseHandler) OnRequest(filters ...Filter) *ReqFilterGroup
OnRequest filter requests through Filters
func (*ReverseHandler) OnResponse ΒΆ
func (reverse *ReverseHandler) OnResponse(filters ...Filter) *RespFilterGroup
OnResponse filter response through Filters
func (*ReverseHandler) ServeHTTP ΒΆ
func (reverse *ReverseHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function. You can use it alone
func (*ReverseHandler) Transport ΒΆ
func (reverse *ReverseHandler) Transport() *http.Transport
Transport
func (*ReverseHandler) Use ΒΆ
func (reverse *ReverseHandler) Use(middleware ...Middleware)
Use registers an Middleware to proxy
func (*ReverseHandler) UseFunc ΒΆ
func (reverse *ReverseHandler) UseFunc(fus ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type TunnelHandler ΒΆ
type TunnelHandler struct { Ctx *Context BufferPool httputil.BufferPool ConnContainer pool.ConnContainer }
TunnelHandler The tunnel proxy type. Implements http.Handler.
func NewTunnelHandler ΒΆ
func NewTunnelHandler() *TunnelHandler
NewTunnelHandler Create a tunnel handler
func NewTunnelHandlerWithContext ΒΆ
func NewTunnelHandlerWithContext(ctx *Context) *TunnelHandler
NewTunnelHandlerWithContext Create a tunnel handler with Context
func (*TunnelHandler) ConnectDial ΒΆ
func (tunnel *TunnelHandler) ConnectDial(network, addr string) (net.Conn, error)
func (*TunnelHandler) OnRequest ΒΆ
func (tunnel *TunnelHandler) OnRequest(filters ...Filter) *ReqFilterGroup
OnRequest filter requests through Filters
func (*TunnelHandler) OnResponse ΒΆ
func (tunnel *TunnelHandler) OnResponse(filters ...Filter) *RespFilterGroup
OnResponse filter response through Filters
func (*TunnelHandler) ServeHTTP ΒΆ
func (tunnel *TunnelHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function. You can use it alone
func (*TunnelHandler) Transport ΒΆ
func (tunnel *TunnelHandler) Transport() *http.Transport
Transport get http.Transport instance
func (*TunnelHandler) Use ΒΆ
func (tunnel *TunnelHandler) Use(middleware ...Middleware)
Use registers an Middleware to proxy
func (*TunnelHandler) UseFunc ΒΆ
func (tunnel *TunnelHandler) UseFunc(fus ...MiddlewareFunc)
UseFunc registers an MiddlewareFunc to proxy
type WebsocketHandler ΒΆ
type WebsocketHandler struct { Ctx *Context BufferPool httputil.BufferPool }
WebsocketHandler The websocket proxy type. Implements http.Handler.
func NewWebsocketHandler ΒΆ
func NewWebsocketHandler() *WebsocketHandler
NewWebsocketHandler Create a websocket handler
func NewWebsocketHandlerWithContext ΒΆ
func NewWebsocketHandlerWithContext(ctx *Context) *WebsocketHandler
NewWebsocketHandlerWithContext Create a tunnel handler with Context
func (*WebsocketHandler) ConnectDial ΒΆ
func (ws *WebsocketHandler) ConnectDial(network, addr string) (net.Conn, error)
func (*WebsocketHandler) ServeHTTP ΒΆ
func (ws *WebsocketHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
Standard net/http function. You can use it alone
func (*WebsocketHandler) Transport ΒΆ added in v0.1.2
func (ws *WebsocketHandler) Transport() *http.Transport
Transport get http.Transport instance