httpd

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package httpd implements the minimal HTTP/1.1 server vminitd needs to serve Connect RPCs over vsock.

It exists for one reason: naming http.Server links crypto/tls. net/http's (*conn).serve type-asserts its net.Conn to *tls.Conn, which keeps *tls.Conn's method set — and behind it the handshake, x509 chain verification, the NIST curves and math/big — reachable. Measured on this contract, avoiding http.Server removes 1.50 MiB (16.3%) from the guest binary and drops crypto/tls from 729 linked symbols to 19. vsock never negotiates TLS, so all of that is dead weight inside PID 1, multiplied by every initfs we ship.

This package still imports net/http — for http.Handler, http.ReadRequest and http.Header, which cost nothing — it just never references http.Server.

Scope

This is NOT a general-purpose HTTP server and must not be used as one. It serves a single trusted peer (the host, enforced by the caller's listener before Accept returns) speaking one protocol (Connect over HTTP/1.1, unary plus server-streaming). Everything below is written for that contract:

  • No TLS. The transport is vsock.
  • No HTTP/2. Bidi streaming is the only thing that would need it, and this contract has none.
  • No request-body size limit. WriteFile legitimately carries large payloads; bounding it belongs in connecthttp.WithReadMaxBytes, where the error can name the RPC, not here where it can only close the connection.
  • No Date header, no automatic HEAD/Range/conditional handling. Connect never issues those.

Failure policy

This runs as PID 1 in a VM with no supervisor: a process exit panics the kernel. So every request is served under a recover, and no parse error, handler panic or write failure may take the process down — the blast radius of anything going wrong is one connection.

Index

Constants

This section is empty.

Variables

View Source
var ErrServerClosed = errors.New("httpd: server closed")

ErrServerClosed is returned by Serve when the listener is closed.

Functions

This section is empty.

Types

type Server

type Server struct {
	// Handler receives every request. Required.
	Handler http.Handler

	// ReadHeaderTimeout bounds how long a peer may take to finish sending a
	// request head ONCE IT HAS STARTED. It deliberately does not cover idle time
	// between requests — see serveConn.
	ReadHeaderTimeout time.Duration

	// Logf receives connection-level anomalies: panics, malformed requests. Nil
	// discards them.
	Logf func(format string, args ...any)
}

Server serves HTTP/1.1 on a listener. The zero value is not useful: Handler must be set.

func (*Server) Serve

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

Serve accepts connections and serves each in its own goroutine. It returns only when the listener fails, which for vminitd means shutdown.

Unlike net/http, there is no retry-on-temporary-error loop: the caller's listener already filters non-host peers and returns their rejection as a dropped connection rather than an error, so an error here is terminal.

Jump to

Keyboard shortcuts

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