@@ -380,7 +380,7 @@ impl Headers {
380380 key : impl AsHeaderComponent ,
381381 value : impl AsHeaderComponent ,
382382 ) -> Result < Option < String > , HttpError > {
383- let key = header_name ( key. into_maybe_static ( ) ? ) ?;
383+ let key = header_name ( key) ?;
384384 let value = header_value ( value. into_maybe_static ( ) ?) ?;
385385 Ok ( self
386386 . headers
@@ -404,8 +404,10 @@ impl Headers {
404404 /// Removes all headers with a given key
405405 ///
406406 /// If there are multiple entries for this key, the first entry is returned
407- pub fn remove ( & mut self , key : & str ) -> Option < HeaderValue > {
408- self . headers . remove ( key)
407+ pub fn remove ( & mut self , key : impl AsRef < str > ) -> Option < String > {
408+ self . headers
409+ . remove ( key. as_ref ( ) )
410+ . map ( |h| h. as_str ( ) . to_string ( ) )
409411 }
410412
411413 /// Appends a value to a given key
@@ -427,6 +429,9 @@ mod sealed {
427429 /// If the component can be represented as a Cow<'static, str>, return it
428430 fn into_maybe_static ( self ) -> Result < MaybeStatic , HttpError > ;
429431
432+ /// Return a string reference to this header
433+ fn as_str ( & self ) -> Result < & str , HttpError > ;
434+
430435 /// If a component is already internally represented as a `http02x::HeaderName`, return it
431436 fn repr_as_http02x_header_name ( self ) -> Result < http0:: HeaderName , Self >
432437 where
@@ -440,18 +445,30 @@ mod sealed {
440445 fn into_maybe_static ( self ) -> Result < MaybeStatic , HttpError > {
441446 Ok ( Cow :: Borrowed ( self ) )
442447 }
448+
449+ fn as_str ( & self ) -> Result < & str , HttpError > {
450+ Ok ( self )
451+ }
443452 }
444453
445454 impl AsHeaderComponent for String {
446455 fn into_maybe_static ( self ) -> Result < MaybeStatic , HttpError > {
447456 Ok ( Cow :: Owned ( self ) )
448457 }
458+
459+ fn as_str ( & self ) -> Result < & str , HttpError > {
460+ Ok ( self )
461+ }
449462 }
450463
451464 impl AsHeaderComponent for Cow < ' static , str > {
452465 fn into_maybe_static ( self ) -> Result < MaybeStatic , HttpError > {
453466 Ok ( self )
454467 }
468+
469+ fn as_str ( & self ) -> Result < & str , HttpError > {
470+ Ok ( self . as_ref ( ) )
471+ }
455472 }
456473
457474 impl AsHeaderComponent for http0:: HeaderValue {
@@ -462,13 +479,21 @@ mod sealed {
462479 . to_string ( ) ,
463480 ) )
464481 }
482+
483+ fn as_str ( & self ) -> Result < & str , HttpError > {
484+ std:: str:: from_utf8 ( self . as_bytes ( ) ) . map_err ( HttpError :: header_was_not_a_string)
485+ }
465486 }
466487
467488 impl AsHeaderComponent for http0:: HeaderName {
468489 fn into_maybe_static ( self ) -> Result < MaybeStatic , HttpError > {
469490 Ok ( self . to_string ( ) . into ( ) )
470491 }
471492
493+ fn as_str ( & self ) -> Result < & str , HttpError > {
494+ Ok ( self . as_ref ( ) )
495+ }
496+
472497 fn repr_as_http02x_header_name ( self ) -> Result < http0:: HeaderName , Self >
473498 where
474499 Self : Sized ,
0 commit comments