Documentation
¶
Index ¶
- Constants
- func AnswerErrorStatus(w http.ResponseWriter, r *http.Request, statusCode int)
- func GetStatusCode(err error) int
- func StatusText(statusCode int) string
- func StripHostPort(h string) string
- type FilterFunc
- type HTTPProxyService
- type Options
- type Proxy
- type ProxyHandler
- type ProxyRequest
- type RewriteFunc
- type WithEarlyFilter
- type WithErrorHandler
- type WithFilter
- type WithModifyResponse
- type WithRewrite
Constants ¶
const StatusClientClosedRequest = 499
StatusClientClosedRequest is a custom status code to indicate that the client closed the request.
const StatusClientClosedRequestText = "Client Closed Request"
Variables ¶
This section is empty.
Functions ¶
func AnswerErrorStatus ¶
func AnswerErrorStatus(w http.ResponseWriter, r *http.Request, statusCode int)
func GetStatusCode ¶
func StatusText ¶
func StripHostPort ¶
Types ¶
type FilterFunc ¶
type HTTPProxyService ¶
type Options ¶
type Options struct { FlushInterval time.Duration RoundTripper http.RoundTripper BufferPool httputil.BufferPool ErrorLog *log.Logger }
type Proxy ¶
type Proxy[RCTX any] struct { // contains filtered or unexported fields }
func NewProxy ¶
func NewProxy[RCTX any](service HTTPProxyService[RCTX], opts *Options) *Proxy[RCTX]
Create a new proxy from a service The service must implement HTTPProxyService[RCTX] opts may be nil The service can also implement the following interfaces: - WithErrorHandler[RCTX] - WithModifyResponse[RCTX] - WithRewrite[RCTX] - WithEarlyFilter[RCTX] - WithFilter[RCTX]
type ProxyHandler ¶
type ProxyRequest ¶
type ProxyRequest struct { // In is the request received by the proxy. // The Rewrite function must not modify In. In *http.Request // Out is the request which will be sent by the proxy. // The Rewrite function may modify or replace this request. // Hop-by-hop headers are removed from this request // before Rewrite is called. Out *http.Request }
type RewriteFunc ¶
type RewriteFunc[RCTX any] func(*httputil.ProxyRequest, *RCTX)
type WithEarlyFilter ¶
type WithEarlyFilter[RCTX any] interface { EarlyFilter(http.ResponseWriter, *http.Request, *RCTX) bool }
Early filter to reject / accept the request before any processing Should return false to reject the request Default is to accept all requests
type WithErrorHandler ¶
type WithErrorHandler[RCTX any] interface { ErrorHandler(http.ResponseWriter, *http.Request, *RCTX, error) }
Error handler to handle errors returned by ModifyResponse or errors during request processing defaultErrorHandler is used if nil
type WithFilter ¶
Filter to reject / accept the request after the target is resolved Default is to accept all requests
type WithModifyResponse ¶
Modify the response before sending it to the client If returns an error, the Error handler is called Default is to do nothing
type WithRewrite ¶
type WithRewrite[RCTX any] interface { Rewrite(*ProxyRequest, *RCTX) }
Rewrite the request before sending it to the upstream useful for adding headers, etc. Default is to do nothing but rewrite the target and clean websocket headers