autoendpoint/headers/util.rs
1//! Utilities for working with headers
2
3use actix_web::HttpRequest;
4
5/// Get a header from the request
6pub fn get_header<'r>(req: &'r HttpRequest, header: &str) -> Option<&'r str> {
7 req.headers().get(header).and_then(|h| h.to_str().ok())
8}
9
10/// Get an owned copy of a header from the request
11pub fn get_owned_header(req: &HttpRequest, header: &str) -> Option<String> {
12 get_header(req, header).map(str::to_string)
13}
14
15/// Split a string into key and value, ex. "key=value" -> "key" and "value"
16pub fn split_key_value(item: &str) -> Option<(&str, &str)> {
17 let mut splitter = item.splitn(2, '=');
18
19 Some((splitter.next()?, splitter.next()?))
20}