This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs-blog-newsletter/cronjob/node_modules/@aws-sdk/middleware-host-header/dist-es/index.js

34 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-05-26 22:54:55 +02:00
import { HttpRequest } from "@smithy/protocol-http";
export function resolveHostHeaderConfig(input) {
return input;
}
export const hostHeaderMiddleware = (options) => (next) => async (args) => {
if (!HttpRequest.isInstance(args.request))
return next(args);
const { request } = args;
const { handlerProtocol = "" } = options.requestHandler.metadata || {};
if (handlerProtocol.indexOf("h2") >= 0 && !request.headers[":authority"]) {
delete request.headers["host"];
request.headers[":authority"] = request.hostname + (request.port ? ":" + request.port : "");
}
else if (!request.headers["host"]) {
let host = request.hostname;
if (request.port != null)
host += `:${request.port}`;
request.headers["host"] = host;
}
return next(args);
};
export const hostHeaderMiddlewareOptions = {
name: "hostHeaderMiddleware",
step: "build",
priority: "low",
tags: ["HOST"],
override: true,
};
export const getHostHeaderPlugin = (options) => ({
applyToStack: (clientStack) => {
clientStack.add(hostHeaderMiddleware(options), hostHeaderMiddlewareOptions);
},
});