Skip to content

Commit 0b3327b

Browse files
authored
fix(protocol-http): revert SRA HttpRequest (#4529)
1 parent 35f60e3 commit 0b3327b

File tree

16 files changed

+47
-862
lines changed

16 files changed

+47
-862
lines changed

packages/middleware-host-header/src/index.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ describe("hostHeaderMiddleware", () => {
2020
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com");
2121
});
2222

23+
2324
it("should include port in host header when set", async () => {
2425
expect.assertions(2);
2526
const middleware = hostHeaderMiddleware({ requestHandler: {} as any });
2627
const handler = middleware(mockNextHandler, {} as any);
2728
await handler({
2829
input: {},
29-
request: new HttpRequest({ hostname: "foo.amazonaws.com", port: 9000 }),
30+
request: new HttpRequest({ hostname: "foo.amazonaws.com", port: 443 }),
3031
});
3132
expect(mockNextHandler.mock.calls.length).toEqual(1);
32-
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com:9000");
33+
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com:443");
3334
});
3435

3536
it("should not set host header if already set", async () => {

packages/middleware-sdk-transcribe-streaming/src/middleware-endpoint.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("websocketURLMiddleware", () => {
4545
expect(HttpRequest.isInstance(args.request)).toBeTruthy();
4646
const processed = args.request as HttpRequest;
4747
expect(processed.protocol).toEqual("wss:");
48-
expect(processed.port).toEqual(8443);
48+
expect(processed.hostname).toEqual("transcribestreaming.us-east-1.amazonaws.com:8443");
4949
expect(processed.path).toEqual("/stream-transcription-websocket");
5050
expect(processed.method).toEqual("GET");
5151
done();

packages/middleware-sdk-transcribe-streaming/src/middleware-endpoint.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const websocketURLMiddleware =
1919
if (HttpRequest.isInstance(request) && options.requestHandler.metadata?.handlerProtocol === "websocket") {
2020
// Update http/2 endpoint to WebSocket-specific endpoint.
2121
request.protocol = "wss:";
22-
// Update port for using WebSocket.
23-
request.port = 8443;
22+
// Append port to hostname because it needs to be signed together
23+
request.hostname = `${request.hostname}:8443`;
2424
request.path = `${request.path}-websocket`;
2525
request.method = "GET";
2626

packages/protocol-http/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:types": "tsc -p tsconfig.types.json",
1010
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1111
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12-
"test": "jest --coverage"
12+
"test": "jest"
1313
},
1414
"main": "./dist-cjs/index.js",
1515
"module": "./dist-es/index.js",

packages/protocol-http/src/Field.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ export class Field {
5858
}
5959

6060
/**
61-
* Get comma-delimited string to be sent over the wire.
61+
* Get comma-delimited string.
6262
*
6363
* @returns String representation of {@link Field}.
6464
*/
6565
public toString(): string {
66-
// Values with commas MUST be double-quoted
67-
return this.values.map((v) => (v.includes(",") ? `"${v}"` : v)).join(", ");
66+
// Values with spaces or commas MUST be double-quoted
67+
return this.values.map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v)).join(", ");
6868
}
6969

7070
/**
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum FieldPosition {
22
HEADER,
3-
TRAILER
3+
TRAILER,
44
}

packages/protocol-http/src/Fields.ts

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Field, FieldOptions } from "./Field";
1+
import { Field } from "./Field";
22
import { FieldPosition } from "./FieldPosition";
33

44
export type FieldsOptions = { fields?: Field[]; encoding?: string };
@@ -56,30 +56,4 @@ export class Fields {
5656
public getByType(kind: FieldPosition): Field[] {
5757
return Object.values(this.entries).filter((field) => field.kind === kind);
5858
}
59-
60-
/**
61-
* Retrieves all the {@link Field}s in the collection.
62-
* Includes headers and trailers.
63-
*
64-
* @returns All fields in the collection.
65-
*/
66-
public getAll(): Field[] {
67-
return Object.values(this.entries);
68-
}
69-
70-
/**
71-
* Utility for creating {@link Fields} without having to
72-
* construct each {@link Field} individually.
73-
*
74-
* @param fieldsToCreate List of arguments used to create each
75-
* {@link Field}.
76-
* @param encoding Optional encoding of resultant {@link Fields}.
77-
* @returns The {@link Fields} instance.
78-
*/
79-
public static from(fieldsToCreate: FieldOptions[], encoding?: string): Fields {
80-
return fieldsToCreate.reduce((fields, fieldArgs) => {
81-
fields.setField(new Field(fieldArgs));
82-
return fields;
83-
}, new Fields({ encoding }));
84-
}
8559
}

packages/protocol-http/src/headersProxy.spec.ts

-156
This file was deleted.

packages/protocol-http/src/headersProxy.ts

-89
This file was deleted.

0 commit comments

Comments
 (0)