@smithy/middleware-compression
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -10,5 +10,9 @@ "use strict"; | ||
const compressionMiddleware = (config, middlewareConfig) => (next) => async (args) => { | ||
if (!protocol_http_1.HttpRequest.isInstance(args.request) || config.disableRequestCompression) { | ||
if (!protocol_http_1.HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const disableRequestCompression = await config.disableRequestCompression(); | ||
if (disableRequestCompression) { | ||
return next(args); | ||
} | ||
const { request } = args; | ||
@@ -33,3 +37,4 @@ const { body, headers } = request; | ||
const bodyLength = config.bodyLengthChecker(body); | ||
if (bodyLength && bodyLength >= config.requestMinCompressionSizeBytes) { | ||
const requestMinCompressionSizeBytes = await config.requestMinCompressionSizeBytes(); | ||
if (bodyLength && bodyLength >= requestMinCompressionSizeBytes) { | ||
updatedBody = await (0, compressString_1.compressString)(body); | ||
@@ -36,0 +41,0 @@ isRequestCompressed = true; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveCompressionConfig = void 0; | ||
const resolveCompressionConfig = (input) => { | ||
const { requestMinCompressionSizeBytes } = input; | ||
if (requestMinCompressionSizeBytes < 0 || requestMinCompressionSizeBytes > 10485760) { | ||
throw new RangeError("The value for requestMinCompressionSizeBytes must be between 0 and 10485760 inclusive. " + | ||
`The provided value ${requestMinCompressionSizeBytes} is outside this range."`); | ||
} | ||
return input; | ||
}; | ||
const util_middleware_1 = require("@smithy/util-middleware"); | ||
const resolveCompressionConfig = (input) => ({ | ||
...input, | ||
disableRequestCompression: (0, util_middleware_1.normalizeProvider)(input.disableRequestCompression), | ||
requestMinCompressionSizeBytes: async () => { | ||
const requestMinCompressionSizeBytes = await (0, util_middleware_1.normalizeProvider)(input.requestMinCompressionSizeBytes)(); | ||
if (requestMinCompressionSizeBytes < 0 || requestMinCompressionSizeBytes > 10485760) { | ||
throw new RangeError("The value for requestMinCompressionSizeBytes must be between 0 and 10485760 inclusive. " + | ||
`The provided value ${requestMinCompressionSizeBytes} is outside this range."`); | ||
} | ||
return requestMinCompressionSizeBytes; | ||
}, | ||
}); | ||
exports.resolveCompressionConfig = resolveCompressionConfig; |
@@ -7,5 +7,9 @@ import { HttpRequest } from "@smithy/protocol-http"; | ||
export const compressionMiddleware = (config, middlewareConfig) => (next) => async (args) => { | ||
if (!HttpRequest.isInstance(args.request) || config.disableRequestCompression) { | ||
if (!HttpRequest.isInstance(args.request)) { | ||
return next(args); | ||
} | ||
const disableRequestCompression = await config.disableRequestCompression(); | ||
if (disableRequestCompression) { | ||
return next(args); | ||
} | ||
const { request } = args; | ||
@@ -30,3 +34,4 @@ const { body, headers } = request; | ||
const bodyLength = config.bodyLengthChecker(body); | ||
if (bodyLength && bodyLength >= config.requestMinCompressionSizeBytes) { | ||
const requestMinCompressionSizeBytes = await config.requestMinCompressionSizeBytes(); | ||
if (bodyLength && bodyLength >= requestMinCompressionSizeBytes) { | ||
updatedBody = await compressString(body); | ||
@@ -33,0 +38,0 @@ isRequestCompressed = true; |
@@ -1,8 +0,13 @@ | ||
export const resolveCompressionConfig = (input) => { | ||
const { requestMinCompressionSizeBytes } = input; | ||
if (requestMinCompressionSizeBytes < 0 || requestMinCompressionSizeBytes > 10485760) { | ||
throw new RangeError("The value for requestMinCompressionSizeBytes must be between 0 and 10485760 inclusive. " + | ||
`The provided value ${requestMinCompressionSizeBytes} is outside this range."`); | ||
} | ||
return input; | ||
}; | ||
import { normalizeProvider } from "@smithy/util-middleware"; | ||
export const resolveCompressionConfig = (input) => ({ | ||
...input, | ||
disableRequestCompression: normalizeProvider(input.disableRequestCompression), | ||
requestMinCompressionSizeBytes: async () => { | ||
const requestMinCompressionSizeBytes = await normalizeProvider(input.requestMinCompressionSizeBytes)(); | ||
if (requestMinCompressionSizeBytes < 0 || requestMinCompressionSizeBytes > 10485760) { | ||
throw new RangeError("The value for requestMinCompressionSizeBytes must be between 0 and 10485760 inclusive. " + | ||
`The provided value ${requestMinCompressionSizeBytes} is outside this range."`); | ||
} | ||
return requestMinCompressionSizeBytes; | ||
}, | ||
}); |
import { AbsoluteLocation, BuildHandlerOptions, BuildMiddleware } from "@smithy/types"; | ||
import { CompressionResolvedConfig } from "./configurations"; | ||
import { CompressionPreviouslyResolved, CompressionResolvedConfig } from "./configurations"; | ||
/** | ||
@@ -20,3 +20,3 @@ * @internal | ||
*/ | ||
export declare const compressionMiddleware: (config: CompressionResolvedConfig, middlewareConfig: CompressionMiddlewareConfig) => BuildMiddleware<any, any>; | ||
export declare const compressionMiddleware: (config: CompressionResolvedConfig & CompressionPreviouslyResolved, middlewareConfig: CompressionMiddlewareConfig) => BuildMiddleware<any, any>; | ||
export declare const compressionMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation; |
@@ -1,2 +0,2 @@ | ||
import { BodyLengthCalculator } from "@smithy/types"; | ||
import { BodyLengthCalculator, Provider } from "@smithy/types"; | ||
/** | ||
@@ -7,9 +7,5 @@ * @public | ||
/** | ||
* A function that can calculate the length of a body. | ||
*/ | ||
bodyLengthChecker: BodyLengthCalculator; | ||
/** | ||
* Whether to disable request compression. | ||
*/ | ||
disableRequestCompression: boolean; | ||
disableRequestCompression: boolean | Provider<boolean>; | ||
/** | ||
@@ -19,3 +15,3 @@ * The minimum size in bytes that a request body should be to trigger compression. | ||
*/ | ||
requestMinCompressionSizeBytes: number; | ||
requestMinCompressionSizeBytes: number | Provider<number>; | ||
} | ||
@@ -25,3 +21,20 @@ /** | ||
*/ | ||
export interface CompressionResolvedConfig extends CompressionInputConfig { | ||
export interface CompressionPreviouslyResolved { | ||
/** | ||
* A function that can calculate the length of a body. | ||
*/ | ||
bodyLengthChecker: BodyLengthCalculator; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export interface CompressionResolvedConfig { | ||
/** | ||
* Resolved value for input config {@link CompressionInputConfig.disableRequestCompression} | ||
*/ | ||
disableRequestCompression: Provider<boolean>; | ||
/** | ||
* Resolved value for input config {@link CompressionInputConfig.requestMinCompressionSizeBytes} | ||
*/ | ||
requestMinCompressionSizeBytes: Provider<number>; | ||
} |
import { Pluggable } from "@smithy/types"; | ||
import { CompressionMiddlewareConfig } from "./compressionMiddleware"; | ||
import { CompressionResolvedConfig } from "./configurations"; | ||
import { CompressionPreviouslyResolved, CompressionResolvedConfig } from "./configurations"; | ||
/** | ||
* @internal | ||
*/ | ||
export declare const getCompressionPlugin: (config: CompressionResolvedConfig, middlewareConfig: CompressionMiddlewareConfig) => Pluggable<any, any>; | ||
export declare const getCompressionPlugin: (config: CompressionResolvedConfig & CompressionPreviouslyResolved, middlewareConfig: CompressionMiddlewareConfig) => Pluggable<any, any>; |
{ | ||
"name": "@smithy/middleware-compression", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Middleware and Plugin for request compression.", | ||
@@ -21,2 +21,3 @@ "scripts": { | ||
"@smithy/util-config-provider": "^2.1.0", | ||
"@smithy/util-middleware": "^2.0.9", | ||
"fflate": "0.8.1", | ||
@@ -23,0 +24,0 @@ "tslib": "^2.5.0" |
36986
529
6
+ Added@smithy/util-middleware@2.2.0(transitive)