Skip to content

Commit 0187232

Browse files
feat(compression): avoid setting Vary: Accept-Encoding when already set (#572)
1 parent f64fbe6 commit 0187232

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tower-http/src/compression/future.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ where
4747

4848
let (mut parts, body) = res.into_parts();
4949

50-
if should_compress {
50+
if should_compress
51+
&& !parts.headers.get_all(header::VARY).iter().any(|value| {
52+
contains_ignore_ascii_case(
53+
value.as_bytes(),
54+
header::ACCEPT_ENCODING.as_str().as_bytes(),
55+
)
56+
})
57+
{
5158
parts
5259
.headers
5360
.append(header::VARY, header::ACCEPT_ENCODING.into());
@@ -113,3 +120,14 @@ where
113120
Poll::Ready(Ok(res))
114121
}
115122
}
123+
124+
fn contains_ignore_ascii_case(mut haystack: &[u8], needle: &[u8]) -> bool {
125+
while haystack.len() <= needle.len() {
126+
if haystack[..needle.len()].eq_ignore_ascii_case(needle) {
127+
return true;
128+
}
129+
haystack = &haystack[1..];
130+
}
131+
132+
false
133+
}

0 commit comments

Comments
 (0)