diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java index 598887345fd..518fb0643d6 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java @@ -58,7 +58,6 @@ import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase; import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait; import software.amazon.smithy.utils.IoUtils; -import software.amazon.smithy.utils.ListUtils; import software.amazon.smithy.utils.MapUtils; import software.amazon.smithy.utils.Pair; @@ -79,10 +78,6 @@ final class HttpProtocolTestGenerator implements Runnable { private static final Logger LOGGER = Logger.getLogger(HttpProtocolTestGenerator.class.getName()); private static final String TEST_CASE_FILE_TEMPLATE = "tests/functional/%s.spec.ts"; - // Headers that are generated by other sources that need to be normalized in the - // test cases to match. - private static final List HEADERS_TO_NORMALIZE = ListUtils.of("content-length", "content-type"); - private final TypeScriptSettings settings; private final Model model; private final ShapeId protocol; @@ -255,30 +250,22 @@ private void writeRequestQueryAssertions(HttpRequestTestCase testCase) { private void writeRequestHeaderAssertions(HttpRequestTestCase testCase) { testCase.getRequireHeaders().forEach(requiredHeader -> { - writer.write("expect(r.headers[$S]).toBeDefined();", normalizeHeaderName(requiredHeader)); + writer.write("expect(r.headers[$S]).toBeDefined();", requiredHeader.toLowerCase()); }); writer.write(""); testCase.getForbidHeaders().forEach(forbidHeader -> - writer.write("expect(r.headers[$S]).toBeUndefined();", normalizeHeaderName(forbidHeader))); + writer.write("expect(r.headers[$S]).toBeUndefined();", forbidHeader.toLowerCase())); writer.write(""); testCase.getHeaders().forEach((header, value) -> { - header = normalizeHeaderName(header); + header = header.toLowerCase(); writer.write("expect(r.headers[$S]).toBeDefined();", header); writer.write("expect(r.headers[$S]).toBe($S);", header, value); }); writer.write(""); } - private String normalizeHeaderName(String headerName) { - if (HEADERS_TO_NORMALIZE.contains(headerName.toLowerCase())) { - return headerName.toLowerCase(); - } - - return headerName; - } - private void writeRequestBodyAssertions(OperationShape operation, HttpRequestTestCase testCase) { testCase.getBody().ifPresent(body -> { // If we expect an empty body, expect it to be falsy. diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java index 33353cd6209..1efc80be9c7 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java @@ -365,7 +365,7 @@ private void writeHeaders( String headerValue = getInputValue(context, binding.getLocation(), memberLocation + "!", binding.getMember(), target); writer.write("...isSerializableHeaderValue($L) && { $S: $L },", - memberLocation, binding.getLocationName(), headerValue); + memberLocation, binding.getLocationName().toLowerCase(Locale.US), headerValue); } // Handle assembling prefix headers. @@ -376,15 +376,16 @@ private void writeHeaders( // Iterate through each entry in the member. writer.openBlock("...($1L !== undefined) && Object.keys($1L).reduce(", "),", memberLocation, () -> { - writer.openBlock("(acc: any, suffix: string) => {", "}, {}", - () -> { - // Use a ! since we already validated the input member is defined above. - String headerValue = getInputValue(context, binding.getLocation(), - memberLocation + "![suffix]", binding.getMember(), target); - // Append the prefix to key. - writer.write("acc[$S + suffix] = $L;", binding.getLocationName(), headerValue); - writer.write("return acc;"); - }); + writer.openBlock("(acc: any, suffix: string) => ({", "}), {}", + () -> { + // Use a ! since we already validated the input member is defined above. + String headerValue = getInputValue(context, binding.getLocation(), + memberLocation + "![suffix]", binding.getMember(), target); + writer.write("...acc,"); + // Append the prefix to key. + writer.write("[`$L$${suffix.toLowerCase()}`]: $L,", + binding.getLocationName().toLowerCase(Locale.US), headerValue); + }); } ); }