tower-rs / tower-rs/tower-http

A means to propagate state between the layers that run before the service function, and those that run after.

Open
#423 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-new-middleware
Dominant language
Rust
Stars
913
Forks
231
Avg merge
1d 20h
Merged PRs (30d)
8

Description

Feature Request

A middleware to be used as a way of sharing state between "pre service" layers/filters etc and those that run "post service", particularly when the service itself is unaware of that state.

Motivation

The concrete motivation in my case is the "as lite-a-touch-as-possible" approach to wrapping AWS Lambda functions (eventually in any language, but initially in Rust) with layers that enforce our enterprise policy and aid in homogenizing the interface that the Lambda function is written to - specifically for AWS API Gateway API invocations.

These layers examine the request and need to set various state values that are then used by the layers that run after the Lambda function has returned. The problem is, of course, that the Lambda function consumes the request and produces a response.

The propagate_header middleware is addressing a very similar use case for headers.

Proposal

Effectively, copy the propagate_header middleware and change its semantics to be those of http::Request and Response extensions!

Alternatives

There are of course many ways that Layer developers might be able to propagate such state when necessary - but they all rely on the same need - to save the state off "somewhere" when invoking the request/response service and retrieve when the response is ready. This scheme of exploiting the request and response extensions mechanism within a propagation middleware is an extremely convenient way to achieve this in a generic fashion.

I am in the process of creating this middleware - see PR #425

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing propagate_header middleware and the linked PR #425, which contains the work already in progress. Confirm that the proposed middleware supports state propagation through request and response extensions between pre-service and post-service layers.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.