Skip to content

Commit e5cf6d5

Browse files
Use base64 en/decoder from context in bindings
This updates the http binding generator to use the context's http encoder / decoder for base64 rather than relying on Buffer's implementation. We do still use Buffer for converting between utf8 and Uint8Array though.
1 parent 2794649 commit e5cf6d5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ private String getStringInputParam(
10811081
case HEADER:
10821082
// Encode these to base64 if a MediaType is present.
10831083
if (target.hasTrait(MediaTypeTrait.ID)) {
1084-
return "Buffer.from(" + baseParam + ").toString('base64')";
1084+
return "context.base64Encoder(Buffer.from(" + baseParam + "))";
10851085
}
10861086
default:
10871087
return baseParam;
@@ -2643,7 +2643,7 @@ private String getStringOutputParam(
26432643
) {
26442644
// Decode these to base64 if a MediaType is present.
26452645
if (bindingType == Location.HEADER && target.hasTrait(MediaTypeTrait.ID)) {
2646-
dataSource = "Buffer.from(" + dataSource + ", 'base64').toString('ascii')";
2646+
dataSource = "Buffer.from(context.base64Decoder(" + dataSource + ")).toString('utf8')";
26472647
}
26482648

26492649
return HttpProtocolGeneratorUtils.getStringOutputParam(

0 commit comments

Comments
 (0)