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

# fix http headers, header could has same name key, but diff value. #39

Closed
wants to merge 1 commit into from

Conversation

tmtbe
Copy link

@tmtbe tmtbe commented Dec 6, 2023

http header could has same name key, but diff value.

ehttp/src/types.rs Show resolved Hide resolved
@tmtbe tmtbe force-pushed the master branch 2 times, most recently from 5b8d958 to 299bc28 Compare December 7, 2023 01:52
@tmtbe tmtbe force-pushed the master branch 2 times, most recently from 29c88d6 to e1da30b Compare December 8, 2023 01:25
Comment on lines +29 to +36
/// Get `Header` list from request with the given key.
pub fn get_header(&self, key: String) -> Vec<String> {
self.headers
.iter()
.filter(|h| h.0 == key)
.map(|h| h.1.clone())
.collect()
}
Copy link
Owner

Choose a reason for hiding this comment

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

This could return Vec<&str> or impl Iterator<Item = &str>.

The key should be &str

Also header_values is a better name (rust API:s don't use the get_ prefix for getters).

Suggested change
/// Get `Header` list from request with the given key.
pub fn get_header(&self, key: String) -> Vec<String> {
self.headers
.iter()
.filter(|h| h.0 == key)
.map(|h| h.1.clone())
.collect()
}
/// Get `Header` list from request with the given key.
pub fn header_values(&self, key: &str) -> impl Iterator<Item = &str> {
self.headers
.iter()
.filter(|(name, _)| name == key)
.map(|(_, value)| value.as_str())
}
/// Get the first matching header value for the given key.
pub fn header_value(&self, key: &str) -> Option<&str> {
self.header_values(key).next()
}

@emilk emilk closed this in #46 Jan 17, 2024
emilk added a commit that referenced this pull request Jan 17, 2024
* Closes #38
* Closes #39

This adds `ehttp::Headers` for storing the headers.

Incoming headers on web do NOT support duplicated headers yet.
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.

Headers need same key
2 participants