Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Clone for AppendHeaders #2774

Closed
1 task done
jbirnick opened this issue Jun 7, 2024 · 1 comment · Fixed by #2776
Closed
1 task done

Implement Clone for AppendHeaders #2774

jbirnick opened this issue Jun 7, 2024 · 1 comment · Fixed by #2776

Comments

@jbirnick
Copy link
Contributor

jbirnick commented Jun 7, 2024

  • I have looked for existing issues (including closed) about this

Feature Request

Please implement Clone for AppendHeaders.

Motivation

I need it in my project. I once and forever create an AppendHeaders object which contains some headers that I add to every response. However, when I create a response, the AppendHeaders object is consumed by into_response_parts(...) of IntoResponseParts. So I need to be able to clone it for every response.

Proposal

Add a #[derive(Clone)] to the AppendHeaders struct.

...
#[derive(Clone)]
pub struct AppendHeaders<I>(pub I);

Alternatives

I guess could only store the contents of my AppendHeaders object, which I can clone, and then construct a new AppendHeaders object from cloned contents for every reponse. However, I really want to store the wrapping AppendHeaders object, because that it the correct semantics.

I think it's very natural that AppendHeaders should be clonable (if the contents are clonable), and I'm surprised that it's not already implemented.

@jbirnick jbirnick changed the title implement Clone for AppendHeaders Implement Clone for AppendHeaders Jun 7, 2024
@jplatte
Copy link
Member

jplatte commented Jun 7, 2024

Seems reasonable, and we already derive this for many extractors, as well as the Html response wrappers.
Do you want to send a PR? Deriving Copy would be good as well for consistency.

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 a pull request may close this issue.

2 participants