@aws-sdk/middleware-websocket 3.972.2 → 3.972.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -64,19 +64,21 @@ class EventStreamPayloadHandler {
64
64
  }
65
65
  const placeHolderStream = new TransformStream();
66
66
  request.body = placeHolderStream.readable;
67
+ const match = (headers?.authorization ?? "").match(/Signature=(\w+)$/);
68
+ const priorSignature = (match ?? [])[1] ?? (query && query["X-Amz-Signature"]) ?? "";
69
+ const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
70
+ payload.pipeThrough(signingStream).pipeThrough(placeHolderStream);
67
71
  let result;
68
72
  try {
69
73
  result = await next(args);
70
74
  }
71
75
  catch (e) {
72
- request.body.cancel();
76
+ const p = payload.cancel?.();
77
+ if (p instanceof Promise) {
78
+ p.catch(() => { });
79
+ }
73
80
  throw e;
74
81
  }
75
- const match = (headers["authorization"] || "").match(/Signature=([\w]+)$/);
76
- const priorSignature = (match || [])[1] || (query && query["X-Amz-Signature"]) || "";
77
- const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
78
- const signedPayload = payload.pipeThrough(signingStream);
79
- signedPayload.pipeThrough(placeHolderStream);
80
82
  return result;
81
83
  }
82
84
  }
@@ -310,8 +312,13 @@ class WebSocketFetchHandler {
310
312
  };
311
313
  const send = async () => {
312
314
  try {
313
- for await (const inputChunk of data) {
314
- socket.send(inputChunk);
315
+ for await (const chunk of data) {
316
+ if (socket.readyState >= WebSocket.CLOSING) {
317
+ break;
318
+ }
319
+ else {
320
+ socket.send(chunk);
321
+ }
315
322
  }
316
323
  }
317
324
  catch (err) {
@@ -17,19 +17,21 @@ export class EventStreamPayloadHandler {
17
17
  }
18
18
  const placeHolderStream = new TransformStream();
19
19
  request.body = placeHolderStream.readable;
20
+ const match = (headers?.authorization ?? "").match(/Signature=(\w+)$/);
21
+ const priorSignature = (match ?? [])[1] ?? (query && query["X-Amz-Signature"]) ?? "";
22
+ const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
23
+ payload.pipeThrough(signingStream).pipeThrough(placeHolderStream);
20
24
  let result;
21
25
  try {
22
26
  result = await next(args);
23
27
  }
24
28
  catch (e) {
25
- request.body.cancel();
29
+ const p = payload.cancel?.();
30
+ if (p instanceof Promise) {
31
+ p.catch(() => { });
32
+ }
26
33
  throw e;
27
34
  }
28
- const match = (headers["authorization"] || "").match(/Signature=([\w]+)$/);
29
- const priorSignature = (match || [])[1] || (query && query["X-Amz-Signature"]) || "";
30
- const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
31
- const signedPayload = payload.pipeThrough(signingStream);
32
- signedPayload.pipeThrough(placeHolderStream);
33
35
  return result;
34
36
  }
35
37
  }
@@ -132,8 +132,13 @@ export class WebSocketFetchHandler {
132
132
  };
133
133
  const send = async () => {
134
134
  try {
135
- for await (const inputChunk of data) {
136
- socket.send(inputChunk);
135
+ for await (const chunk of data) {
136
+ if (socket.readyState >= WebSocket.CLOSING) {
137
+ break;
138
+ }
139
+ else {
140
+ socket.send(chunk);
141
+ }
137
142
  }
138
143
  }
139
144
  catch (err) {
@@ -1,4 +1,7 @@
1
1
  import { Decoder, Encoder, EventStreamPayloadHandler as IEventStreamPayloadHandler, FinalizeHandler, FinalizeHandlerArguments, FinalizeHandlerOutput, HandlerExecutionContext, MessageSigner, MetadataBearer, Provider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
2
5
  export interface EventStreamPayloadHandlerOptions {
3
6
  messageSigner: Provider<MessageSigner>;
4
7
  utf8Encoder: Encoder;
@@ -11,6 +14,8 @@ export interface EventStreamPayloadHandlerOptions {
11
14
  * 2. Close the stream if initial request fails.
12
15
  * 3. Start piping payload when connection is established.
13
16
  * 4. Sign the payload after payload stream starting to flow.
17
+ *
18
+ * @internal
14
19
  */
15
20
  export declare class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
16
21
  private readonly messageSigner;
@@ -1,3 +1,5 @@
1
1
  import { EventStreamPayloadHandlerProvider } from "@smithy/types";
2
- /** NodeJS event stream utils provider */
2
+ /**
3
+ * @internal
4
+ */
3
5
  export declare const eventStreamPayloadHandlerProvider: EventStreamPayloadHandlerProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-websocket",
3
- "version": "3.972.2",
3
+ "version": "3.972.4",
4
4
  "main": "./dist-cjs/index.js",
5
5
  "module": "./dist-es/index.js",
6
6
  "types": "./dist-types/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
27
  "@aws-sdk/types": "^3.973.1",
28
- "@aws-sdk/util-format-url": "^3.972.2",
28
+ "@aws-sdk/util-format-url": "^3.972.3",
29
29
  "@smithy/eventstream-codec": "^4.2.8",
30
30
  "@smithy/eventstream-serde-browser": "^4.2.8",
31
31
  "@smithy/fetch-http-handler": "^5.3.9",
@@ -42,8 +42,7 @@
42
42
  "mock-socket": "9.1.5",
43
43
  "premove": "4.0.0",
44
44
  "typescript": "~5.8.3",
45
- "vitest-websocket-mock": "0.2.3",
46
- "web-streams-polyfill": "3.2.1"
45
+ "vitest-websocket-mock": "0.2.3"
47
46
  },
48
47
  "engines": {
49
48
  "node": ">= 14.0.0"