Skip to content

Commit f8005f8

Browse files
committed
chore: add NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS
1 parent ea69f82 commit f8005f8

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

packages/middleware-compression/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"types": "./dist-types/index.d.ts",
1010
"module": "./dist-es/index.js",
1111
"dependencies": {
12+
"@smithy/node-config-provider": "^2.1.8",
13+
"@smithy/util-config-provider": "^2.0.0",
1214
"@smithy/types": "^2.7.0",
1315
"tslib": "^2.5.0"
1416
},
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { booleanSelector, SelectorType } from "@smithy/util-config-provider";
2+
3+
import {
4+
NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS,
5+
NODE_DISABLE_REQUEST_COMPRESSION_ENV_NAME,
6+
NODE_DISABLE_REQUEST_COMPRESSION_INI_NAME,
7+
} from "./NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS";
8+
9+
jest.mock("@smithy/util-config-provider");
10+
11+
describe("NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS", () => {
12+
afterEach(() => {
13+
jest.clearAllMocks();
14+
});
15+
16+
const test = (func: Function, obj: Record<string, string>, key: string, type: SelectorType) => {
17+
it.each([true, false, undefined])("returns %s", (output) => {
18+
(booleanSelector as jest.Mock).mockReturnValueOnce(output);
19+
expect(func(obj)).toEqual(output);
20+
expect(booleanSelector).toBeCalledWith(obj, key, type);
21+
});
22+
23+
it("throws error", () => {
24+
const mockError = new Error("error");
25+
(booleanSelector as jest.Mock).mockImplementationOnce(() => {
26+
throw mockError;
27+
});
28+
expect(() => {
29+
func(obj);
30+
}).toThrow(mockError);
31+
});
32+
};
33+
34+
describe("calls booleanSelector for environmentVariableSelector", () => {
35+
const env: { [NODE_DISABLE_REQUEST_COMPRESSION_ENV_NAME]: any } = {} as any;
36+
const { environmentVariableSelector } = NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS;
37+
test(environmentVariableSelector, env, NODE_DISABLE_REQUEST_COMPRESSION_ENV_NAME, SelectorType.ENV);
38+
});
39+
40+
describe("calls booleanSelector for configFileSelector", () => {
41+
const profileContent: { [NODE_DISABLE_REQUEST_COMPRESSION_INI_NAME]: any } = {} as any;
42+
const { configFileSelector } = NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS;
43+
test(configFileSelector, profileContent, NODE_DISABLE_REQUEST_COMPRESSION_INI_NAME, SelectorType.CONFIG);
44+
});
45+
46+
it("returns false for default", () => {
47+
const { default: defaultValue } = NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS;
48+
expect(defaultValue).toEqual(false);
49+
});
50+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
2+
import { booleanSelector, SelectorType } from "@smithy/util-config-provider";
3+
4+
/**
5+
* @internal
6+
*/
7+
export const NODE_DISABLE_REQUEST_COMPRESSION_ENV_NAME = "AWS_DISABLE_REQUEST_COMPRESSION";
8+
9+
/**
10+
* @internal
11+
*/
12+
export const NODE_DISABLE_REQUEST_COMPRESSION_INI_NAME = "disable_request_compression";
13+
14+
/**
15+
* @internal
16+
*/
17+
export const NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
18+
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
19+
booleanSelector(env, NODE_DISABLE_REQUEST_COMPRESSION_ENV_NAME, SelectorType.ENV),
20+
configFileSelector: (profile) =>
21+
booleanSelector(profile, NODE_DISABLE_REQUEST_COMPRESSION_INI_NAME, SelectorType.CONFIG),
22+
default: false,
23+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS";
12
export * from "./compressionMiddleware";
23
export * from "./configurations";
34
export * from "./resolveCompressionConfig";

0 commit comments

Comments
 (0)