Skip to content

Commit

Permalink
fix(middleware-user-agent): add middleware to final step of build (#1833
Browse files Browse the repository at this point in the history
)

previously the middleware was added relative(before) signing middleware.
It will through for the requests not requiring singing. So change it
to absolute position.
  • Loading branch information
AllanZhengYP authored Dec 23, 2020
1 parent 0711503 commit e7dce39
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/middleware-user-agent/src/user-agent-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { HttpRequest } from "@aws-sdk/protocol-http";
import {
FinalizeHandler,
FinalizeHandlerArguments,
FinalizeHandlerOutput,
AbsoluteLocation,
BuildHandler,
BuildHandlerArguments,
BuildHandlerOptions,
BuildHandlerOutput,
HandlerExecutionContext,
MetadataBearer,
Pluggable,
RelativeMiddlewareOptions,
UserAgentPair,
} from "@aws-sdk/types";

Expand All @@ -26,9 +27,9 @@ import { SPACE, UA_ESCAPE_REGEX, USER_AGENT, X_AMZ_USER_AGENT } from "./constant
* agent.
*/
export const userAgentMiddleware = (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(
next: FinalizeHandler<any, any>,
next: BuildHandler<any, any>,
context: HandlerExecutionContext
): FinalizeHandler<any, any> => async (args: FinalizeHandlerArguments<any>): Promise<FinalizeHandlerOutput<Output>> => {
): BuildHandler<any, any> => async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
const { request } = args;
if (!HttpRequest.isInstance(request)) return next(args);
const { headers } = request;
Expand Down Expand Up @@ -70,15 +71,15 @@ const escapeUserAgent = ([name, version]: UserAgentPair): string => {
.join("/");
};

export const getUserAgentMiddlewareOptions: RelativeMiddlewareOptions = {
export const getUserAgentMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation = {
name: "getUserAgentMiddleware",
relation: "before",
toMiddleware: "awsAuthMiddleware",
step: "build",
priority: "low",
tags: ["SET_USER_AGENT", "USER_AGENT"],
};

export const getUserAgentPlugin = (config: UserAgentResolvedConfig): Pluggable<any, any> => ({
applyToStack: (clientStack) => {
clientStack.addRelativeTo(userAgentMiddleware(config), getUserAgentMiddlewareOptions);
clientStack.add(userAgentMiddleware(config), getUserAgentMiddlewareOptions);
},
});

0 comments on commit e7dce39

Please sign in to comment.