From e23bdc806a8968432eb78de2675bd69215936237 Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 23 Nov 2021 19:16:07 +0100 Subject: [PATCH] `rust-server-codegen`: don't check JSON Content-Type header if there is no body (#888) --- .../server/smithy/protocols/ServerHttpProtocolGenerator.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt index 219b2dc4e..82f43e6b9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt @@ -138,7 +138,6 @@ private class ServerHttpProtocolImplGenerator( } else { """ async fn from_request(req: &mut #{Axum}::extract::RequestParts) -> Result { - #{SmithyHttpServer}::protocols::check_json_content_type(req)?; Ok($inputName(#{parse_request}(req).await?)) } """.trimIndent() @@ -481,7 +480,10 @@ private class ServerHttpProtocolImplGenerator( """ let body = request.take_body().ok_or(#{SmithyHttpServer}::rejection::BodyAlreadyExtracted)?; let bytes = #{Hyper}::body::to_bytes(body).await?; - input = #{parser}(bytes.as_ref(), input)?; + if !bytes.is_empty() { + #{SmithyHttpServer}::protocols::check_json_content_type(request)?; + input = #{parser}(bytes.as_ref(), input)?; + } """, *codegenScope, "parser" to parser, -- GitLab