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

Allow arbitrary header names #422

Closed
passcod opened this issue Mar 21, 2020 · 2 comments
Closed

Allow arbitrary header names #422

passcod opened this issue Mar 21, 2020 · 2 comments

Comments

@passcod
Copy link

passcod commented Mar 21, 2020

Currently the set and append header methods on Response take a static str for the key:

pub fn set_header(self, key: &'static str, value: impl AsRef<str>) -> Self;
pub fn append_header(self, key: &'static str, value: impl AsRef<str>) -> Self;

I'd like to be able to specify arbitrary header names:

pub fn set_header(self, key: &str, value: impl AsRef<str>) -> Self;
pub fn append_header(self, key: &str, value: impl AsRef<str>) -> Self;

Example usecases:

  • echo server, copying (most) headers
  • varying header name based on configuration
  • (my immediate usecase) processing the request in a 'plugin'
@passcod
Copy link
Author

passcod commented Mar 21, 2020

For reference, my current workaround:

let mut res = tide::http::Response::builder();
res.status(meta.status);
for (key, value) in meta.headers {
    res.header(key.as_slice(), value.as_slice());
}

let res = tide::Response::from(res.body(http_service::Body::empty())?);

@Fishrock123
Copy link
Member

This has been fixed since #414 (0.7.0). The header apis now use http_types::headers::HeaderName, which uses String internally.

@passcod passcod closed this as completed Apr 28, 2020
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

No branches or pull requests

2 participants