server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultTLSConfig

func DefaultTLSConfig(cert tls.Certificate) *tls.Config

DefaultTLSConfig returns a TLS configuration suitable for HTTP/2.

func GenerateSelfSignedCert

func GenerateSelfSignedCert() (tls.Certificate, error)

GenerateSelfSignedCert creates a self-signed certificate for testing.

Types

type HTTP2Config

type HTTP2Config struct {
	// MaxConcurrentStreams per connection (default 250).
	MaxConcurrentStreams uint32
	// MaxFrameSize is the maximum frame payload size (default 16384).
	MaxFrameSize uint32
	// InitialWindowSize is the initial flow-control window (default 1MB).
	InitialWindowSize uint32
	// MaxHeaderListSize is the maximum header list size (default 1MB).
	MaxHeaderListSize uint32
}

HTTP2Config holds HTTP/2-specific server settings.

type Server

type Server struct {
	// Addr is the TCP address to listen on (e.g. ":8443").
	Addr string

	// Handler handles requests. It uses the HTTP/2 RequestCtx type, which is
	// also used for HTTP/1.1 requests via an automatic bridge when HTTP1Handler
	// is nil. This enables a single handler for both protocols.
	Handler http2.RequestHandler

	// TLSConfig is the TLS configuration. Required for ListenAndServeTLS().
	// Must include at least one certificate and should set NextProtos to
	// []string{"h2", "http/1.1"} for HTTP/2 support.
	TLSConfig *tls.Config

	// ReadTimeout is the maximum duration for reading a request.
	ReadTimeout time.Duration
	// WriteTimeout is the maximum duration for writing a response.
	WriteTimeout time.Duration
	// IdleTimeout is the maximum time to wait for the next request on a keep-alive connection.
	IdleTimeout time.Duration

	// MaxRequestBodySize limits request body size (default 4MB).
	MaxRequestBodySize int

	// HTTP2 holds HTTP/2-specific settings. If nil, defaults are used.
	HTTP2 *HTTP2Config

	// MaxConcurrentStreams per HTTP/2 connection (default 250).
	// Deprecated: use HTTP2.MaxConcurrentStreams instead.
	MaxConcurrentStreams uint32

	// WorkerPoolSize for HTTP/2 request processing (default: NumCPU * 256).
	WorkerPoolSize int

	// HTTP1Handler optionally overrides the default HTTP/1.1 handler.
	// If nil, Handler is used via an automatic protocol bridge.
	HTTP1Handler http1.RequestHandler
	// contains filtered or unexported fields
}

Server is the main BlazeHTTP server supporting HTTP/1.1 and HTTP/2.

func (*Server) Close

func (s *Server) Close() error

Close gracefully shuts down the server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the server on the configured address using plain HTTP. Supports h2c (HTTP/2 over cleartext) via connection preface detection.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS() error

ListenAndServeTLS starts the server with TLS using the pre-configured TLSConfig. TLSConfig must be set and must contain at least one certificate.

func (*Server) ListenAndServeTLSCert

func (s *Server) ListenAndServeTLSCert(cert tls.Certificate) error

ListenAndServeTLSCert starts the server with a pre-loaded TLS certificate.

func (*Server) ListenAndServeTLSFiles

func (s *Server) ListenAndServeTLSFiles(certFile, keyFile string) error

ListenAndServeTLSFiles starts the server with TLS using cert/key files.

func (*Server) Serve

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

Serve accepts connections from the listener and serves them.

Directories

Path Synopsis
Package http1 implements the HTTP/1.1 server handler for BlazeHTTP.
Package http1 implements the HTTP/1.1 server handler for BlazeHTTP.

Jump to

Keyboard shortcuts

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