Skip to content

feat: set multiple request header#677

Merged
jlizen merged 4 commits into
tower-rs:mainfrom
seun-ja:add-multiple-headers-in-SetRequestHeaderLayer
May 14, 2026
Merged

feat: set multiple request header#677
jlizen merged 4 commits into
tower-rs:mainfrom
seun-ja:add-multiple-headers-in-SetRequestHeaderLayer

Conversation

@seun-ja

@seun-ja seun-ja commented May 12, 2026

Copy link
Copy Markdown
Contributor

Motivation

Fixes #676

Adds native support for inserting multiple header middleware per layer

Solution

For better code organisation, the request.rs file, which handles the request, is now a module and split into two files. One for setting a single header and the other for multiple, while still maintaining the current API structure.

The functions handling setting headers take a dynamic variable that implements HeaderMetadataGenerator. The newly created HeaderMetadata and a tuple of (HeaderName, M), currently implemented in M, can be HeaderValue (A test case covers this). This also helps with maintainability.

It also includes tests

The PR also moved some reused code into the root module for easy access by both request and response headers

… layer multiple header middleware

Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
@jlizen jlizen changed the title feat: set multiple response header feat: set multiple request header May 12, 2026
Comment thread tower-http/src/set_header/request/multiple_headers.rs Outdated
Comment thread tower-http/src/set_header/request/multiple_headers.rs
Comment thread tower-http/src/set_header/mod.rs
Comment thread tower-http/src/set_header/request/multiple_headers.rs Outdated
Comment thread tower-http/src/set_header/request/multiple_headers.rs Outdated
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
@seun-ja seun-ja requested a review from jlizen May 12, 2026 10:52
Comment thread tower-http/src/set_header/request/mod.rs Outdated
Comment thread tower-http/src/set_header/request/multiple_headers.rs Outdated
Comment thread tower-http/src/set_header/response/mod.rs Outdated
Comment thread tower-http/src/set_header/response/mod.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_headers.rs Outdated
Comment thread tower-http/src/set_header/mod.rs Outdated
Comment thread tower-http/src/set_header/response/mod.rs
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
@seun-ja seun-ja requested a review from jlizen May 13, 2026 23:08

@jlizen jlizen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one last Clone impl needed, sorry to scope creep you.

Comment thread tower-http/src/set_header/request/multiple_headers.rs Outdated
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
@seun-ja seun-ja requested a review from jlizen May 14, 2026 06:01
@jlizen jlizen merged commit 9c3117d into tower-rs:main May 14, 2026
12 checks passed
@seun-ja seun-ja deleted the add-multiple-headers-in-SetRequestHeaderLayer branch May 14, 2026 22:05
jlizen added a commit to jlizen/tower-http that referenced this pull request May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add multiple headers in SetRequestHeaderLayer

2 participants