Options
All
  • Public
  • Public/Protected
  • All
Menu

Predefined implementations of TestHttpHandler for use with TestHttpServer.

Hierarchy

  • TestHttpHandlers

Index

Constructors

Methods

  • Creates a TestHttpHandler that sends a chunked HTTP response, using an AsyncQueue as a pipe.

        const chunkQueue = new AsyncQueue<string>();
    server.forMethodAndPath("get", "/path",
    TestHttpHandlers.chunkedStream(200, {}, chunkQueue));
    chunkQueue.add("a chunk of data");
    chunkQueue.add("another one");
    chunkQueue.close();

    Parameters

    • status: number

      The desired HTTP status.

    • headers: TestHttpHeaders

      Response headers, if any.

    • chunkQueue: AsyncQueue<string>

      An existing AsyncQueue. As you add chunks of response data to the queue, they will be consumed and sent. Call close() on the queue to end the response.

    Returns TestHttpHandler

    A response handler.

  • Creates a TestHttpHandler that will cause the request to terminate with a network error, by closing the response socket prematurely.

    Returns TestHttpHandler

    A response handler.

  • Creates a TestHttpHandler that sends a simple response.

        server.forMethodAndPath("get", "/path", TestHttpHandlers.respond(500));
    server.forMethodAndPath("get", "/path",
    TestHttpHandlers.respond(200, { "content-type": "text/plain" }, "hi"));

    Parameters

    • status: number

      The desired HTTP status.

    • Optional headers: TestHttpHeaders

      Response headers, if any.

    • Optional body: string

      Response body, if any.

    Returns TestHttpHandler

    A response handler.

  • Shortcut for creating a TestHttpHandler that sends a 200 response with JSON content.

        server.forMethodAndPath("get", "/path",
    TestHttpHandlers.respondJson({ message: "hi" }));

    Parameters

    • serializableData: any

      A value of any type that will be converted to JSON.

    Returns TestHttpHandler

    A response handler.

  • Creates a TestHttpHandler that sends a streaming response in Server-Sent Events format, using an AsyncQueue as an event pipe.

        const eventQueue = new AsyncQueue<SSEItem>();
    server.forMethodAndPath("get", "/path",
    TestHttpHandlers.sseStream(eventQueue));
    eventQueue.add({ type: "patch", data: { path: "/flags", key: "x" } });
    eventQueue.add({ comment: "" });
    eventQueue.close();

    Parameters

    • eventQueue: AsyncQueue<SSEItem>

      An existing AsyncQueue. As you add SSEItem objects to the queue, they will be consumed and sent. Call close() on the queue to end the response.

    Returns TestHttpHandler

Generated using TypeDoc