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();
The desired HTTP status.
Response headers, if any.
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.
A response handler.
Creates a TestHttpHandler that will cause the request to terminate with a network error, by closing the response socket prematurely.
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"));
The desired HTTP status.
Response headers, if any.
Response body, if any.
A response handler.
Shortcut for creating a TestHttpHandler that sends a 200 response with JSON content.
server.forMethodAndPath("get", "/path",
TestHttpHandlers.respondJson({ message: "hi" }));
A value of any type that will be converted to JSON.
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();
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.
Generated using TypeDoc
Predefined implementations of TestHttpHandler for use with TestHttpServer.