Documentation
¶
Overview ¶
Package http provides HTTP transport capabilities that complement net/http. Its Transport discovers HTTP/3 through Alt-Svc and safely falls back through net/http's HTTP/2 and HTTP/1.1 negotiation.
Index ¶
- Variables
- func Get(url string) (*nethttp.Response, error)
- func Head(url string) (*nethttp.Response, error)
- func Post(url, contentType string, body io.Reader) (*nethttp.Response, error)
- func PostForm(target string, data url.Values) (*nethttp.Response, error)
- func RouteHandler(pattern route.Pattern, handler route.Handler) nethttp.Handler
- func WithHTTP3Capability(ctx context.Context) context.Context
- type Mode
- type Server
- type Transport
- func (t *Transport) CloseIdleConnections()
- func (t *Transport) ForgetHTTP3(u *url.URL)
- func (t *Transport) MarkHTTP3(u *url.URL, until time.Time)
- func (t *Transport) ObserveAltSvc(u *url.URL, values []string, now time.Time)
- func (t *Transport) RoundTrip(req *nethttp.Request) (*nethttp.Response, error)
- func (t *Transport) SupportsHTTP3(u *url.URL) bool
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = &nethttp.Client{Transport: DefaultTransport}
DefaultClient is ready for ordinary HTTP use with automatic HTTP/3. Its methods have the same shape as net/http.Client.
var DefaultTransport = &Transport{}
DefaultTransport automatically learns HTTP/3 through Alt-Svc and safely falls back through HTTP/2 and HTTP/1.1. It is shared by DefaultClient.
Functions ¶
func Get ¶ added in v0.23.0
Get uses DefaultClient, including automatic HTTP/3 discovery and fallback.
func Head ¶ added in v0.23.0
Head uses DefaultClient, including automatic HTTP/3 discovery and fallback.
func Post ¶ added in v0.23.0
Post uses DefaultClient, including automatic HTTP/3 discovery and fallback.
func PostForm ¶ added in v0.23.0
PostForm uses DefaultClient, including automatic HTTP/3 discovery and fallback.
func RouteHandler ¶ added in v0.25.0
RouteHandler bridges the pattern-indexed std/http/route layer into the protocol-negotiating Server. Go+ checks Pattern[p] and Handler[p] before erasure; ordinary Go receives the retained runtime boundary guard.
Types ¶
type Server ¶
type Server struct {
Handler nethttp.Handler
TLSConfig *tls.Config
QUICConfig *quic.Config
NativeQUICConfig *nativehttp3.RFC9000Config
// XQUICConfig is retained for compatibility. NativeQUICConfig takes
// precedence when both are set.
// Deprecated: use NativeQUICConfig.
XQUICConfig *nativehttp3.RFC9000Config
HTTP *nethttp.Server
// NativeHTTP3 opts into and customizes the experimental native server.
// When both HTTP3 and NativeHTTP3 are nil, the RFC 9368/9369-capable
// quic-go server is used so QUIC v1 and v2 work out of the box.
NativeHTTP3 *nativehttp3.NativeServer
// HTTP3 customizes the default quic-go server.
HTTP3 *refhttp3.Server
// contains filtered or unexported fields
}
Server serves one net/http Handler over HTTP/3 and TLS-based HTTP/2 or HTTP/1.1. The zero value requires TLSConfig to be set before Serve.
type Transport ¶
type Transport struct {
Mode Mode
// PriorKnowledge tries HTTP/3 for every HTTPS origin before an Alt-Svc
// advertisement has been observed.
PriorKnowledge bool
TLSClientConfig *tls.Config
QUICConfig *quic.Config
// HTTP3 and Fallback permit shared or instrumented transports. Nil values
// use an HTTP/3 transport and net/http.DefaultTransport respectively.
HTTP3 nethttp.RoundTripper
Fallback nethttp.RoundTripper
// contains filtered or unexported fields
}
Transport implements net/http.RoundTripper with HTTP/3 -> HTTP/2 -> HTTP/1.1 selection. The zero value is ready for use.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes idle connections owned by both transport tiers.
func (*Transport) ForgetHTTP3 ¶
ForgetHTTP3 removes learned capability after a failed HTTP/3 attempt.
func (*Transport) MarkHTTP3 ¶
MarkHTTP3 records prior knowledge for an origin until the supplied time.
func (*Transport) ObserveAltSvc ¶
ObserveAltSvc records an h3 alternative, including an alternative host or UDP port, while retaining the origin host for TLS verification and HTTP authority.