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

Add AsRef/AsMut<Headers> for Request/Response #553

Merged
merged 1 commit into from
May 28, 2020

Conversation

yoshuawuyts
Copy link
Member

Adds {AsRef,AsMut}<Headers> impls for Request and Response. This is useful for generic functions that want to operate on http_types::Headers. With this Tide's req/res types can be passed directly to functions that operate on http-types's types:

fn set_custom(headers: impl AsMut<http_types::Headers>) {
    headers.insert("x-custom", "meow");
}

set_custom(&mut req);
set_custom(&mut res);

Copy link
Member

@jbr jbr left a comment

Choose a reason for hiding this comment

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

👍

src/response.rs Outdated Show resolved Hide resolved
Copy link
Member

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

Should this kind of thing be done for others, e.g. Body as well?

@yoshuawuyts
Copy link
Member Author

@Fishrock123 I was thinking probably not for Body -- we already forward AsyncRead -- but perhaps for Url, StatusCode and Method as well. But the right way to go about those is to add them to http-types first, and then forward them from tide second.

@yoshuawuyts yoshuawuyts merged commit cefa58d into master May 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

Successfully merging this pull request may close these issues.

3 participants