Skip to content

Commit 30889c8

Browse files
committed
Update accept_encoding.rs
1 parent 0ce44df commit 30889c8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/content/accept_encoding.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,22 @@ mod test {
286286
assert_eq!(accept.next().unwrap(), Encoding::Brotli);
287287
Ok(())
288288
}
289+
290+
#[test]
291+
fn reorder_iter_based_on_weight() -> crate::Result<()> {
292+
let mut accept = AcceptEncoding::new();
293+
accept.push(EncodingProposal::new(Encoding::Gzip, Some(0.4))?);
294+
accept.push(EncodingProposal::new(Encoding::Brotli, Some(0.8))?);
295+
296+
let mut headers = Response::new(200);
297+
accept.apply(&mut headers);
298+
299+
let accept = AcceptEncoding::from_headers(headers)?.unwrap();
300+
let mut accept = accept.iter();
301+
assert_eq!(accept.next().unwrap(), Encoding::Brotli);
302+
assert_eq!(accept.next().unwrap(), Encoding::Gzip);
303+
Ok(())
304+
}
289305
}
290306

291307
/// Order header proposals. In the case of two proposals of equal weight we pick

0 commit comments

Comments
 (0)