Skip to content

Commit 0ce44df

Browse files
committed
Update accept_encoding.rs
1 parent 3f15cfd commit 0ce44df

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/content/accept_encoding.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,26 @@ mod test {
270270
assert_eq!(accept.iter().next().unwrap(), Encoding::Gzip);
271271
Ok(())
272272
}
273+
274+
#[test]
275+
fn iter() -> crate::Result<()> {
276+
let mut accept = AcceptEncoding::new();
277+
accept.push(Encoding::Gzip);
278+
accept.push(Encoding::Brotli);
279+
280+
let mut headers = Response::new(200);
281+
accept.apply(&mut headers);
282+
283+
let accept = AcceptEncoding::from_headers(headers)?.unwrap();
284+
let mut accept = accept.iter();
285+
assert_eq!(accept.next().unwrap(), Encoding::Gzip);
286+
assert_eq!(accept.next().unwrap(), Encoding::Brotli);
287+
Ok(())
288+
}
289+
}
290+
291+
/// Order header proposals. In the case of two proposals of equal weight we pick
292+
/// the one that was declared last.
293+
fn sort_proposals<T: PartialOrd>(props: &mut Vec<T>) {
294+
props.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Less))
273295
}

0 commit comments

Comments
 (0)