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 8bb617172e2..7858de905a3 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 @@ -227,16 +227,21 @@ private void generateOperationSerializer( HttpProtocolGeneratorUtils.writeHostPrefix(context, operation); } + // Get the hostname, port, and scheme from client's resolved endpoint. Then construct the request from + // them. The client's resolved endpoint can be default one or supplied by users. + writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();"); writer.openBlock("return new $T({", "});", requestType, () -> { if (hasHostPrefix) { writer.write("hostname: resolvedHostname,"); } - writer.write("protocol: \"https\","); + writer.write("protocol,"); + writer.write("hostname,"); + writer.write("port,"); writer.write("method: $S,", trait.getMethod()); - writer.write("headers: headers,"); + writer.write("headers,"); writer.write("path: resolvedPath,"); if (hasQueryComponents) { - writer.write("query: query,"); + writer.write("query,"); } if (!bodyBindings.isEmpty()) { // Track all shapes bound to the body so their serializers may be generated. @@ -246,8 +251,7 @@ private void generateOperationSerializer( .forEach(serializingDocumentShapes::add); } // Always set the body, - writer.write("body: body,"); - writer.write("...context.endpoint,"); + writer.write("body,"); }); }); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java index 8ff75bc339a..d12354f2c7e 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpRpcProtocolGenerator.java @@ -100,19 +100,23 @@ public void generateSharedComponents(GenerationContext context) { writer.addUseImports(requestType); writer.addImport("SerdeContext", "__SerdeContext", "@aws-sdk/types"); writer.addImport("HeaderBag", "__HeaderBag", "@aws-sdk/types"); - writer.openBlock("const buildHttpRpcRequest = (\n" + writer.openBlock("const buildHttpRpcRequest = async (\n" + " context: __SerdeContext,\n" + " headers: __HeaderBag,\n" + " path: string,\n" + " resolvedHostname: string | undefined,\n" + " body: any,\n" - + "): $T => {", "};", requestType, () -> { + + "): Promise<$T> => {", "};", requestType, () -> { + // Get the hostname, port, and scheme from client's resolved endpoint. Then construct the request from + // them. The client's resolved endpoint can be default one or supplied by users. + writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();"); writer.openBlock("const contents: any = {", "};", () -> { - writer.write("protocol: \"https\","); + writer.write("protocol,"); + writer.write("hostname,"); + writer.write("port,"); writer.write("method: \"POST\","); - writer.write("path: path,"); - writer.write("headers: headers,"); - writer.write("...context.endpoint,"); + writer.write("path,"); + writer.write("headers,"); }); writer.openBlock("if (resolvedHostname !== undefined) {", "}", () -> { writer.write("contents.hostname = resolvedHostname;");