Skip to content

Commit

Permalink
fix(middleware-apply-body-checksum): use lowercase content-md5 header (
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Aug 5, 2021
1 parent 96de406 commit e1f2dfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("applyMd5BodyChecksumMiddleware", () => {
});

for (const body of ["body", new ArrayBuffer(10), new Uint8Array(10), void 0]) {
it("should calculate the body hash, encode the result, and set the encoded hash to Content-MD5 header", async () => {
it("should calculate the body hash, encode the result, and set the encoded hash to content-md5 header", async () => {
const handler = applyMd5BodyChecksumMiddleware({
md5: MockHash,
base64Encoder: mockEncoder,
Expand All @@ -40,7 +40,7 @@ describe("applyMd5BodyChecksumMiddleware", () => {

expect(next.mock.calls.length).toBe(1);
const { request } = next.mock.calls[0][0];
expect(request.headers["Content-MD5"]).toBe("encoded");
expect(request.headers["content-md5"]).toBe("encoded");
expect(mockHashUpdate.mock.calls).toEqual([[body || ""]]);
});

Expand All @@ -65,7 +65,7 @@ describe("applyMd5BodyChecksumMiddleware", () => {
expect(next.mock.calls.length).toBe(1);
const { request } = next.mock.calls[0][0];
expect(request.headers["CoNtEnT-Md5"]).toBe("foo");
expect(request.headers["Content-MD5"]).toBe(undefined);
expect(request.headers["content-md5"]).toBe(undefined);
expect(mockHashUpdate.mock.calls.length).toBe(0);
expect(mockHashDigest.mock.calls.length).toBe(0);
expect(mockEncoder.mock.calls.length).toBe(0);
Expand All @@ -90,7 +90,7 @@ describe("applyMd5BodyChecksumMiddleware", () => {
expect(next.mock.calls.length).toBe(1);
const { request } = next.mock.calls[0][0];
expect(request.body).toStrictEqual(new ExoticStream());
expect(request.headers["Content-MD5"]).toBe("encoded");
expect(request.headers["content-md5"]).toBe("encoded");
expect(mockHashDigest.mock.calls.length).toBe(0);
expect(mockEncoder.mock.calls.length).toBe(1);
expect(mockEncoder.mock.calls).toEqual([[new Uint8Array(5)]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const applyMd5BodyChecksumMiddleware =
let { request } = args;
if (HttpRequest.isInstance(request)) {
const { body, headers } = request;
if (!hasHeader("Content-MD5", headers)) {
if (!hasHeader("content-md5", headers)) {
let digest: Promise<Uint8Array>;
if (body === undefined || typeof body === "string" || ArrayBuffer.isView(body) || isArrayBuffer(body)) {
const hash = new options.md5();
Expand All @@ -34,7 +34,7 @@ export const applyMd5BodyChecksumMiddleware =
...request,
headers: {
...headers,
"Content-MD5": options.base64Encoder(await digest),
"content-md5": options.base64Encoder(await digest),
},
};
}
Expand Down

0 comments on commit e1f2dfc

Please sign in to comment.