Documentation
¶
Overview ¶
Package http2 provides helpers for HTTP/2.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server accepting both regular and proxied, both HTTP/1 and HTTP/2 connections.
HTTP/2 is negotiated using TLS ALPN, either directly via a tls.Conn, either indirectly via the PROXY protocol. When the PROXY protocol is used, the TLS-terminating proxy in front of the server must be configured to accept the "h2" TLS ALPN protocol.
The server is closed when the http.Server is.
Example ¶
ln, err := net.Listen("tcp", "localhost:80")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
proxyLn := &proxyproto.Listener{
Listener: ln,
}
server := h2proxy.NewServer(&http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello world!\n"))
}),
}, nil)
if err := server.Serve(proxyLn); err != nil {
log.Fatalf("failed to serve: %v", err)
}
Click to show internal directories.
Click to hide internal directories.