weirhttp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(e *weir.Engine, origin weir.Origin) http.Handler

Handler is Middleware without a next handler: every request goes through e, and CONNECT and upgrades get 501.

func Middleware

func Middleware(e *weir.Engine, origin weir.Origin) func(http.Handler) http.Handler

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

func RequestFrom(r *http.Request) *weir.Request

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

type HandlerOrigin struct{ Handler http.Handler }

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

func (o *HandlerOrigin) Fetch(ctx context.Context, req *weir.Request) (*weir.Response, error)

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.

func (*TransportOrigin) Fetch

func (o *TransportOrigin) Fetch(ctx context.Context, req *weir.Request) (*weir.Response, error)

Fetch sends req to Target exactly as given: the path goes out through URL.Opaque so net/url does not re-encode it (FR-FWD-1, INV-1).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL