From 6239f5784ae63cdb801fe38bd87bd2dbe4f2a867 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 12 Mar 2026 20:56:37 +0100 Subject: [PATCH 1/2] Set `isBase64Encoded` based on HTTP response body type This commit changes the way `isBase64Encoded` attribute is set for the Lambda HTTP response. Currently, it is hardcoded to `false` which prevents an API endpoint from returning binary data to the caller. The problem is that Lambda uses this attribute to signal API Gateway that the response is base64 encoded which is then used by API Gateway to possibly convert the response payload to binary before sending it back to the caller. I think the change is safe because it doesn't actuate any change in isolation: an API Gateway must first be configured to convert a base64 encoded payload into binary. This setting is the `Binary media types` which indicates which `content-type` should be treated as binary (both from client and server side). More information can be found at https://docs.aws.amazon.com/apigateway/latest/developerguide/lambda-proxy-binary-media.html. --- openapi-lambda/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openapi-lambda/src/lib.rs b/openapi-lambda/src/lib.rs index 6dbaf96..e0735b1 100644 --- a/openapi-lambda/src/lib.rs +++ b/openapi-lambda/src/lib.rs @@ -34,12 +34,16 @@ pub type HttpResponse = Response; /// Serialize an [`HttpResponse`] as an [`ApiGatewayProxyResponse`]. pub fn http_response_to_apigw(response: HttpResponse) -> ApiGatewayProxyResponse { let (parts, body) = response.into_parts(); + let is_base64_encoded = match body { + Body::Binary(_) => true, + _ => false, + }; ApiGatewayProxyResponse { status_code: parts.status.as_u16() as i64, headers: Default::default(), multi_value_headers: parts.headers, body: Some(body), - is_base64_encoded: false, + is_base64_encoded: is_base64_encoded, } } From 7fc1c4e1d5947c750fffae9e4cf1a9dd127f4807 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 16 Mar 2026 12:39:32 +0100 Subject: [PATCH 2/2] Address `clippy` guidelines --- openapi-lambda/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/openapi-lambda/src/lib.rs b/openapi-lambda/src/lib.rs index e0735b1..717a108 100644 --- a/openapi-lambda/src/lib.rs +++ b/openapi-lambda/src/lib.rs @@ -34,16 +34,13 @@ pub type HttpResponse = Response; /// Serialize an [`HttpResponse`] as an [`ApiGatewayProxyResponse`]. pub fn http_response_to_apigw(response: HttpResponse) -> ApiGatewayProxyResponse { let (parts, body) = response.into_parts(); - let is_base64_encoded = match body { - Body::Binary(_) => true, - _ => false, - }; + let is_base64_encoded = matches!(body, Body::Binary(_)); ApiGatewayProxyResponse { status_code: parts.status.as_u16() as i64, headers: Default::default(), multi_value_headers: parts.headers, body: Some(body), - is_base64_encoded: is_base64_encoded, + is_base64_encoded, } }