Skip to content

Commit

Permalink
Add more tests for setting vary response header
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhavck authored and johnhurt committed Aug 23, 2024
1 parent 55049c4 commit 6214b8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7191487dbc8cac60270d4539babca04b6e5d406d
4c2c0ae61a505ccb25a0b39a5ca081d02fd64ba2
28 changes: 28 additions & 0 deletions pingora-core/src/protocols/http/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6214b8d

Please sign in to comment.