Skip to content

Commit ba2b4d0

Browse files
committed
chore: feature detection for gzip and endpoint override
1 parent 72faecc commit ba2b4d0

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

.changeset/silent-rockets-turn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@smithy/middleware-compression": minor
3+
"@smithy/middleware-endpoint": minor
4+
"@smithy/core": minor
5+
---
6+
7+
feature detection for custom endpoint and gzip

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from "./util-identity-and-auth";
44
export * from "./getSmithyContext";
55
export * from "./normalizeProvider";
66
export * from "./protocols/requestBuilder";
7+
export * from "./setFeature";
78
export { createPaginator } from "./pagination/createPaginator";

packages/middleware-compression/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"main": "./dist-cjs/index.js",
1616
"module": "./dist-es/index.js",
1717
"dependencies": {
18+
"@smithy/core": "workspace:^",
1819
"@smithy/is-array-buffer": "workspace:^",
1920
"@smithy/node-config-provider": "workspace:^",
2021
"@smithy/protocol-http": "workspace:^",

packages/middleware-compression/src/compressionMiddleware.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setFeature } from "@smithy/core";
12
import { HttpRequest } from "@smithy/protocol-http";
23
import {
34
AbsoluteLocation,
@@ -6,6 +7,7 @@ import {
67
BuildHandlerOptions,
78
BuildHandlerOutput,
89
BuildMiddleware,
10+
HandlerExecutionContext,
911
MetadataBearer,
1012
} from "@smithy/types";
1113

@@ -39,7 +41,10 @@ export const compressionMiddleware =
3941
config: CompressionResolvedConfig & CompressionPreviouslyResolved,
4042
middlewareConfig: CompressionMiddlewareConfig
4143
): BuildMiddleware<any, any> =>
42-
<Output extends MetadataBearer>(next: BuildHandler<any, Output>): BuildHandler<any, Output> =>
44+
<Output extends MetadataBearer>(
45+
next: BuildHandler<any, Output>,
46+
context: HandlerExecutionContext
47+
): BuildHandler<any, Output> =>
4348
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
4449
if (!HttpRequest.isInstance(args.request)) {
4550
return next(args);
@@ -88,6 +93,10 @@ export const compressionMiddleware =
8893
updatedHeaders = { ...headers, "content-encoding": algorithm };
8994
}
9095

96+
if (headers["content-encoding"].includes("gzip")) {
97+
setFeature(context, "GZIP_REQUEST_COMPRESSION", "L");
98+
}
99+
91100
// We've matched on one supported algorithm in the
92101
// priority-ordered list, so we're finished.
93102
break;

packages/middleware-endpoint/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"license": "Apache-2.0",
2525
"dependencies": {
26+
"@smithy/core": "workspace:^",
2627
"@smithy/middleware-serde": "workspace:^",
2728
"@smithy/node-config-provider": "workspace:^",
2829
"@smithy/shared-ini-file-loader": "workspace:^",

packages/middleware-endpoint/src/endpointMiddleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setFeature } from "@smithy/core";
12
import {
23
AuthScheme,
34
EndpointParameters,
@@ -38,6 +39,10 @@ export const endpointMiddleware = <T extends EndpointParameters>({
3839
context: HandlerExecutionContext
3940
): SerializeHandler<any, Output> =>
4041
async (args: SerializeHandlerArguments<any>): Promise<SerializeHandlerOutput<Output>> => {
42+
if (config.endpoint) {
43+
setFeature(context, "ENDPOINT_OVERRIDE", "N");
44+
}
45+
4146
const endpoint: EndpointV2 = await getEndpointFromInstructions(
4247
args.input,
4348
{

0 commit comments

Comments
 (0)