aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Hauck <[email protected]>2024-08-16 08:23:41 -0700
committerKevin Guthrie <[email protected]>2024-08-23 17:53:13 -0400
commit6214b8d9196103af38693180aa531bcd16defe32 (patch)
tree8a81d4f142fc230f374718c7bda9c8749e4d25a0
parent55049c4e7983055551b34feee397c736ffc912bb (diff)
downloadpingora-6214b8d9196103af38693180aa531bcd16defe32.tar.gz
pingora-6214b8d9196103af38693180aa531bcd16defe32.zip
Add more tests for setting vary response header
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/protocols/http/compression/mod.rs28
2 files changed, 29 insertions, 1 deletions
diff --git a/.bleep b/.bleep
index f063994..4c5f43c 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-7191487dbc8cac60270d4539babca04b6e5d406d \ No newline at end of file
+4c2c0ae61a505ccb25a0b39a5ca081d02fd64ba2 \ No newline at end of file
diff --git a/pingora-core/src/protocols/http/compression/mod.rs b/pingora-core/src/protocols/http/compression/mod.rs
index cf37888..9bf443b 100644
--- a/pingora-core/src/protocols/http/compression/mod.rs
+++ b/pingora-core/src/protocols/http/compression/mod.rs
@@ -451,6 +451,34 @@ fn depends_on_accept_encoding(
|| (compress_enabled && compressible(resp))
}
+#[test]
+fn test_decide_on_accept_encoding() {
+ let mut resp = ResponseHeader::build(200, None).unwrap();
+ resp.insert_header("content-length", "50").unwrap();
+ resp.insert_header("content-type", "text/html").unwrap();
+ resp.insert_header("content-encoding", "gzip").unwrap();
+
+ // enabled
+ assert!(depends_on_accept_encoding(&resp, false, &[true]));
+
+ // decompress disabled => disabled
+ assert!(!depends_on_accept_encoding(&resp, false, &[false]));
+
+ // no content-encoding => disabled
+ resp.remove_header("content-encoding");
+ assert!(!depends_on_accept_encoding(&resp, false, &[true]));
+
+ // compress enabled and compressible response => enabled
+ assert!(depends_on_accept_encoding(&resp, true, &[false]));
+
+ // compress disabled and compressible response => disabled
+ assert!(!depends_on_accept_encoding(&resp, false, &[false]));
+
+ // compress enabled and not compressible response => disabled
+ resp.insert_header("content-type", "text/html+zip").unwrap();
+ assert!(!depends_on_accept_encoding(&resp, true, &[false]));
+}
+
// filter response header to see if (de)compression is needed
fn decide_action(resp: &ResponseHeader, accept_encoding: &[Algorithm]) -> Action {
use http::header::CONTENT_ENCODING;