Documentation
¶
Overview ¶
Package httprevproxy provides a TinyGo-compatible subset of net/http/httputil's reverse proxy API.
The public API intentionally follows net/http/httputil so applications can migrate without redesigning proxy configuration when TinyGo supports the standard implementation. Protocol upgrades and 1xx forwarding are not supported.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
A BufferPool gets and returns temporary byte slices used when copying a response body.
type ProxyRequest ¶
type ProxyRequest struct {
// In is the request received by the proxy. Rewrite must not modify In.
In *http.Request
// Out is the request sent by the proxy. Rewrite may modify or replace Out.
Out *http.Request
}
A ProxyRequest contains a request to be rewritten by a ReverseProxy.
func (*ProxyRequest) SetURL ¶
func (r *ProxyRequest) SetURL(target *url.URL)
SetURL routes the outbound request to target, joining target's base path to the incoming path. It also makes the outbound Host header use target.Host.
func (*ProxyRequest) SetXForwarded ¶
func (r *ProxyRequest) SetXForwarded()
SetXForwarded sets X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto from the inbound request. An existing X-Forwarded-For value on Out is preserved and appended to.
type ReverseProxy ¶
type ReverseProxy struct {
Rewrite func(*ProxyRequest)
Transport http.RoundTripper
FlushInterval time.Duration
ErrorLog *log.Logger
BufferPool BufferPool
ModifyResponse func(*http.Response) error
ErrorHandler func(http.ResponseWriter, *http.Request, error)
// Director is deprecated. Use Rewrite instead. Exactly one of Director or
// Rewrite must be set.
Director func(*http.Request)
}
ReverseProxy is an HTTP Handler that proxies requests to another server. Its public fields match net/http/httputil.ReverseProxy. This implementation does not support protocol upgrades or forwarding 1xx responses.
func NewSingleHostReverseProxy ¶
func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy
NewSingleHostReverseProxy returns a proxy that routes requests to target. Like net/http/httputil, it uses the deprecated Director field for backwards compatibility and preserves the inbound Host header.
func (*ReverseProxy) ServeHTTP ¶
func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler.