Skip to content

Commit d644faa

Browse files
committed
fix(protocol-http): revert SRA HttpRequest (aws#4514)
This reverts commit d9d24b0. A bug was found with this commit when using a Symbol as a key, or a non-string as a value in `request.headers`.
1 parent 35f60e3 commit d644faa

File tree

15 files changed

+64
-877
lines changed

15 files changed

+64
-877
lines changed

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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { FieldPosition } from "./FieldPosition";
22

3-
export type FieldOptions = {
3+
export type FieldOptions = {
44
name: string;
5-
kind?: FieldPosition;
5+
kind?: FieldPosition
66
values?: string[];
77
};
88

99
/**
1010
* A name-value pair representing a single field
1111
* transmitted in an HTTP Request or Response.
12-
*
12+
*
1313
* The kind will dictate metadata placement within
1414
* an HTTP message.
15-
*
15+
*
1616
* All field names are case insensitive and
1717
* case-variance must be treated as equivalent.
1818
* Names MAY be normalized but SHOULD be preserved
@@ -31,8 +31,8 @@ export class Field {
3131
}
3232

3333
/**
34-
* Appends a value to the field.
35-
*
34+
* Appends a value to the field.
35+
*
3636
* @param value The value to append.
3737
*/
3838
public add(value: string): void {
@@ -41,7 +41,7 @@ export class Field {
4141

4242
/**
4343
* Overwrite existing field values.
44-
*
44+
*
4545
* @param values The new field values.
4646
*/
4747
public set(values: string[]): void {
@@ -50,26 +50,28 @@ export class Field {
5050

5151
/**
5252
* Remove all matching entries from list.
53-
*
53+
*
5454
* @param value Value to remove.
5555
*/
5656
public remove(value: string): void {
5757
this.values = this.values.filter((v) => v !== value);
5858
}
5959

6060
/**
61-
* Get comma-delimited string to be sent over the wire.
62-
*
61+
* Get comma-delimited string.
62+
*
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
68+
.map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v))
69+
.join(", ");
6870
}
6971

7072
/**
7173
* Get string values as a list
72-
*
74+
*
7375
* @returns Values in {@link Field} as a list.
7476
*/
7577
public get(): string[] {

packages/protocol-http/src/Fields.ts

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Field, FieldOptions } from "./Field";
1+
import { Field } from "./Field";
22
import { FieldPosition } from "./FieldPosition";
33

4-
export type FieldsOptions = { fields?: Field[]; encoding?: string };
4+
export type FieldsOptions = { fields?: Field[]; encoding?: string; };
55

66
/**
77
* Collection of Field entries mapped by name.
@@ -18,7 +18,7 @@ export class Fields {
1818
/**
1919
* Set entry for a {@link Field} name. The `name`
2020
* attribute will be used to key the collection.
21-
*
21+
*
2222
* @param field The {@link Field} to set.
2323
*/
2424
public setField(field: Field): void {
@@ -27,7 +27,7 @@ export class Fields {
2727

2828
/**
2929
* Retrieve {@link Field} entry by name.
30-
*
30+
*
3131
* @param name The name of the {@link Field} entry
3232
* to retrieve
3333
* @returns The {@link Field} if it exists.
@@ -38,48 +38,22 @@ export class Fields {
3838

3939
/**
4040
* Delete entry from collection.
41-
*
41+
*
4242
* @param name Name of the entry to delete.
43-
*/
43+
*/
4444
public removeField(name: string): void {
4545
delete this.entries[name.toLowerCase()];
4646
}
4747

4848
/**
4949
* Helper function for retrieving specific types of fields.
5050
* Used to grab all headers or all trailers.
51-
*
51+
*
5252
* @param kind {@link FieldPosition} of entries to retrieve.
5353
* @returns The {@link Field} entries with the specified
5454
* {@link FieldPosition}.
5555
*/
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

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)