http2

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

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)
}
Output:

func NewServer

func NewServer(h1 *http.Server, h2 *http2.Server) *Server

NewServer creates a new HTTP server.

A nil h2 is equivalent to a zero http2.Server.

func (*Server) Serve

func (srv *Server) Serve(ln net.Listener) error

Serve accepts incoming connections on the listener ln.

Jump to

Keyboard shortcuts

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