default enable compression, update test helpers (#10102)

set `enable_request_compression` flag to default-enabled.

update integration test helpers to decompress `zstd` if flag set.
This commit is contained in:
sayan-oai
2026-01-28 12:25:40 -08:00
committed by GitHub
parent fe920d7804
commit ff9fa56368
4 changed files with 37 additions and 5 deletions

View File

@@ -76,9 +76,32 @@ impl ResponseMock {
#[derive(Debug, Clone)]
pub struct ResponsesRequest(wiremock::Request);
fn is_zstd_encoding(value: &str) -> bool {
value
.split(',')
.any(|entry| entry.trim().eq_ignore_ascii_case("zstd"))
}
fn decode_body_bytes(body: &[u8], content_encoding: Option<&str>) -> Vec<u8> {
if content_encoding.is_some_and(is_zstd_encoding) {
zstd::stream::decode_all(std::io::Cursor::new(body)).unwrap_or_else(|err| {
panic!("failed to decode zstd request body: {err}");
})
} else {
body.to_vec()
}
}
impl ResponsesRequest {
pub fn body_json(&self) -> Value {
self.0.body_json().unwrap()
let body = decode_body_bytes(
&self.0.body,
self.0
.headers
.get("content-encoding")
.and_then(|value| value.to_str().ok()),
);
serde_json::from_slice(&body).unwrap()
}
pub fn body_bytes(&self) -> Vec<u8> {
@@ -105,7 +128,7 @@ impl ResponsesRequest {
}
pub fn input(&self) -> Vec<Value> {
self.0.body_json::<Value>().unwrap()["input"]
self.body_json()["input"]
.as_array()
.expect("input array not found in request")
.clone()
@@ -1083,7 +1106,14 @@ fn validate_request_body_invariants(request: &wiremock::Request) {
if request.method != "POST" || !request.url.path().ends_with("/responses") {
return;
}
let Ok(body): Result<Value, _> = request.body_json() else {
let body_bytes = decode_body_bytes(
&request.body,
request
.headers
.get("content-encoding")
.and_then(|value| value.to_str().ok()),
);
let Ok(body): Result<Value, _> = serde_json::from_slice(&body_bytes) else {
return;
};
let Some(items) = body.get("input").and_then(Value::as_array) else {