Skip to content

Middleware and responses

aeronet supports ordinary request handlers, streaming handlers, and middleware that applies policy around them. Keep the handler model that matches how much output you need to retain before writing it.

Choose a response model

  • Return HttpResponse when the status, headers, and body are ready together.
  • Use HttpResponseWriter for a response produced incrementally. It handles HTTP/1.1 chunk framing and works with the streaming lifecycle.
  • Use asynchronous handlers when application work must suspend without blocking the event-loop thread.

The streaming response guide documents the writer lifecycle, trailers, and mixed streaming/non-streaming route precedence.

Add policy with middleware

Middleware can apply cross-cutting behavior such as authentication, headers, request accounting, rate limits, CORS, and compression policy. Apply it at the narrowest useful scope so route-specific behavior remains easy to reason about.

Use the detailed references for the behavior that must be explicit in production:

Error and connection behavior

The protocol layer handles framing and standard parser errors. Application handlers should make their own domain failures clear with an appropriate status and response body. For shutdown and client-disconnect behavior, read connection close semantics and the server lifecycle.