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
5 changes: 5 additions & 0 deletions .changeset/nervous-lies-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/core": patch
---

drain stream in httpBindingProtocol with unit output
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { op } from "@smithy/core/schema";
import { streamCollector } from "@smithy/node-http-handler";
import { HttpResponse } from "@smithy/protocol-http";
import type {
$Schema,
Expand All @@ -20,6 +21,7 @@ import type {
TimestampEpochSecondsSchema,
} from "@smithy/types";
import { parseUrl } from "@smithy/url-parser/src";
import { Readable } from "node:stream";
import { describe, expect, test as it } from "vitest";

import { HttpBindingProtocol } from "./HttpBindingProtocol";
Expand Down Expand Up @@ -244,4 +246,42 @@ describe(HttpBindingProtocol.name, () => {
expect(request.path).toMatch(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/);
expect(request.headers?.["header-token"]).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
});

it("should discard response bodies for Unit operation outputs, making no attempt to parse them", async () => {
const protocol = new StringRestProtocol();
let streamProgress = 0;
const response = await protocol.deserializeResponse(
op("", "", {}, "unit", "unit"),
{
streamCollector: streamCollector,
} as any,
new HttpResponse({
statusCode: 200,
headers: {},
body: Readable.from({
async *[Symbol.asyncIterator]() {
yield "@";
streamProgress = 25;
yield "#";
streamProgress = 50;
yield "$";
streamProgress = 75;
yield "%";
streamProgress = 100;
},
}),
})
);

expect(response).toEqual({
$metadata: {
cfId: undefined,
extendedRequestId: undefined,
httpStatusCode: 200,
requestId: undefined,
},
});

expect(streamProgress).toBe(100);
});
});
13 changes: 9 additions & 4 deletions packages/core/src/submodules/protocols/HttpBindingProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export abstract class HttpBindingProtocol extends HttpProtocol {
}
// Due to Smithy validation, we can assume that the members with no HTTP
// bindings DO NOT contain an event stream.
} else if (nonHttpBindingMembers.discardResponseBody) {
await collectBody(response.body, context);
}

dataObject.$metadata = this.deserializeMetadata(response);
Expand All @@ -247,35 +249,37 @@ export abstract class HttpBindingProtocol extends HttpProtocol {
response: IHttpResponse,
headerBindings: Set<string>,
dataObject: any
): Promise<string[]>;
): Promise<string[] & { discardResponseBody?: boolean }>;
protected async deserializeHttpMessage(
schema: Schema,
context: HandlerExecutionContext & SerdeFunctions,
response: IHttpResponse,
dataObject: any
): Promise<string[]>;
): Promise<string[] & { discardResponseBody?: boolean }>;
protected async deserializeHttpMessage(
schema: Schema,
context: HandlerExecutionContext & SerdeFunctions,
response: IHttpResponse,
arg4: unknown,
arg5?: unknown
): Promise<string[]> {
): Promise<string[] & { discardResponseBody?: boolean }> {
let dataObject: any;
if (arg4 instanceof Set) {
dataObject = arg5;
} else {
dataObject = arg4;
}

let discardResponseBody = true;
const deserializer = this.deserializer;
const ns = NormalizedSchema.of(schema);
const nonHttpBindingMembers = [] as string[];
const nonHttpBindingMembers = [] as string[] & { discardResponseBody?: boolean };

for (const [memberName, memberSchema] of ns.structIterator()) {
const memberTraits = memberSchema.getMemberTraits();

if (memberTraits.httpPayload) {
discardResponseBody = false;
const isStreaming = memberSchema.isStreaming();
if (isStreaming) {
const isEventStream = memberSchema.isStructSchema();
Expand Down Expand Up @@ -339,6 +343,7 @@ export abstract class HttpBindingProtocol extends HttpProtocol {
nonHttpBindingMembers.push(memberName);
}
}
nonHttpBindingMembers.discardResponseBody = discardResponseBody;
return nonHttpBindingMembers;
}
}
Loading