How to use the @aws-sdk/protocol-http.HttpRequest.isInstance function in @aws-sdk/protocol-http

To help you get started, we’ve selected a few @aws-sdk/protocol-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-sdk-js-v3 / packages / middleware-host-header / src / index.ts View on Github external
): BuildMiddleware => next => async args => {
  if (!HttpRequest.isInstance(args.request)) return next(args);
  const { request } = args;
  const { handlerProtocol = "" } = options.requestHandler.metadata || {};
  //For H2 request, remove 'host' header and use ':authority' header instead
  //reference: https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#ERR_HTTP2_INVALID_CONNECTION_HEADERS
  if (handlerProtocol.indexOf("h2") >= 0 && !request.headers[":authority"]) {
    delete request.headers["host"];
    request.headers[":authority"] = "";
    //non-H2 request and 'host' header is not set, set the 'host' header to request's hostname.
  } else if (!request.headers["host"]) {
    request.headers["host"] = request.hostname;
  }
  return next(args);
};
github aws / aws-sdk-js-v3 / packages / middleware-user-agent / src / middleware.ts View on Github external
): BuildHandler => (
    args: BuildHandlerArguments
  ): Promise> => {
    let { request } = args;
    if (!HttpRequest.isInstance(request)) return next(args);
    const { headers } = request;
    if (!headers[userAgentHeader]) {
      headers[userAgentHeader] = `${options.defaultUserAgent}`;
    } else {
      headers[userAgentHeader] += ` ${options.defaultUserAgent}`;
    }
    if (options.customUserAgent) {
      headers[userAgentHeader] += ` ${options.customUserAgent}`;
    }
    return next({
      ...args,
      request
    });
  };
}
github aws / aws-sdk-js-v3 / packages / middleware-header-default / src / index.ts View on Github external
return (args: BuildHandlerArguments) => {
      if (HttpRequest.isInstance(args.request)) {
        const headers = { ...args.request.headers };

        for (const name of Object.keys(headerBag)) {
          if (!(name in headers)) {
            headers[name] = headerBag[name];
          }
        }

        return next({
          ...args,
          request: {
            ...args.request,
            headers
          }
        });
      } else {
github aws / aws-sdk-js-v3 / packages / middleware-signing / src / middleware.ts View on Github external
async function(
      args: FinalizeHandlerArguments<input>
    ): Promise&gt; {
      if (!HttpRequest.isInstance(args.request)) return next(args);
      const signer =
        typeof options.signer === "function"
          ? await options.signer()
          : options.signer;
      const output = await next({
        ...args,
        request: await signer.sign(args.request, {
          signingDate: new Date(Date.now() + options.systemClockOffset)
        })
      });

      const { headers } = output.response as any;
      const dateHeader = headers &amp;&amp; (headers.date || headers.Date);
      if (dateHeader) {
        const serverTime = Date.parse(dateHeader);
        if (isClockSkewed(serverTime, options.systemClockOffset)) {
github aws / aws-sdk-js-v3 / packages / middleware-sdk-glacier / src / add-glacier-api-version.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    let request = args.request;
    if (HttpRequest.isInstance(request)) {
      request.headers["x-amz-glacier-version"] = options.apiVersion;
    }

    return next({
      ...args,
      request
    });
  };
}
github aws / aws-sdk-js-v3 / packages / middleware-expect-continue / src / index.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    let { request } = args;
    if (
      HttpRequest.isInstance(request) &amp;&amp;
      request.body &amp;&amp;
      options.runtime === "node"
    ) {
      request.headers = {
        ...request.headers,
        Expect: "100-continue"
      };
    }
    return next({
      ...args,
      request
    });
  };
}
github aws / aws-sdk-js-v3 / packages / middleware-bucket-endpoint / src / bucketEndpointMiddleware.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    const { Bucket: bucketName } = args.input;
    let replaceBucketInPath = options.bucketEndpoint;
    let request = args.request;
    if (HttpRequest.isInstance(request)) {
      if (options.bucketEndpoint) {
        request.hostname = bucketName;
      } else {
        const { hostname, bucketEndpoint } = bucketHostname({
          bucketName,
          baseHostname: request.hostname,
          accelerateEndpoint: options.useAccelerateEndpoint,
          dualstackEndpoint: options.useDualstackEndpoint,
          pathStyleEndpoint: options.forcePathStyle,
          tlsCompatible: request.protocol === "https:"
        });

        request.hostname = hostname;
        replaceBucketInPath = bucketEndpoint;
      }
github aws / aws-sdk-js-v3 / packages / middleware-sdk-api-gateway / src / index.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    let { request } = args;
    if (HttpRequest.isInstance(request)) {
      request.headers = {
        ...request.headers,
        accepts: "application/json"
      };
    }
    return next({
      ...args,
      request
    });
  };
}
github aws / aws-sdk-js-v3 / packages / middleware-content-length / src / index.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    let request = args.request;
    if (HttpRequest.isInstance(request)) {
      const { body, headers } = request;
      if (
        body &amp;&amp;
        Object.keys(headers)
          .map(str =&gt; str.toLowerCase())
          .indexOf(CONTENT_LENGTH_HEADER) === -1
      ) {
        const length = bodyLengthChecker(body);
        if (length !== undefined) {
          request.headers = {
            ...request.headers,
            [CONTENT_LENGTH_HEADER]: String(length)
          };
        }
      }
    }
github aws / aws-sdk-js-v3 / packages / middleware-apply-body-checksum / src / applyMd5BodyChecksumMiddleware.ts View on Github external
): BuildHandler =&gt; async (
    args: BuildHandlerArguments
  ): Promise&gt; =&gt; {
    let { request } = args;
    if (HttpRequest.isInstance(request)) {
      const { body, headers } = request;
      if (!hasHeader("Content-MD5", headers)) {
        let digest: Promise;
        if (
          body === undefined ||
          typeof body === "string" ||
          ArrayBuffer.isView(body) ||
          isArrayBuffer(body)
        ) {
          const hash = new options.md5();
          hash.update(body || "");
          digest = hash.digest();
        } else {
          digest = options.streamHasher(options.md5, body);
        }

@aws-sdk/protocol-http

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/protocol-http/latest.svg)](https://www.npmjs.com/package/@aws-sdk/protocol-http) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/protocol-http.svg)](https://www.npmjs.com/package/@aws-sdk/prot

Apache-2.0
Latest version published 1 year ago

Package Health Score

72 / 100
Full package analysis

Similar packages