-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(middleware-flexible-checksums): skip checksum computation if prov…
…ided (#6745)
- Loading branch information
Showing
4 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/middleware-flexible-checksums/src/hasHeaderWithPrefix.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { HeaderBag } from "@smithy/types"; | ||
import { describe, expect, test as it } from "vitest"; | ||
|
||
import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix"; | ||
|
||
describe(hasHeaderWithPrefix.name, () => { | ||
const mockHeaders: HeaderBag = { | ||
"header-prefix-lowercase-1": "header-value-1", | ||
"HEADER-PREFIX-UPPERCASE-2": "header-value-2", | ||
}; | ||
|
||
describe("contains header prefix", () => { | ||
it("when headerPrefix is exact", () => { | ||
expect(hasHeaderWithPrefix("header-prefix-lowercase-", mockHeaders)).toBe(true); | ||
}); | ||
|
||
it("when headerPrefix is in different case", () => { | ||
expect(hasHeaderWithPrefix("HEADER-PREFIX-LOWERCASE-", mockHeaders)).toBe(true); | ||
}); | ||
|
||
it("when headerPrefix in headers is in different case", () => { | ||
expect(hasHeaderWithPrefix("header-prefix-uppercase-", mockHeaders)).toBe(true); | ||
}); | ||
}); | ||
|
||
it("doesn't contain header with headerPrefix", () => { | ||
expect(hasHeaderWithPrefix("header-prefix-3", mockHeaders)).toBe(false); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/middleware-flexible-checksums/src/hasHeaderWithPrefix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { HeaderBag } from "@smithy/types"; | ||
|
||
/** | ||
* Returns true if header with headerPrefix is present in headers. | ||
* Comparisons are case-insensitive. | ||
*/ | ||
export const hasHeaderWithPrefix = (headerPrefix: string, headers: HeaderBag): boolean => { | ||
const soughtHeaderPrefix = headerPrefix.toLowerCase(); | ||
for (const headerName of Object.keys(headers)) { | ||
if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; |