Skip to content

Commit 17e69dc

Browse files
committed
chore: add NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES
1 parent f8005f8 commit 17e69dc

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
2+
import { SelectorType } from "@smithy/util-config-provider";
3+
4+
/**
5+
* @internal
6+
*/
7+
export const NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_ENV_NAME = "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES";
8+
9+
/**
10+
* @internal
11+
*/
12+
export const NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_INI_NAME = "request_min_compression_size_bytes";
13+
14+
/**
15+
* ToDo: switch to using numberSelector from @smithy/util-config-provider once available.
16+
* https://github.com/smithy-lang/smithy-typescript/pull/1126
17+
*/
18+
const numberSelector = (obj: Record<string, string | undefined>, key: string, type: SelectorType) => {
19+
if (!(key in obj)) return undefined;
20+
21+
const numberValue = parseInt(obj[key] as string, 10);
22+
if (Number.isNaN(numberValue)) {
23+
throw new TypeError(`Cannot load ${type} '${key}'. Expected number, got '${obj[key]}'.`);
24+
}
25+
26+
return numberValue;
27+
};
28+
29+
/**
30+
* @internal
31+
*/
32+
export const NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS: LoadedConfigSelectors<number> = {
33+
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
34+
numberSelector(env, NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_ENV_NAME, SelectorType.ENV),
35+
configFileSelector: (profile) =>
36+
numberSelector(profile, NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_INI_NAME, SelectorType.CONFIG),
37+
default: 10240,
38+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS";
2+
export * from "./NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS";
23
export * from "./compressionMiddleware";
34
export * from "./configurations";
45
export * from "./resolveCompressionConfig";

0 commit comments

Comments
 (0)