From 4830434e653f52acf5054f736b242a19fdf90ac6 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 19 Mar 2026 14:56:07 -0500 Subject: [PATCH 1/2] Use with_body instead of with_body_text_plain for JSON responses The with_body_text_plain method sets Content-Type to text/plain, overriding the APPLICATION_JSON type set by with_content_type. Replace all 6 occurrences in request signing endpoints with with_body which preserves the previously set Content-Type. Closes #424 --- .../src/request_signing/endpoints.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/trusted-server-core/src/request_signing/endpoints.rs b/crates/trusted-server-core/src/request_signing/endpoints.rs index 032a6fc5..c93dabe0 100644 --- a/crates/trusted-server-core/src/request_signing/endpoints.rs +++ b/crates/trusted-server-core/src/request_signing/endpoints.rs @@ -48,7 +48,7 @@ pub fn handle_trusted_server_discovery( Ok(Response::from_status(200) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&json)) + .with_body(json)) } #[derive(Debug, Deserialize, Serialize)] @@ -118,7 +118,7 @@ pub fn handle_verify_signature( Ok(Response::from_status(200) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&response_json)) + .with_body(response_json)) } #[derive(Debug, Deserialize, Serialize)] @@ -199,7 +199,7 @@ pub fn handle_rotate_key( Ok(Response::from_status(200) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&response_json)) + .with_body(response_json)) } Err(e) => { let response = RotateKeyResponse { @@ -220,7 +220,7 @@ pub fn handle_rotate_key( Ok(Response::from_status(500) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&response_json)) + .with_body(response_json)) } } } @@ -305,7 +305,7 @@ pub fn handle_deactivate_key( Ok(Response::from_status(200) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&response_json)) + .with_body(response_json)) } Err(e) => { let response = DeactivateKeyResponse { @@ -329,7 +329,7 @@ pub fn handle_deactivate_key( Ok(Response::from_status(500) .with_content_type(fastly::mime::APPLICATION_JSON) - .with_body_text_plain(&response_json)) + .with_body(response_json)) } } } From 53107e87f76ec9dbe8e037f405140b88aa1e4d54 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 23 Mar 2026 10:31:26 -0500 Subject: [PATCH 2/2] Add Content-Type assertions to request signing endpoint tests --- .../src/request_signing/endpoints.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/trusted-server-core/src/request_signing/endpoints.rs b/crates/trusted-server-core/src/request_signing/endpoints.rs index c93dabe0..1db457f4 100644 --- a/crates/trusted-server-core/src/request_signing/endpoints.rs +++ b/crates/trusted-server-core/src/request_signing/endpoints.rs @@ -366,6 +366,11 @@ mod tests { let mut resp = handle_verify_signature(&settings, req).expect("should handle verification request"); assert_eq!(resp.get_status(), StatusCode::OK); + assert_eq!( + resp.get_content_type(), + Some(fastly::mime::APPLICATION_JSON), + "should return application/json content type" + ); // Parse response let resp_body = resp.take_body_str(); @@ -403,6 +408,11 @@ mod tests { let mut resp = handle_verify_signature(&settings, req).expect("should handle verification request"); assert_eq!(resp.get_status(), StatusCode::OK); + assert_eq!( + resp.get_content_type(), + Some(fastly::mime::APPLICATION_JSON), + "should return application/json content type" + ); // Parse response let resp_body = resp.take_body_str(); @@ -584,6 +594,11 @@ mod tests { match result { Ok(mut resp) => { assert_eq!(resp.get_status(), StatusCode::OK); + assert_eq!( + resp.get_content_type(), + Some(fastly::mime::APPLICATION_JSON), + "should return application/json content type" + ); let body = resp.take_body_str(); // Parse the discovery document