Skip to content

Commit

Permalink
fix(middleware-sdk-s3-control): place host prefix dedupe after serial…
Browse files Browse the repository at this point in the history
…izer
  • Loading branch information
kuhe committed Dec 14, 2022
1 parent c5c8cd1 commit 7dff8ee
Showing 1 changed file with 7 additions and 9 deletions.
@@ -1,6 +1,6 @@
import {
EndpointV2,
HandlerExecutionContext,
HttpRequest,
Pluggable,
RelativeMiddlewareOptions,
SerializeHandler,
Expand All @@ -21,11 +21,9 @@ import { deduplicateHostPrefix } from "./deduplicateHostPrefix";
export const hostPrefixDeduplicationMiddleware = (): SerializeMiddleware<any, any> => {
return (next: SerializeHandler<any, any>, context: HandlerExecutionContext): SerializeHandler<any, any> =>
async (args: SerializeHandlerArguments<any>): Promise<SerializeHandlerOutput<any>> => {
const endpoint: EndpointV2 | undefined = context.endpointV2;
if (endpoint?.url?.hostname) {
endpoint.url.hostname = deduplicateHostPrefix(endpoint.url.hostname);
} else {
throw new Error("Endpoint w/ url.hostname not found in hostPrefixDeduplicationMiddleware.");
const httpRequest: HttpRequest = (args.request ?? {}) as HttpRequest;
if (httpRequest?.hostname) {
httpRequest.hostname = deduplicateHostPrefix(httpRequest.hostname);
}
return next(args);
};
Expand All @@ -36,7 +34,7 @@ export const hostPrefixDeduplicationMiddleware = (): SerializeMiddleware<any, an
*/
export const hostPrefixDeduplicationMiddlewareOptions: RelativeMiddlewareOptions = {
tags: ["HOST_PREFIX_DEDUPLICATION", "ENDPOINT_V2", "ENDPOINT"],
toMiddleware: "endpointV2Middleware",
toMiddleware: "serializerMiddleware",
relation: "after",
name: "hostPrefixDeduplicationMiddleware",
override: true,
Expand All @@ -45,8 +43,8 @@ export const hostPrefixDeduplicationMiddlewareOptions: RelativeMiddlewareOptions
/**
* @internal
*/
export const getHostPrefixDeduplicationPlugin = <T>(config?: T): Pluggable<any, any> => ({
export const getHostPrefixDeduplicationPlugin = <T>(config: T): Pluggable<any, any> => ({
applyToStack: (clientStack) => {
clientStack.add(hostPrefixDeduplicationMiddleware(), hostPrefixDeduplicationMiddlewareOptions);
clientStack.addRelativeTo(hostPrefixDeduplicationMiddleware(), hostPrefixDeduplicationMiddlewareOptions);
},
});

0 comments on commit 7dff8ee

Please sign in to comment.