@@ -10,7 +10,14 @@ impl<'a> Headers<'a> {
10
10
/// Sets a new value for an existing header or adds the header if
11
11
/// it does not already exist.
12
12
pub fn set ( & mut self , header : Header < ' a > ) {
13
- self . 0 . retain ( |Header { name, .. } | & header. name != name) ;
13
+ self . 0 . retain ( |old_header| header. name != old_header. name ) ;
14
+ self . 0 . push ( header) ;
15
+ }
16
+
17
+ /// Add the header.
18
+ ///
19
+ /// Headers with the same name are not modified or removed.
20
+ pub fn add ( & mut self , header : Header < ' a > ) {
14
21
self . 0 . push ( header) ;
15
22
}
16
23
}
@@ -33,7 +40,7 @@ pub struct Header<'a> {
33
40
impl < ' a > Header < ' a > {
34
41
/// Create `Content-Type` header.
35
42
pub fn content_type ( value : impl Into < Cow < ' a , str > > ) -> Header < ' a > {
36
- Self :: custom ( "Content-Type" , value. into ( ) )
43
+ Self :: custom ( "Content-Type" , value)
37
44
}
38
45
39
46
/// Create `Authorization` header.
@@ -42,8 +49,8 @@ impl<'a> Header<'a> {
42
49
}
43
50
44
51
/// Create `Authorization: Bearer xxx` header.
45
- pub fn bearer ( value : impl Into < Cow < ' a , str > > ) -> Header < ' a > {
46
- Self :: custom ( "Authorization" , format ! ( "Bearer {}" , value . into ( ) ) )
52
+ pub fn bearer ( token : & str ) -> Header < ' a > {
53
+ Self :: custom ( "Authorization" , format ! ( "Bearer {}" , token ) )
47
54
}
48
55
49
56
/// Create custom header.
0 commit comments