Skip to content

Commit

Permalink
fix(protocol-http): revert SRA HttpRequest (#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesziemer committed Mar 15, 2023
1 parent 35f60e3 commit 0b3327b
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 862 deletions.
5 changes: 3 additions & 2 deletions packages/middleware-host-header/src/index.spec.ts
Expand Up @@ -20,16 +20,17 @@ describe("hostHeaderMiddleware", () => {
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com");
});


it("should include port in host header when set", async () => {
expect.assertions(2);
const middleware = hostHeaderMiddleware({ requestHandler: {} as any });
const handler = middleware(mockNextHandler, {} as any);
await handler({
input: {},
request: new HttpRequest({ hostname: "foo.amazonaws.com", port: 9000 }),
request: new HttpRequest({ hostname: "foo.amazonaws.com", port: 443 }),
});
expect(mockNextHandler.mock.calls.length).toEqual(1);
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com:9000");
expect(mockNextHandler.mock.calls[0][0].request.headers.host).toBe("foo.amazonaws.com:443");
});

it("should not set host header if already set", async () => {
Expand Down
Expand Up @@ -45,7 +45,7 @@ describe("websocketURLMiddleware", () => {
expect(HttpRequest.isInstance(args.request)).toBeTruthy();
const processed = args.request as HttpRequest;
expect(processed.protocol).toEqual("wss:");
expect(processed.port).toEqual(8443);
expect(processed.hostname).toEqual("transcribestreaming.us-east-1.amazonaws.com:8443");
expect(processed.path).toEqual("/stream-transcription-websocket");
expect(processed.method).toEqual("GET");
done();
Expand Down
Expand Up @@ -19,8 +19,8 @@ export const websocketURLMiddleware =
if (HttpRequest.isInstance(request) && options.requestHandler.metadata?.handlerProtocol === "websocket") {
// Update http/2 endpoint to WebSocket-specific endpoint.
request.protocol = "wss:";
// Update port for using WebSocket.
request.port = 8443;
// Append port to hostname because it needs to be signed together
request.hostname = `${request.hostname}:8443`;
request.path = `${request.path}-websocket`;
request.method = "GET";

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-http/package.json
Expand Up @@ -9,7 +9,7 @@
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest --coverage"
"test": "jest"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-http/src/Field.ts
Expand Up @@ -58,13 +58,13 @@ export class Field {
}

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

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-http/src/FieldPosition.ts
@@ -1,4 +1,4 @@
export enum FieldPosition {
HEADER,
TRAILER
TRAILER,
}
28 changes: 1 addition & 27 deletions packages/protocol-http/src/Fields.ts
@@ -1,4 +1,4 @@
import { Field, FieldOptions } from "./Field";
import { Field } from "./Field";
import { FieldPosition } from "./FieldPosition";

export type FieldsOptions = { fields?: Field[]; encoding?: string };
Expand Down Expand Up @@ -56,30 +56,4 @@ export class Fields {
public getByType(kind: FieldPosition): Field[] {
return Object.values(this.entries).filter((field) => field.kind === kind);
}

/**
* Retrieves all the {@link Field}s in the collection.
* Includes headers and trailers.
*
* @returns All fields in the collection.
*/
public getAll(): Field[] {
return Object.values(this.entries);
}

/**
* Utility for creating {@link Fields} without having to
* construct each {@link Field} individually.
*
* @param fieldsToCreate List of arguments used to create each
* {@link Field}.
* @param encoding Optional encoding of resultant {@link Fields}.
* @returns The {@link Fields} instance.
*/
public static from(fieldsToCreate: FieldOptions[], encoding?: string): Fields {
return fieldsToCreate.reduce((fields, fieldArgs) => {
fields.setField(new Field(fieldArgs));
return fields;
}, new Fields({ encoding }));
}
}
156 changes: 0 additions & 156 deletions packages/protocol-http/src/headersProxy.spec.ts

This file was deleted.

89 changes: 0 additions & 89 deletions packages/protocol-http/src/headersProxy.ts

This file was deleted.

0 comments on commit 0b3327b

Please sign in to comment.