Skip to content

Commit 0f2023d

Browse files
committed
fix: lowercase all headers in request serialization
The HTTP request class doesn't have any implementations to insure case-insensitivity of the http headers. So we need to be mindful when populating these headers. Otherwise, the reqeust signature will be messed up. This change will ensure the protocol-specific default headers like content-type will be overriden by the serialized header if exists. For other headers added through middleware stack either by customization or users, it wouldn't affect signing or sending as long as the request doesn't contain same header names in different casing. All the internal headers will be consistent. But users should be careful when they are adding their own headers. We don't add middleware to lowercase all headers to prevent alternating the users' customizations. Ref: aws/aws-sdk-js-v3#1800
1 parent c57cca3 commit 0f2023d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private void writeHeaders(
365365
String headerValue = getInputValue(context, binding.getLocation(), memberLocation + "!",
366366
binding.getMember(), target);
367367
writer.write("...isSerializableHeaderValue($L) && { $S: $L },",
368-
memberLocation, binding.getLocationName(), headerValue);
368+
memberLocation, binding.getLocationName().toLowerCase(Locale.US), headerValue);
369369
}
370370

371371
// Handle assembling prefix headers.
@@ -382,7 +382,8 @@ private void writeHeaders(
382382
String headerValue = getInputValue(context, binding.getLocation(),
383383
memberLocation + "![suffix]", binding.getMember(), target);
384384
// Append the prefix to key.
385-
writer.write("acc[$S + suffix] = $L;", binding.getLocationName(), headerValue);
385+
writer.write("acc[$S + suffix] = $L;",
386+
binding.getLocationName().toLowerCase(Locale.US), headerValue);
386387
writer.write("return acc;");
387388
});
388389
}

0 commit comments

Comments
 (0)