http-transform
An extension of the Node.js Transform stream that additionally supports the HTTP header interface.
RequestPair
: creates a pair of related streams, one writable, one readable; anything written to theclientWritableSide
is readable on theserverReadableSide
.ResponsePair
: creates a pair of related streams, one writable, one readable; anything written to theserverWritableSide
is readable on theclientReadableSide
.ResponsePassThrough
: creates a Duplex stream that also stores HTTP headers; anything written to it becomes readable. Headers are passed through as exactly as possible. It should typically possible to pipe a response through a ResponsePassThrough instance with no change in behavior. This is typically used to programmatically create a response that's readable the same way a Node.jsreq
object is, and can be piped to ares
server response object.
TODO
RequestPassThrough
— Request variation ofResponsePassThrough
RequestThroughOrigin
— subclass of RequestPair that applies header normalizations, as if the request is actually going through the network.ResponseThroughOrigin
— subclass of ResponsePair that applies header normalizations, as if the response is actually going through the network.
Features
Mock a readable response object:
{ const res = ; res res; return resreadableClientSide;}
Add a Content-Type to a ReadableStream:
const http = ;const createReadStream = ;const inherits = ;const ResponseTransform = ;const markdown = ; { super; const input output = this; output; output; output; output; output; output; output; output; output; output; input; }; const server = http;server;
API
ResponseTransform
A subclass of the Node.js Transform that also transforms HTTP headers and status code.
Properties/methods:
- headersReady - A promise that resolves when headers have been committed and are ready to be read
PassThrough
Accepts input and passes it to the write target(s).
This can be used to convert a typical ReadableStream into one that produces HTTP headers.
Headers
Headers is a simple container for HTTP headers. Its methods and properties are imported into ServerResponseTransform.
Properties/methods, as implemented in Node.js:
- statusCode
- statusMessage
- getHeader(name)
- setHeader(name, value)
- removeHeader(name)
- getHeaderNames()
- getHeaders()
- hasHeader(name)
- pipe(dst)
Additional methods:
- addHeader(name, value)
- pipeHeaders(dst) - copy status/message fields to
dst
- pipeMessage(dst) - copy status, message fields, and pipe the stream to
dst