Skip to content

feat(set_header): refactor and improve multiple header middleware#672

Merged
jlizen merged 5 commits intotower-rs:mainfrom
seun-ja:571-add-multiple-headers-in-SetResponseHeaderLayer-or-similar
May 8, 2026
Merged

feat(set_header): refactor and improve multiple header middleware#672
jlizen merged 5 commits intotower-rs:mainfrom
seun-ja:571-add-multiple-headers-in-SetResponseHeaderLayer-or-similar

Conversation

@seun-ja
Copy link
Copy Markdown
Contributor

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

Motivation

Fixes #571

Offering the ability to add multiple headers at once

Solution

For better code organisation, the response.rs file, which handles the response 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 tuple of (HeaderName, M) currently implemented in M can be HeaderValue (A test case covers this). This also helps with maintainability

seun-ja added 3 commits May 7, 2026 15:25
Signed-off-by: Aminu Oluwaseun Joshua <[email protected]>
Signed-off-by: Aminu Oluwaseun Joshua <[email protected]>
Copy link
Copy Markdown
Member

@jlizen jlizen left a comment

Choose a reason for hiding this comment

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

I like the intent here, but there are a few issues as written, see below.

Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/single_header.rs
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Comment thread tower-http/src/set_header/response/multiple_header.rs
@seun-ja seun-ja requested a review from jlizen May 8, 2026 16:24
Copy link
Copy Markdown
Member

@jlizen jlizen left a comment

Choose a reason for hiding this comment

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

@seun-ja changes look great! Just one last bit of cleanup


impl<T, M> From<(HeaderName, M)> for HeaderMetadata<T>
where
M: CloneableMakeHeaderValue<T> + Clone + 'static,
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.

We should do this based on the public traits instead:

  impl<T, M> From<(HeaderName, M)> for HeaderMetadata<T>
  where
      M: MakeHeaderValue<T> + Clone + Send + Sync + 'static,
  {
      fn from((header_name, make): (HeaderName, M)) -> Self {
          HeaderMetadata::new(header_name, make)
      }
  }

Comment thread tower-http/src/set_header/response/multiple_header.rs Outdated
Signed-off-by: Aminu Oluwaseun Joshua <[email protected]>
@seun-ja seun-ja requested a review from jlizen May 8, 2026 22:35
Copy link
Copy Markdown
Member

@jlizen jlizen left a comment

Choose a reason for hiding this comment

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

Great stuff! Thanks for the contribution. Will get a release out.

@jlizen jlizen merged commit 7551a9b into tower-rs:main May 8, 2026
12 checks passed
@seun-ja seun-ja deleted the 571-add-multiple-headers-in-SetResponseHeaderLayer-or-similar branch May 8, 2026 22:57
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 SetResponseHeaderLayer or similar

2 participants