File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ use std::slice;
29
29
/// accept.push(EncodingProposal::new(Encoding::Identity, None)?);
30
30
///
31
31
/// let mut res = Response::new(200);
32
- /// let encoding = accept.negotiate(&[Encoding::Gzip , Encoding::Brotli ])?;
32
+ /// let encoding = accept.negotiate(&[Encoding::Brotli , Encoding::Gzip ])?;
33
33
/// encoding.apply(&mut res);
34
34
///
35
35
/// assert_eq!(res["Content-Encoding"], "br");
@@ -135,7 +135,7 @@ impl AcceptEncoding {
135
135
Err ( err)
136
136
}
137
137
138
- /// Insert a `HeaderName` + `HeaderValue` pair into a `Headers` instance .
138
+ /// Sets the `Accept-Encoding` header .
139
139
pub fn apply ( & self , mut headers : impl AsMut < Headers > ) {
140
140
headers. as_mut ( ) . insert ( ACCEPT_ENCODING , self . value ( ) ) ;
141
141
}
Original file line number Diff line number Diff line change @@ -50,20 +50,16 @@ impl ContentEncoding {
50
50
let mut inner = None ;
51
51
52
52
for value in headers {
53
- for part in value. as_str ( ) . trim ( ) . split ( ',' ) {
54
- // Try and parse a directive from a str. If the directive is
55
- // unkown we skip it.
56
- if let Some ( entry) = Encoding :: from_str ( part) {
57
- inner = Some ( entry) ;
58
- }
53
+ if let Some ( entry) = Encoding :: from_str ( value. as_str ( ) ) {
54
+ inner = Some ( entry) ;
59
55
}
60
56
}
61
57
62
58
let inner = inner. expect ( "Headers instance with no entries found" ) ;
63
59
Ok ( Some ( Self { inner } ) )
64
60
}
65
61
66
- /// Sets the `Server-Timing ` header.
62
+ /// Sets the `Content-Encoding ` header.
67
63
pub fn apply ( & self , mut headers : impl AsMut < Headers > ) {
68
64
headers. as_mut ( ) . insert ( CONTENT_ENCODING , self . value ( ) ) ;
69
65
}
@@ -77,6 +73,11 @@ impl ContentEncoding {
77
73
pub fn value ( & self ) -> HeaderValue {
78
74
self . inner . into ( )
79
75
}
76
+
77
+ /// Access the encoding kind.
78
+ pub fn encoding ( & self ) -> Encoding {
79
+ self . inner
80
+ }
80
81
}
81
82
82
83
impl ToHeaderValues for ContentEncoding {
You can’t perform that action at this time.
0 commit comments