Skip to content

Let applications finalize rendered admitted error responses #518

In review

Description

@ChristianPavilonis

Summary

An application can't add its own headers to the error responses EdgeZero renders for admitted requests. Middleware sees only Ok(Response), so a router miss, a 405, or a handler Err goes out without the headers the application puts on every other response.

Behavior today

  • App::dispatch_admitted_with_geo passes the request's Geo outcome to the handler context. When dispatch fails, it renders the error with the configured error renderer and builds the egress envelope (crates/edgezero-core/src/app.rs).
  • That rendered response never passes through application middleware. The application can't see it or change it.
  • The error renderer receives only the EdgeError. It has no access to the request's Geo outcome, so it can't derive Geo-dependent headers.
  • Trusted Server needs this on its native Axum path. Extract the protected CloudFront Geo baseline trusted-server#1532 removed its call because rc/identity doesn't have the API, so errors EdgeZero renders outside the router carry no Geo or Trusted Server headers.

Acceptance criteria

  • An application can install an optional, synchronous finalizer that runs once on each rendered admitted dispatch error, after the error renderer.
  • The finalizer receives the same GeoOutcome the request context received. EdgeZero doesn't resolve Geo again, and request headers or extensions the handler changed can't replace it.
  • EdgeZero keeps the failure classification, route and synthesized-response bookkeeping, and reapplies the rendered status and required protocol headers (for example Retry-After and Allow) after the finalizer runs.
  • Successful responses (including application-returned error statuses), detached errors, pre-admission refusals and admitted body-conversion errors don't call the finalizer.
  • With no finalizer installed, behavior is unchanged.
  • docs/guide/native-geo.md explains when to use middleware and when to use the finalizer.

Related

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions