diff options
author | Andrew Hauck <[email protected]> | 2024-08-16 08:23:41 -0700 |
---|---|---|
committer | Kevin Guthrie <[email protected]> | 2024-08-23 17:53:13 -0400 |
commit | 6214b8d9196103af38693180aa531bcd16defe32 (patch) | |
tree | 8a81d4f142fc230f374718c7bda9c8749e4d25a0 | |
parent | 55049c4e7983055551b34feee397c736ffc912bb (diff) | |
download | pingora-6214b8d9196103af38693180aa531bcd16defe32.tar.gz pingora-6214b8d9196103af38693180aa531bcd16defe32.zip |
Add more tests for setting vary response header
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/protocols/http/compression/mod.rs | 28 |
2 files changed, 29 insertions, 1 deletions
@@ -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; |