Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ private void generateClientRequestTest(OperationShape operation, HttpRequestTest
// Create a client with a custom request handler that intercepts requests.
writer.openBlock("const client = new $T({", "});\n", serviceSymbol, () -> {
writer.write("...clientParams,");
testCase.getHost().ifPresent(host -> {
writer.write("endpoint: \"https://$L\",", host);
});
writer.write("requestHandler: new RequestSerializationTestHandler(),");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ private void generateOperationRequestSerializer(
+ " input: $T,\n"
+ " context: $L\n"
+ "): Promise<$T> => {", "}", methodName, inputType, contextType, requestType, () -> {

// Get the hostname, path, 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 = $S, port, path: basePath} = await context.endpoint();", "https");

writeRequestHeaders(context, operation, bindingIndex);
writeResolvedPath(context, operation, bindingIndex, trait);
boolean hasQueryComponents = writeRequestQueryString(context, operation, bindingIndex, trait);
Expand All @@ -616,10 +621,6 @@ private void generateOperationRequestSerializer(
if (hasHostPrefix) {
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, () -> {
writer.write("protocol,");
if (hasHostPrefix) {
Expand Down Expand Up @@ -683,7 +684,9 @@ private void writeResolvedPath(
List<HttpBinding> labelBindings = bindingIndex.getRequestBindings(operation, Location.LABEL);

// Always write the bound path, but only the actual segments.
writer.write("let resolvedPath = $S;", "/" + trait.getUri().getSegments().stream()
writer.write("let resolvedPath = `$L` + $S;",
"${basePath?.endsWith('/') ? basePath.slice(0, -1) : (basePath || '')}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a unit test to add tests for these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can see, no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like protocol tests let you specify a custom endpoint, so it should be testable there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"/" + trait.getUri().getSegments().stream()
.map(Segment::toString)
.collect(Collectors.joining("/")));

Expand Down