Documentation
¶
Overview ¶
Package weirhttp adapts a weir.Engine to net/http: middleware and a handler that serve requests through the engine, conversions between net/http and weir types, and an Origin backed by an http.RoundTripper. The adapter's duties are listed in docs/03-hld.md §5 and its API in docs/04-lld.md §10.
Index ¶
- func Handler(e *weir.Engine, origin weir.Origin) http.Handler
- func Middleware(e *weir.Engine, origin weir.Origin) func(http.Handler) http.Handler
- func RequestFrom(r *http.Request) *weir.Request
- func WriteError(w http.ResponseWriter, err error)
- func WriteResponse(w http.ResponseWriter, resp *weir.Response) error
- type HandlerOrigin
- type TransportOrigin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler is Middleware without a next handler: every request goes through e, and CONNECT and upgrades get 501.
func Middleware ¶
Middleware serves requests through e, using origin for misses. CONNECT and protocol upgrades go to next directly, outside the engine and its limiter (FR-UPG-1).
func RequestFrom ¶
RequestFrom builds the engine request from r. Path and RawQuery come from the raw request target, so the engine keys and forwards the bytes the client sent (FR-FWD-1, INV-1). Absolute-form targets are cut after the authority; other targets fall back to the parsed URL.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError writes the status that weir.StatusCode maps err to, with Retry-After when weir.RetryAfter has a hint. It writes nothing when the client has gone away (status 499).
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, resp *weir.Response) error
WriteResponse writes resp to w, without hop-by-hop fields, and closes its body.
Types ¶
type HandlerOrigin ¶
HandlerOrigin calls an in-process http.Handler, buffering nothing: the handler runs on its own goroutine and writes into a pipe that becomes the response body. The Caddy adapter reuses this shape for next (08).
func (*HandlerOrigin) Fetch ¶
Fetch returns once the handler writes headers or returns. Cancelling ctx, or closing the returned body, cancels the handler's context and fails its writes and any body read in progress (03 §5). A handler that ignores its context and never writes keeps its goroutine until it returns, past Engine.Close too.
type TransportOrigin ¶
type TransportOrigin struct {
// Target holds the scheme and host of the origin. Its path is ignored.
Target *url.URL
// Transport sends the requests. Nil means a clone of
// http.DefaultTransport with DisableCompression set and no Proxy. A
// custom *http.Transport must do the same: compression adds an unkeyed
// Accept-Encoding: gzip to requests that carry none (INV-1), and through
// a forward proxy the URL.Opaque path goes out as an origin-form target.
Transport http.RoundTripper
// Rewrite, when set, edits each outgoing request (Via, origin auth).
// Headers it adds to cacheable requests are unkeyed input (T-4).
Rewrite func(*http.Request)
}
TransportOrigin sends forwarded requests to Target with Transport.