Skip to content

Commit 1965eb0

Browse files
kuhetrivikr
andauthored
fix(middleware-eventstream): lowercase headers more consistently (#6259)
* fix(middleware-eventstream): lowercase headers more consistently * fix: restore test in packages/middleware-websocket/src/middleware-websocket-endpoint.spec.ts Co-authored-by: Trivikram Kamat <[email protected]> * test(middleware-websocket): update unit test for clarity * test(middleware-websocket): update unit test assertion --------- Co-authored-by: Trivikram Kamat <[email protected]>
1 parent 2697d89 commit 1965eb0

File tree

9 files changed

+19
-18
lines changed

9 files changed

+19
-18
lines changed

packages/credential-provider-http/src/fromHttp/fromHttp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const mockHandle = jest.fn().mockResolvedValue({
2525
response: new HttpResponse({
2626
statusCode: 200,
2727
headers: {
28-
"Content-Type": "application/json",
28+
"content-type": "application/json",
2929
},
3030
body: Readable.from([""]),
3131
}),

packages/credential-provider-http/src/fromHttp/requestHelpers.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe(getCredentials.name, () => {
1717
const response = new HttpResponse({
1818
statusCode: 200,
1919
headers: {
20-
"Content-Type": "application/json",
20+
"content-type": "application/json",
2121
},
2222
body: Readable.from(JSON.stringify(data)),
2323
});
@@ -34,7 +34,7 @@ describe(getCredentials.name, () => {
3434
const response = new HttpResponse({
3535
statusCode: 400,
3636
headers: {
37-
"Content-Type": "application/json",
37+
"content-type": "application/json",
3838
},
3939
body: Readable.from(
4040
JSON.stringify({
@@ -57,7 +57,7 @@ describe(getCredentials.name, () => {
5757
const response = new HttpResponse({
5858
statusCode: 500,
5959
headers: {
60-
"Content-Type": "json",
60+
"content-type": "json",
6161
},
6262
body: Readable.from(JSON.stringify({})),
6363
});

packages/middleware-eventstream/src/eventStreamHeaderMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const eventStreamHeaderMiddleware: BuildMiddleware<any, any> = (next) =>
55
if (!HttpRequest.isInstance(request)) return next(args);
66
request.headers = {
77
...request.headers,
8-
"Content-Type": "application/vnd.amazon.eventstream",
8+
"content-type": "application/vnd.amazon.eventstream",
99
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-EVENTS",
1010
};
1111
return next({

packages/middleware-eventstream/src/middleware-eventstream.integ.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("middleware-eventstream", () => {
2020

2121
requireRequestsFrom(client).toMatch({
2222
headers: {
23-
"Content-Type": "application/vnd.amazon.eventstream",
23+
"content-type": "application/vnd.amazon.eventstream",
2424
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-EVENTS",
2525
},
2626
});
@@ -51,7 +51,7 @@ describe("middleware-eventstream", () => {
5151

5252
requireRequestsFrom(client).toMatch({
5353
headers: {
54-
"Content-Type": "application/vnd.amazon.eventstream",
54+
"content-type": "application/vnd.amazon.eventstream",
5555
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-EVENTS",
5656
},
5757
});
@@ -83,7 +83,7 @@ describe("middleware-eventstream", () => {
8383

8484
requireRequestsFrom(client).toMatch({
8585
headers: {
86-
"Content-Type": "application/vnd.amazon.eventstream",
86+
"content-type": "application/vnd.amazon.eventstream",
8787
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-EVENTS",
8888
},
8989
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("middleware-sdk-transcribe-streaming", () => {
1212

1313
requireRequestsFrom(client).toMatch({
1414
headers: {
15-
"Content-Type": /undefined/,
15+
"content-type": /undefined/,
1616
host: "transcribestreaming.us-west-2.amazonaws.com:8443",
1717
},
1818
query: {

packages/middleware-websocket/src/middleware-websocket-endpoint.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe(websocketEndpointMiddleware.name, () => {
3838
mw(next as any, {} as any)({ request, input: {} });
3939
});
4040

41-
it("should remove content-type and sha256 hash header", (done) => {
41+
it("should remove content-type and sha256 hash header without transferring them to query parameters", (done) => {
4242
const request = new HttpRequest({
4343
headers: {
4444
"content-type": "application/vnd.amazon.eventstream",
@@ -50,21 +50,22 @@ describe(websocketEndpointMiddleware.name, () => {
5050
const next = (args: BuildHandlerArguments<any>) => {
5151
expect(HttpRequest.isInstance(args.request)).toBeTruthy();
5252
const processed = args.request as HttpRequest;
53-
expect(processed.headers["content-type"]).toBeUndefined();
54-
expect(processed.headers["Content-Type"]).toBeUndefined();
55-
expect(processed.headers["x-amz-content-sha256"]).toBeUndefined();
56-
expect(processed.headers["X-Amz-Content-Sha256"]).toBeUndefined();
53+
const queryKeys = Object.keys(processed.query).map((key) => key.toLowerCase());
54+
expect(queryKeys).not.toContain("content-type");
55+
expect(queryKeys).not.toContain("x-amz-content-sha256");
5756
done();
5857
};
5958
const mw = websocketEndpointMiddleware(config, handlerOption);
6059
mw(next as any, {} as any)({ request, input: {} });
6160
});
6261

63-
it("should contains host header after adjustment", (done) => {
62+
it("should contain only a host header after adjustment", (done) => {
6463
const request = new HttpRequest({});
6564
const next = (args: BuildHandlerArguments<any>) => {
6665
expect(HttpRequest.isInstance(args.request)).toBeTruthy();
6766
const processed = args.request as HttpRequest;
67+
const headerKeys = Object.keys(processed.headers).map((key) => key.toLowerCase());
68+
expect(headerKeys).toEqual(["host"]);
6869
expect(processed.headers["host"]).toBeDefined();
6970
done();
7071
};

packages/middleware-websocket/src/middleware-websocket-endpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const websocketEndpointMiddleware =
3737
// 'Content-Type' and 'x-amz-content-sha256' headers are normally set for
3838
// event stream, but WebSocket doesn't require it.
3939
// See: 'eventStreamHeaderMiddleware' in @aws-sdk/middleware-eventstream
40-
delete headers["Content-Type"];
40+
delete headers["content-type"];
4141
delete headers["x-amz-content-sha256"];
4242

4343
for (const name of Object.keys(headers)) {

packages/middleware-websocket/src/middleware-websocket.integ.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("middleware-websocket", () => {
2121
path: "/start-face-liveness-session-websocket",
2222
headers: {
2323
host: "streaming-rekognition.us-west-2.amazonaws.com",
24-
"Content-Type": /^undefined$/,
24+
"content-type": /^undefined$/,
2525
"x-amz-content-sha256": /^undefined$/,
2626
"user-agent": /^aws-sdk-js/,
2727
},

packages/s3-request-presigner/src/presigner.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe("s3 presigner", () => {
7171
...minimalRequest,
7272
headers: {
7373
...minimalRequest.headers,
74-
"Content-Type": "application/octet-stream",
74+
"content-type": "application/octet-stream",
7575
},
7676
};
7777
const signed = await signer.presign(requestWithContentTypeHeader, presigningOptions);

0 commit comments

Comments
 (0)