poseidon-http-server

module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT

README

Poseidon HTTP/2 Server

Zero-allocation HTTP/2 + gRPC server for Go, built on poseidon-http-client codec.

Drop-in http.Handler replacement — compatible with chi, echo, gin, and any router built on net/http.

Features

  • Zero allocation — hot paths (HPACK encode, flow control, status codes) achieve 0 allocs/op
  • HTTP/2 + h2c — TLS with ALPN negotiation + clear-text (h2c) with prior-knowledge and Upgrade
  • gRPC — Unary, Server-streaming, Client-streaming, Bidi-streaming; health check + reflection
  • Middleware suite — Recovery, RequestID, AccessLog, StructuredAccessLog (slog), CORS, Gzip — plus the security & observability middleware below
  • Security hardening — HTTP/2 Rapid Reset (CVE-2023-44487) mitigation, request body-size limit, slowloris/idle timeouts, gzip decompression-bomb bound, per-client rate limiting (bounded memory), RealIP with trusted-proxy CIDRs, SecurityHeaders (HSTS / nosniff / frame-options / …)
  • Observability — Prometheus metrics (request + HTTP/2 transport counters), /healthz + /readyz with drain-aware readiness, opt-in pprof, vendor-neutral tracing hooks
  • Graceful drainShutdown(ctx) waits for in-flight streams, sends GOAWAY; readiness flips NOT-ready at drain start
  • Connection & stream limitsMaxConcurrentConnections, MaxConcurrentStreams (advertised and enforced inbound)
  • Deploy-ready — 12-factor poseidon-server binary, distroless Dockerfile, Helm chart + raw k8s manifests

Installation

go get github.com/lodgvideon/poseidon-http-server@latest

Requires Go 1.25+. The HTTP/2 and gRPC packages (server, conn, grpcserver, middleware) and the poseidon-server binary have exactly one third-party dependency — poseidon-http-client — and nothing else. http3server is the exception: QUIC packet protection brings golang.org/x/crypto and golang.org/x/sys in transitively, so import it only if you want HTTP/3 (see docs/HTTP3_SERVER_GUIDE.md).

import (
    "github.com/lodgvideon/poseidon-http-server/server"
    "github.com/lodgvideon/poseidon-http-server/grpcserver"
    "github.com/lodgvideon/poseidon-http-server/middleware"
)

Quick Start

HTTP/2 Server
srv, _ := server.NewServer(server.Options{
    Handler:     myHandler,
    IdleTimeout: 30 * time.Second,
})

ln, _ := net.Listen("tcp", ":8080")
srv.Serve(context.Background(), ln)
TLS + ALPN
srv.ListenAndServeTLS(ctx, "cert.pem", "key.pem")
gRPC Server
reg := grpcserver.NewServiceRegistrar()
reg.RegisterService(&grpcserver.ServiceDesc{
    Name: "my.Service",
    Methods: []grpcserver.MethodDesc{
        {Name: "Echo", UnaryHandler: echoHandler},
    },
})

srv, _ := server.NewServer(server.Options{
    Handler: reg.Handler(),
})
Middleware Chain
chain := server.Chain(
    middleware.Recovery(nil),
    middleware.RequestID(),
    middleware.AccessLog(logger),
)

srv, _ := server.NewServer(server.Options{
    Handler: chain(myHandler),
})
Graceful Drain
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()

go srv.Serve(ctx, ln)

<-ctx.Done()
shutdownCtx, scancel := context.WithTimeout(context.Background(), 10*time.Second)
defer scancel()
srv.Shutdown(shutdownCtx) // waits for active streams

Benchmarks

conn/ (per-frame operations)
BenchmarkWriteServerHeaders    5554 ns/op    0 B/op    0 allocs/op
BenchmarkWriteServerData       5794 ns/op    0 B/op    0 allocs/op
BenchmarkAcquireSendCredits      54 ns/op    0 B/op    0 allocs/op
BenchmarkOnWindowUpdate           39 ns/op    0 B/op    0 allocs/op
BenchmarkOnDataReceived           53 ns/op    0 B/op    0 allocs/op
grpcserver/ (gRPC hot paths)
BenchmarkStatusToHPack      2 ns/op    0 B/op    0 allocs/op
BenchmarkLookup            0 ns/op    0 B/op    0 allocs/op

Packages

Package Description
conn HTTP/2 connection management (server-side streams, flow control, HPACK)
server net.Handler-compatible HTTP/2 server with middleware, TLS, h2c
grpcserver gRPC layer: ServiceRegistrar, 4 RPC patterns, framing
middleware Recovery, RequestID, AccessLog, StructuredAccessLog (slog), Metrics, SecurityHeaders, RateLimit, RealIP, Gzip, CORS, Tracing

Requirements

Documentation

  • Usage guide — configuration, middleware catalog, security hardening, observability, and deployment.
  • Architecture Decision Records — zero-alloc contract, RFC 7540 choices, ResponseWriter interface, Rapid Reset mitigation, and more.
  • Examples — runnable servers: HTTP/2, TLS, gRPC, observability, and security.
  • Backlog — planned feature work as user stories, each with the CI gate that proves it.
  • CHANGELOG — release history and migration notes.

License

MIT

Directories

Path Synopsis
cmd
poseidon-server command
Command poseidon-server is a production-grade, 12-factor HTTP/2 server binary built on the Poseidon server, conn, and middleware packages.
Command poseidon-server is a production-grade, 12-factor HTTP/2 server binary built on the Poseidon server, conn, and middleware packages.
Package conn implements the server-side HTTP/2 connection state machine.
Package conn implements the server-side HTTP/2 connection state machine.
examples
grpc-server command
Package main demonstrates Poseidon gRPC server with all 4 RPC patterns.
Package main demonstrates Poseidon gRPC server with all 4 RPC patterns.
http-server command
Package main demonstrates Poseidon HTTP/2 server with net/http.ServeMux (Go 1.22+ pattern routing) as a drop-in replacement.
Package main demonstrates Poseidon HTTP/2 server with net/http.ServeMux (Go 1.22+ pattern routing) as a drop-in replacement.
observability-server command
Package main demonstrates the Poseidon HTTP/2 server wired for production observability: a Prometheus /metrics endpoint, structured JSON access logs (log/slog), distributed-tracing hooks, opt-in pprof profiling endpoints, and Kubernetes-style liveness (/healthz) and readiness (/readyz) probes.
Package main demonstrates the Poseidon HTTP/2 server wired for production observability: a Prometheus /metrics endpoint, structured JSON access logs (log/slog), distributed-tracing hooks, opt-in pprof profiling endpoints, and Kubernetes-style liveness (/healthz) and readiness (/readyz) probes.
push-server command
Package main demonstrates HTTP/2 Server Push (RFC 7540 §8.2) with priority hints (RFC 7540 §5.3) on the Poseidon server.
Package main demonstrates HTTP/2 Server Push (RFC 7540 §8.2) with priority hints (RFC 7540 §5.3) on the Poseidon server.
secure-server command
Package main demonstrates a hardened Poseidon HTTP/2 server that stacks the production security primitives the library ships:
Package main demonstrates a hardened Poseidon HTTP/2 server that stacks the production security primitives the library ships:
tls-server command
Package main demonstrates Poseidon HTTP/2 server with TLS + ALPN.
Package main demonstrates Poseidon HTTP/2 server with TLS + ALPN.
Package grpcserver implements gRPC-over-HTTP/2 using the server package.
Package grpcserver implements gRPC-over-HTTP/2 using the server package.
Package http3server serves HTTP/3 (RFC 9114) to an ordinary http.Handler.
Package http3server serves HTTP/3 (RFC 9114) to an ordinary http.Handler.
internal
httpfields
Package httpfields holds the inbound field rules that HTTP/2 and HTTP/3 share.
Package httpfields holds the inbound field rules that HTTP/2 and HTTP/3 share.
loadtest
loadgen command
Command loadgen is a self-contained load/soak + profiling harness for poseidon-http-server.
Command loadgen is a self-contained load/soak + profiling harness for poseidon-http-server.
Package middleware provides standard production-ready middlewares for the Poseidon HTTP/2 server.
Package middleware provides standard production-ready middlewares for the Poseidon HTTP/2 server.
Package server provides a high-level HTTP/2 server built on the conn package.
Package server provides a high-level HTTP/2 server built on the conn package.
pprof
Package pprof serves the Go runtime profiling endpoints as a Poseidon server.Handler.
Package pprof serves the Go runtime profiling endpoints as a Poseidon server.Handler.

Jump to

Keyboard shortcuts

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