Unverified Commit 4002a740 authored by Kohei Suzuki's avatar Kohei Suzuki Committed by GitHub
Browse files

Do not append additional headers when already added by add_headers() (#566)



* Do not append additional headers when already added by add_headers()

* Add S3 protocol test and incorporate feedback

* Remove unnecessary lint attribute

Co-authored-by: default avatarJohn DiSanti <jdisanti@amazon.com>
parent d25be58a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -90,3 +90,19 @@ apply CreateMultipartUpload @httpRequestTests([
        }
    }
])

apply PutObject @httpRequestTests([
    {
        id: "DontSendMultipleContentTypeHeaders",
        documentation: "This test validates that if a content-type is specified, that only one content-type header is sent",
        method: "PUT",
        protocol: "aws.protocols#restXml",
        uri: "/test-bucket/test-key",
        headers: { "content-type": "text/html" },
        params: {
            Bucket: "test-bucket",
            Key: "test-key",
            ContentType: "text/html"
        }
    }
])
+10 −4
Original line number Diff line number Diff line
@@ -405,12 +405,18 @@ class HttpBoundProtocolGenerator(
        val contentType = httpBindingResolver.requestContentType(operationShape)
        httpBindingGenerator.renderUpdateHttpBuilder(implBlockWriter)
        httpBuilderFun(implBlockWriter) {
            rust("let builder = #T::new();", RuntimeType.HttpRequestBuilder)
            val additionalHeaders = listOf("Content-Type" to contentType) + protocol.additionalHeaders(operationShape)
            rust("let mut builder = self.update_http_builder(#T::new())?;", RuntimeType.HttpRequestBuilder)
            val additionalHeaders = listOf("content-type" to contentType) + protocol.additionalHeaders(operationShape)
            for (header in additionalHeaders) {
                rust("let builder = builder.header(${header.first.dq()}, ${header.second.dq()});")
                rust(
                    """
                    if !builder.headers_ref().map(|h| h.contains_key(${header.first.dq()})).unwrap_or(false) {
                        builder = builder.header(${header.first.dq()}, ${header.second.dq()});
                    }
                    """
                )
            }
            rust("self.update_http_builder(builder)")
            rust("Ok(builder)")
        }
    }