Skip to content

Commit ffaa65c

Browse files
gautamg795Convex, Inc.
authored and
Convex, Inc.
committed
Add protos and conversion code foundations for HTTP actions (#27235)
GitOrigin-RevId: 19911022093e42a4dc092c3e76c6986b3cf35fe5
1 parent 8cee2b8 commit ffaa65c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/common/src/http/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,29 @@ pub async fn metrics() -> Result<impl IntoResponse, HttpResponseError> {
943943
Ok(output)
944944
}
945945

946+
/// Converts a [`HeaderMap`] into an iterator of key-value tuples, handling
947+
/// `None` keys by using the last seen `HeaderName`. This is needed as
948+
/// [`HeaderMap::into_iter`](http::header::HeaderMap#method.into_iter) provides
949+
/// an iterator of `(Option<HeaderName>, T)`.
950+
pub fn normalize_header_map<T>(header_map: HeaderMap<T>) -> impl Iterator<Item = (HeaderName, T)>
951+
where
952+
T: Clone,
953+
{
954+
let mut last_key: Option<HeaderName> = None;
955+
956+
header_map.into_iter().map(move |(key, value)| {
957+
match key {
958+
Some(ref key) => last_key = Some(key.clone()),
959+
None => {},
960+
}
961+
962+
let key = last_key
963+
.clone()
964+
.expect("HeaderMap should not have a None key without a previous Some key");
965+
(key, value)
966+
})
967+
}
968+
946969
#[cfg(test)]
947970
mod tests {
948971
use axum::response::IntoResponse;

0 commit comments

Comments
 (0)