From 0376f59d6095b37fb383c2f8d743f3b4ae568f59 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Wed, 16 Mar 2022 18:27:33 -0700 Subject: [PATCH 1/2] Be nice to more standard http servers. Handle HTTP status codes coming from the runtime server in a way that plays nice with local development tools like the runtime interface emulator. Signed-off-by: David Calavera --- lambda-http/src/request.rs | 2 +- lambda-runtime/src/lib.rs | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lambda-http/src/request.rs b/lambda-http/src/request.rs index 63c649c6..cff30fc7 100644 --- a/lambda-http/src/request.rs +++ b/lambda-http/src/request.rs @@ -72,7 +72,7 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request Date: Wed, 16 Mar 2022 21:44:52 -0700 Subject: [PATCH 2/2] Enable http niciness only when binaries are compiled in debug mode. Signed-off-by: David Calavera --- lambda-runtime/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lambda-runtime/src/lib.rs b/lambda-runtime/src/lib.rs index bd983a23..35f3c82f 100644 --- a/lambda-runtime/src/lib.rs +++ b/lambda-runtime/src/lib.rs @@ -102,6 +102,7 @@ where let event = next_event_response?; let (parts, body) = event.into_parts(); + #[cfg(debug_assertions)] if parts.status == http::StatusCode::NO_CONTENT { // Ignore the event if the status code is 204. // This is a way to keep the runtime alive when @@ -112,6 +113,7 @@ where let body = hyper::body::to_bytes(body).await?; trace!("response body - {}", std::str::from_utf8(&body)?); + #[cfg(debug_assertions)] if parts.status.is_server_error() { error!("Lambda Runtime server returned an unexpected error"); return Err(parts.status.to_string().into());