Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silent-rockets-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@smithy/middleware-compression": minor
"@smithy/middleware-endpoint": minor
"@smithy/core": minor
---

feature detection for custom endpoint and gzip
8 changes: 8 additions & 0 deletions .changeset/unlucky-books-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@smithy/middleware-compression": patch
"@smithy/middleware-endpoint": patch
"@smithy/smithy-client": patch
"@smithy/core": patch
---

reorganize smithy/core to be upstream of smithy/smithy-client
4 changes: 1 addition & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@
},
"license": "Apache-2.0",
"dependencies": {
"@smithy/middleware-endpoint": "workspace:^",
"@smithy/middleware-retry": "workspace:^",
"@smithy/middleware-serde": "workspace:^",
"@smithy/protocol-http": "workspace:^",
"@smithy/smithy-client": "workspace:^",
"@smithy/types": "workspace:^",
"@smithy/util-body-length-browser": "workspace:^",
"@smithy/util-middleware": "workspace:^",
"@smithy/util-stream": "workspace:^",
"@smithy/util-utf8": "workspace:^",
"tslib": "^2.6.2"
},
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export * from "./getSmithyContext";
export * from "./middleware-http-auth-scheme";
export * from "./middleware-http-signing";
export * from "./util-identity-and-auth";
export * from "./getSmithyContext";
export * from "./normalizeProvider";
export * from "./protocols/requestBuilder";
export { createPaginator } from "./pagination/createPaginator";
export * from "./protocols/collect-stream-body";
export * from "./protocols/requestBuilder";
export * from "./protocols/resolve-path";
export * from "./protocols/extended-encode-uri-component";
export * from "./setFeature";
export * from "./util-identity-and-auth";
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint";
import {
HandlerExecutionContext,
HttpAuthSchemeParameters,
Expand All @@ -20,7 +19,7 @@ export const httpAuthSchemeEndpointRuleSetMiddlewareOptions: SerializeHandlerOpt
name: "httpAuthSchemeMiddleware",
override: true,
relation: "before",
toMiddleware: endpointMiddlewareOptions.name!,
toMiddleware: "endpointV2Middleware",
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { retryMiddlewareOptions } from "@smithy/middleware-retry";
import { FinalizeRequestHandlerOptions, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";

import { httpSigningMiddleware } from "./httpSigningMiddleware";
Expand All @@ -13,7 +12,7 @@ export const httpSigningMiddlewareOptions: FinalizeRequestHandlerOptions & Relat
aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
override: true,
relation: "after",
toMiddleware: retryMiddlewareOptions.name!,
toMiddleware: "retryMiddleware",
};

/**
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/protocols/collect-stream-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SerdeContext } from "@smithy/types";
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream";

/**
* @internal
*
* Collect low-level response body stream to Uint8Array.
*/
export const collectBody = async (
streamBody: any = new Uint8Array(),
context: {
streamCollector: SerdeContext["streamCollector"];
}
): Promise<Uint8ArrayBlobAdapter> => {
if (streamBody instanceof Uint8Array) {
return Uint8ArrayBlobAdapter.mutate(streamBody);
}

if (!streamBody) {
return Uint8ArrayBlobAdapter.mutate(new Uint8Array());
}

const fromContext = context.streamCollector(streamBody);

return Uint8ArrayBlobAdapter.mutate(await fromContext);
};
11 changes: 11 additions & 0 deletions packages/core/src/protocols/extended-encode-uri-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @internal
*
* Function that wraps encodeURIComponent to encode additional characters
* to fully adhere to RFC 3986.
*/
export function extendedEncodeURIComponent(str: string): string {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
});
}
3 changes: 2 additions & 1 deletion packages/core/src/protocols/requestBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HttpRequest } from "@smithy/protocol-http";
import { resolvedPath } from "@smithy/smithy-client";
import type { SerdeContext } from "@smithy/types";

import { resolvedPath } from "./resolve-path";

/**
* @internal
* used in code-generated serde.
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/protocols/resolve-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";

/**
* @internal
*/
export const resolvedPath = (
resolvedPath: string,
input: unknown,
memberName: string,
labelValueProvider: () => string | undefined,
uriLabel: string,
isGreedyLabel: boolean
): string => {
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
const labelValue = labelValueProvider() as string;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: " + memberName + ".");
}
resolvedPath = resolvedPath.replace(
uriLabel,
isGreedyLabel
? labelValue
.split("/")
.map((segment) => extendedEncodeURIComponent(segment))
.join("/")
: extendedEncodeURIComponent(labelValue)
);
} else {
throw new Error("No value provided for input HTTP label: " + memberName + ".");
}
return resolvedPath;
};
2 changes: 1 addition & 1 deletion packages/core/src/submodules/cbor/parseCborBody.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { collectBody } from "@smithy/core";
import { HttpRequest as __HttpRequest } from "@smithy/protocol-http";
import { collectBody } from "@smithy/smithy-client";
import { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types";
import { calculateBodyLength } from "@smithy/util-body-length-browser";

Expand Down
1 change: 1 addition & 0 deletions packages/middleware-compression/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
"dependencies": {
"@smithy/core": "workspace:^",
"@smithy/is-array-buffer": "workspace:^",
"@smithy/node-config-provider": "workspace:^",
"@smithy/protocol-http": "workspace:^",
Expand Down
11 changes: 10 additions & 1 deletion packages/middleware-compression/src/compressionMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setFeature } from "@smithy/core";
import { HttpRequest } from "@smithy/protocol-http";
import {
AbsoluteLocation,
Expand All @@ -6,6 +7,7 @@ import {
BuildHandlerOptions,
BuildHandlerOutput,
BuildMiddleware,
HandlerExecutionContext,
MetadataBearer,
} from "@smithy/types";

Expand Down Expand Up @@ -39,7 +41,10 @@ export const compressionMiddleware =
config: CompressionResolvedConfig & CompressionPreviouslyResolved,
middlewareConfig: CompressionMiddlewareConfig
): BuildMiddleware<any, any> =>
<Output extends MetadataBearer>(next: BuildHandler<any, Output>): BuildHandler<any, Output> =>
<Output extends MetadataBearer>(
next: BuildHandler<any, Output>,
context: HandlerExecutionContext
): BuildHandler<any, Output> =>
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
if (!HttpRequest.isInstance(args.request)) {
return next(args);
Expand Down Expand Up @@ -88,6 +93,10 @@ export const compressionMiddleware =
updatedHeaders = { ...headers, "content-encoding": algorithm };
}

if (headers["content-encoding"].includes("gzip")) {
setFeature(context, "GZIP_REQUEST_COMPRESSION", "L");
}

// We've matched on one supported algorithm in the
// priority-ordered list, so we're finished.
break;
Expand Down
1 change: 1 addition & 0 deletions packages/middleware-endpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@smithy/core": "workspace:^",
"@smithy/middleware-serde": "workspace:^",
"@smithy/node-config-provider": "workspace:^",
"@smithy/shared-ini-file-loader": "workspace:^",
Expand Down
5 changes: 5 additions & 0 deletions packages/middleware-endpoint/src/endpointMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setFeature } from "@smithy/core";
import {
AuthScheme,
EndpointParameters,
Expand Down Expand Up @@ -38,6 +39,10 @@ export const endpointMiddleware = <T extends EndpointParameters>({
context: HandlerExecutionContext
): SerializeHandler<any, Output> =>
async (args: SerializeHandlerArguments<any>): Promise<SerializeHandlerOutput<Output>> => {
if (config.endpoint) {
setFeature(context, "ENDPOINT_OVERRIDE", "N");
}

const endpoint: EndpointV2 = await getEndpointFromInstructions(
args.input,
{
Expand Down
1 change: 1 addition & 0 deletions packages/smithy-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@smithy/core": "workspace:^",
"@smithy/middleware-endpoint": "workspace:^",
"@smithy/middleware-stack": "workspace:^",
"@smithy/protocol-http": "workspace:^",
Expand Down
25 changes: 2 additions & 23 deletions packages/smithy-client/src/collect-stream-body.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
import { SerdeContext } from "@smithy/types";
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream";

/**
* @internal
*
* Collect low-level response body stream to Uint8Array.
* Backwards compatibility re-export.
*/
export const collectBody = async (
streamBody: any = new Uint8Array(),
context: {
streamCollector: SerdeContext["streamCollector"];
}
): Promise<Uint8ArrayBlobAdapter> => {
if (streamBody instanceof Uint8Array) {
return Uint8ArrayBlobAdapter.mutate(streamBody);
}

if (!streamBody) {
return Uint8ArrayBlobAdapter.mutate(new Uint8Array());
}

const fromContext = context.streamCollector(streamBody);

return Uint8ArrayBlobAdapter.mutate(await fromContext);
};
export { collectBody } from "@smithy/core";
10 changes: 2 additions & 8 deletions packages/smithy-client/src/extended-encode-uri-component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/**
* @internal
*
* Function that wraps encodeURIComponent to encode additional characters
* to fully adhere to RFC 3986.
* Backwards compatibility re-export.
*/
export function extendedEncodeURIComponent(str: string): string {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
});
}
export { extendedEncodeURIComponent } from "@smithy/core";
31 changes: 2 additions & 29 deletions packages/smithy-client/src/resolve-path.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";

/**
* @internal
* Backwards compatibility re-export.
*/
export const resolvedPath = (
resolvedPath: string,
input: unknown,
memberName: string,
labelValueProvider: () => string | undefined,
uriLabel: string,
isGreedyLabel: boolean
): string => {
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
const labelValue = labelValueProvider() as string;
if (labelValue.length <= 0) {
throw new Error("Empty value provided for input HTTP label: " + memberName + ".");
}
resolvedPath = resolvedPath.replace(
uriLabel,
isGreedyLabel
? labelValue
.split("/")
.map((segment) => extendedEncodeURIComponent(segment))
.join("/")
: extendedEncodeURIComponent(labelValue)
);
} else {
throw new Error("No value provided for input HTTP label: " + memberName + ".");
}
return resolvedPath;
};
export { resolvedPath } from "@smithy/core";
Loading