Skip to main content

Module gateway

Module gateway 

Source
Expand description

§Gateway Builder and Service

§Purpose

This module provides the Gateway builder struct, which is the primary entry point for configuring and constructing the runtime service stack. It orchestrates the various middleware layers (routing, authentication, error handling, metadata, etc.) into a cohesive tower::Service.

§Scope

This module defines:

  • Gateway: A builder for configuring the runtime.
  • RouterService: The core service responsible for routing and authentication.
  • UnescapingMode: Configuration for path unescaping.
  • Type aliases for various handler callbacks (ErrorHandler, AuthVerifier, etc.).

§Middleware Stack

The Gateway::into_service() method constructs a tower::Service with the following layer order (outer to inner):

  1. Tracing: Request/Response tracing.
  2. Metrics: Request duration and status recording.
  3. Error Handling: Catches errors from inner layers and converts them to HTTP responses.
  4. Response Modifiers: modifying the response before sending it back.
  5. Headers: Filtering/Transforming incoming and outgoing headers.
  6. Metadata: Extracting and injecting metadata (e.g., from headers or annotators).
  7. RouterService: The core logic (Path matching -> Auth -> Dispatch).

§Position in the Architecture

The Gateway is the glue that binds the Router (generated code registry) with the runtime features (handlers, defaults). The resulting service is typically passed to an HTTP server (like hyper).

Structs§

Gateway
A builder and configuration struct for the Gateway runtime.

Enums§

UnescapingMode
Configuration for unescaping path parameters.

Type Aliases§

AuthVerifier
A handler for verifying authentication requirements.
ErrorHandler
A handler for converting errors into HTTP responses.
HeaderMatcher
A handler for matching and transforming headers.
MetadataAnnotator
A handler for annotating requests with metadata.
MetricsRecorder
A handler for recording metrics.
ResponseModifier
A handler for modifying HTTP responses before they are sent.
TracingEndHandler
A handler for tracing end.
TracingStartHandler
A handler for tracing start. Returns an opaque token (TraceContext) to be passed to end.