File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -943,6 +943,29 @@ pub async fn metrics() -> Result<impl IntoResponse, HttpResponseError> {
943
943
Ok ( output)
944
944
}
945
945
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
+
946
969
#[ cfg( test) ]
947
970
mod tests {
948
971
use axum:: response:: IntoResponse ;
You can’t perform that action at this time.
0 commit comments