How to use @aws-sdk/protocol-http - 10 common examples

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-sdk-glacier / src / add-glacier-api-version.spec.ts View on Github external
it("sets the x-amz-glacier-version header", async () => {
    const handler = addGlacierApiVersionMiddleware({
      apiVersion: "1970-01-01"
    })(mockNextHandler, {} as any);

    await handler({
      input: {},
      request: new HttpRequest({
        headers: {}
      })
    });

    // ensure the next handler was called
    expect(mockNextHandler.mock.calls.length).toBe(1);
    const { request } = mockNextHandler.mock.calls[0][0];
    expect(request.headers["x-amz-glacier-version"]).toBe("1970-01-01");
  });
});
github aws / aws-sdk-js-v3 / packages / node-http-handler / src / node-http-handler.spec.ts View on Github external
mockHttpsServer.addListener(
        "request",
        createResponseFunction(mockResponse)
      );
      const spy = jest.spyOn(https, "request").mockImplementationOnce(() => {
        let calls = spy.mock.calls;
        let currentIndex = calls.length - 1;
        return https.request(calls[currentIndex][0], calls[currentIndex][1]);
      });
      // clear data held from previous tests
      spy.mockClear();
      const nodeHttpHandler = new NodeHttpHandler();

      await expect(
        nodeHttpHandler.handle(
          new HttpRequest({
            hostname: "localhost",
            method: "GET",
            port: (mockHttpsServer.address() as AddressInfo).port,
            protocol: "https:",
            path: "/",
            headers: {}
          }),
          {
            abortSignal: {
              aborted: true
            }
          }
        )
      ).rejects.toHaveProperty("name", "AbortError");

      expect(spy.mock.calls.length).toBe(0);
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / prepareRequest.spec.ts View on Github external
import { prepareRequest } from "./prepareRequest";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { AMZ_DATE_HEADER, AUTH_HEADER, DATE_HEADER } from "./constants";

const minimalRequest = new HttpRequest({
  method: "POST",
  protocol: "https:",
  path: "/",
  headers: {
    host: "foo.us-bar-1.amazonaws.com"
  },
  hostname: "foo.us-bar-1.amazonaws.com"
});

describe("prepareRequest", () => {
  it("should clone requests", () => {
    const prepared = prepareRequest(minimalRequest);
    expect(prepared).toEqual(prepareRequest(minimalRequest));
    expect(prepared).not.toBe(prepareRequest(minimalRequest));
  });
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / moveHeadersToQuery.spec.ts View on Github external
import { moveHeadersToQuery } from "./moveHeadersToQuery";
import { HttpRequest } from "@aws-sdk/protocol-http";

const minimalRequest = new HttpRequest({
  method: "POST",
  protocol: "https:",
  path: "/",
  headers: {
    host: "foo.us-east-1.amazonaws.com"
  },
  hostname: "foo.us-east-1.amazonaws.com"
});

describe("moveHeadersToQuery", () => {
  it('should hoist "x-amz-" headers to the querystring', () => {
    const req = moveHeadersToQuery(
      new HttpRequest({
        ...minimalRequest,
        headers: {
          Host: "www.example.com",
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / getPayloadHash.spec.ts View on Github external
describe("getPayloadHash", () => {
  const minimalRequest = new HttpRequest({
    method: "POST",
    protocol: "https:",
    path: "/",
    headers: {},
    hostname: "foo.us-east-1.amazonaws.com"
  });

  it("should return the SHA-256 hash of an empty string if a request has no payload (body)", async () => {
    await expect(getPayloadHash(minimalRequest, Sha256)).resolves.toBe(
      "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
    );
  });

  it(`should return the value in the '${SHA256_HEADER}' header (if present)`, async () => {
    await expect(
      getPayloadHash(
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / getCanonicalHeaders.spec.ts View on Github external
it("should downcase all headers", () => {
    expect(
      getCanonicalHeaders(
        new HttpRequest({
          method: "POST",
          protocol: "https:",
          path: "/",
          headers: {
            fOo: "bar",
            BaZ: "QUUX",
            HoSt: "foo.us-east-1.amazonaws.com"
          },
          hostname: "foo.us-east-1.amazonaws.com"
        })
      )
    ).toEqual({
      foo: "bar",
      baz: "QUUX",
      host: "foo.us-east-1.amazonaws.com"
    });
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / prepareRequest.spec.ts View on Github external
it("should ignore previously set authorization, date, and x-amz-date headers", async () => {
    const { headers } = prepareRequest(
      new HttpRequest({
        ...minimalRequest,
        headers: {
          [AUTH_HEADER]: "foo",
          [AMZ_DATE_HEADER]: "bar",
          [DATE_HEADER]: "baz"
        }
      })
    );
    expect(headers[AUTH_HEADER]).toBeUndefined();
    expect(headers[AMZ_DATE_HEADER]).toBeUndefined();
    expect(headers[DATE_HEADER]).toBeUndefined();
  });
});
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / SignatureV4.spec.ts View on Github external
describe("URI encoding paths", () => {
      const minimalRequest = new HttpRequest({
        method: "POST",
        protocol: "https:",
        path: "/foo%3Dbar",
        headers: {
          host: "foo.us-bar-1.amazonaws.com"
        },
        hostname: "foo.us-bar-1.amazonaws.com"
      });

      it("should URI-encode the path by default", async () => {
        const { query = {} } = await signer.presignRequest(
          minimalRequest,
          expiration,
          presigningOptions
        );
        expect(query[SIGNATURE_QUERY_PARAM]).toBe(
github aws / aws-sdk-js-v3 / packages / middleware-expect-continue / src / index.spec.ts View on Github external
it("does not set the Expect header to 100-continue for browser runtime", async () => {
    const handler = addExpectContinueMiddleware({ runtime: "browser" })(
      mockNextHandler,
      {} as any
    );
    await handler({
      input: {},
      request: new HttpRequest({
        body: "foo",
        headers: {}
      })
    });

    const { calls } = (mockNextHandler as any).mock;
    expect(calls.length).toBe(1);
    const { request } = mockNextHandler.mock.calls[0][0];
    expect(request.headers["Expect"]).toBeUndefined();
  });
});
github aws / aws-sdk-js-v3 / packages / response-metadata-extractor / src / index.spec.ts View on Github external
it("should prefer the request ID from the standard header", () => {
    expect(
      extractMetadata(new HttpResponse({
        ...httpResponseOptions,
        headers: {
          "X-Amz-Request-ID": "id",
          "X-Amz-RequestId": "alt_id"
        }
      })).requestId
    ).toBe("id");
  });

@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