@fkn/lib/http
Classes
Section titled “Classes”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Agent(options?): Agent;Parameters
Section titled “Parameters”options?
Section titled “options?”Record<string, unknown> = {}
Returns
Section titled “Returns”Properties
Section titled “Properties”keepAlive
Section titled “keepAlive”keepAlive: boolean;maxFreeSockets
Section titled “maxFreeSockets”maxFreeSockets: number;maxSockets
Section titled “maxSockets”maxSockets: number;options
Section titled “options”options: Record<string, unknown>;Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy(): void;Returns
Section titled “Returns”void
getName()
Section titled “getName()”getName(options?): string;Parameters
Section titled “Parameters”options?
Section titled “options?”string
localAddress?
Section titled “localAddress?”string
number
Returns
Section titled “Returns”string
ClientRequest
Section titled “ClientRequest”Extends
Section titled “Extends”OutgoingMessage
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ClientRequest(options, callback?): ClientRequest;Parameters
Section titled “Parameters”options
Section titled “options”callback?
Section titled “callback?”(res) => void
Returns
Section titled “Returns”Overrides
Section titled “Overrides”OutgoingMessage.constructorProperties
Section titled “Properties”aborted
Section titled “aborted”aborted: boolean = false;chunkedEncoding
Section titled “chunkedEncoding”chunkedEncoding: boolean = false;Inherited from
Section titled “Inherited from”OutgoingMessage.chunkedEncodingfinished
Section titled “finished”finished: boolean = false;Inherited from
Section titled “Inherited from”OutgoingMessage.finishedheadersSent
Section titled “headersSent”headersSent: boolean = false;Inherited from
Section titled “Inherited from”OutgoingMessage.headersSenthost: string;method
Section titled “method”method: string;path: string;protocol
Section titled “protocol”protocol: string;res: IncomingMessage | null = null;socket
Section titled “socket”socket: Socket;Overrides
Section titled “Overrides”OutgoingMessage.socketAccessors
Section titled “Accessors”connection
Section titled “connection”Get Signature
Section titled “Get Signature”get connection(): Socket;alias retained for Node compatibility
Returns
Section titled “Returns”Methods
Section titled “Methods”abort()
Section titled “abort()”abort(): void;Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy(error?): this;Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable
stream has ended and subsequent calls to write() or end() will result in
an ERR_STREAM_DESTROYED error.
This is a destructive and immediate way to destroy a stream. Previous calls to write() may not have drained, and may trigger an ERR_STREAM_DESTROYED error.
Use end() instead of destroy if data should flush before close, or wait for
the 'drain' event before destroying the stream.
Once destroy() has been called any further calls will be a no-op and no
further errors except from _destroy() may be emitted as 'error'.
Implementors should not override this method,
but instead implement writable._destroy().
Parameters
Section titled “Parameters”error?
Section titled “error?”Error
Optional, an error to emit with 'error' event.
Returns
Section titled “Returns”this
v8.0.0
Overrides
Section titled “Overrides”OutgoingMessage.destroyend( chunk?, encoding?, callback?): this;Parameters
Section titled “Parameters”chunk?
Section titled “chunk?”unknown
encoding?
Section titled “encoding?”unknown
callback?
Section titled “callback?”unknown
Returns
Section titled “Returns”this
Overrides
Section titled “Overrides”OutgoingMessage.endgetHeader()
Section titled “getHeader()”getHeader(name): string | number | string[] | undefined;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string | number | string[] | undefined
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeadergetHeaderNames()
Section titled “getHeaderNames()”getHeaderNames(): string[];Returns
Section titled “Returns”string[]
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeaderNamesgetHeaders()
Section titled “getHeaders()”getHeaders(): OutgoingHttpHeaders;Returns
Section titled “Returns”OutgoingHttpHeaders
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeadershasHeader()
Section titled “hasHeader()”hasHeader(name): boolean;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”OutgoingMessage.hasHeaderremoveHeader()
Section titled “removeHeader()”removeHeader(name): void;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”OutgoingMessage.removeHeadersetHeader()
Section titled “setHeader()”setHeader(name, value): this;Parameters
Section titled “Parameters”string
string | number | readonly string[]
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”OutgoingMessage.setHeadersetNoDelay()
Section titled “setNoDelay()”setNoDelay(noDelay?): void;Parameters
Section titled “Parameters”noDelay?
Section titled “noDelay?”boolean
Returns
Section titled “Returns”void
setSocketKeepAlive()
Section titled “setSocketKeepAlive()”setSocketKeepAlive(enable?, initialDelay?): void;Parameters
Section titled “Parameters”enable?
Section titled “enable?”boolean
initialDelay?
Section titled “initialDelay?”number
Returns
Section titled “Returns”void
setTimeout()
Section titled “setTimeout()”setTimeout(timeout, callback?): this;Parameters
Section titled “Parameters”timeout
Section titled “timeout”number
callback?
Section titled “callback?”() => void
Returns
Section titled “Returns”this
write()
Section titled “write()”write( chunk, encoding?, callback?): boolean;The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
If false is returned, further attempts to write data to the stream should
stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
return false. Once all currently buffered chunks are drained (accepted for
delivery by the operating system), the 'drain' event will be emitted.
Once write() returns false, do not write more chunks
until the 'drain' event is emitted. While calling write() on a stream that
is not draining is allowed, Node.js will buffer all written chunks until
maximum memory usage occurs, at which point it will abort unconditionally.
Even before it aborts, high memory usage will cause poor garbage collector
performance and high RSS (which is not typically released back to the system,
even after the memory is no longer required). Since TCP sockets may never
drain if the remote peer does not read the data, writing a socket that is
not draining can keep buffering until the process runs out of memory.
Writing data while the stream is not draining is particularly
problematic for a Transform, because the Transform streams are paused
by default until they are piped or a 'data' or 'readable' event handler
is added.
If the data to be written can be generated or fetched on demand, it is
recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) { if (!stream.write(data)) { stream.once('drain', cb); } else { process.nextTick(cb); }}
// Wait for cb to be called before doing any other write.write('hello', () => { console.log('Write completed, do more writes now.');});A Writable stream in object mode will always ignore the encoding argument.
Parameters
Section titled “Parameters”unknown
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
encoding?
Section titled “encoding?”BufferEncoding | ((error) => void)
The encoding, if chunk is a string.
callback?
Section titled “callback?”(error) => void
Callback for when this chunk of data is flushed.
Returns
Section titled “Returns”boolean
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
v0.9.4
Inherited from
Section titled “Inherited from”OutgoingMessage.writeHTTPParser
Section titled “HTTPParser”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new HTTPParser(mode, handlers): HTTPParser;Parameters
Section titled “Parameters”"request" | "response"
handlers
Section titled “handlers”ParserHandlers
Returns
Section titled “Returns”Properties
Section titled “Properties”skipBody
Section titled “skipBody”skipBody: boolean = false;Methods
Section titled “Methods”execute()
Section titled “execute()”execute(chunk): void;Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”void
finish()
Section titled “finish()”finish(): void;Returns
Section titled “Returns”void
IncomingMessage
Section titled “IncomingMessage”Extends
Section titled “Extends”Readable
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new IncomingMessage(socket): IncomingMessage;Parameters
Section titled “Parameters”socket
Section titled “socket”Returns
Section titled “Returns”Overrides
Section titled “Overrides”Stream.Readable.constructorProperties
Section titled “Properties”complete
Section titled “complete”complete: boolean = false;headers
Section titled “headers”headers: IncomingHttpHeaders = {};httpVersion
Section titled “httpVersion”httpVersion: string = '1.1';httpVersionMajor
Section titled “httpVersionMajor”httpVersionMajor: number = 1;httpVersionMinor
Section titled “httpVersionMinor”httpVersionMinor: number = 1;method?
Section titled “method?”optional method?: string;request only
rawHeaders
Section titled “rawHeaders”rawHeaders: string[] = [];rawTrailers
Section titled “rawTrailers”rawTrailers: string[] = [];socket
Section titled “socket”socket: Socket;statusCode?
Section titled “statusCode?”optional statusCode?: number;response only
statusMessage?
Section titled “statusMessage?”optional statusMessage?: string;response only
trailers
Section titled “trailers”trailers: Record<string, string> = {};optional url?: string;request only
Accessors
Section titled “Accessors”connection
Section titled “connection”Get Signature
Section titled “Get Signature”get connection(): Socket;Returns
Section titled “Returns”Methods
Section titled “Methods”setTimeout()
Section titled “setTimeout()”setTimeout(msecs, callback?): this;Parameters
Section titled “Parameters”number
callback?
Section titled “callback?”() => void
Returns
Section titled “Returns”this
ServerResponse
Section titled “ServerResponse”Extends
Section titled “Extends”OutgoingMessage
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ServerResponse(req): ServerResponse;Parameters
Section titled “Parameters”Returns
Section titled “Returns”Overrides
Section titled “Overrides”OutgoingMessage.constructorProperties
Section titled “Properties”chunkedEncoding
Section titled “chunkedEncoding”chunkedEncoding: boolean = false;Inherited from
Section titled “Inherited from”finished
Section titled “finished”finished: boolean = false;Inherited from
Section titled “Inherited from”headersSent
Section titled “headersSent”headersSent: boolean = false;Inherited from
Section titled “Inherited from”req: IncomingMessage;sendDate
Section titled “sendDate”sendDate: boolean = true;socket
Section titled “socket”socket: Socket | null;Overrides
Section titled “Overrides”OutgoingMessage.socketstatusCode
Section titled “statusCode”statusCode: number = 200;statusMessage?
Section titled “statusMessage?”optional statusMessage?: string;Methods
Section titled “Methods”end( chunk?, encoding?, callback?): this;Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write method after calling end will raise an error.
// Write 'hello, ' and then end with 'world!'.import fs from 'node:fs';const file = fs.createWriteStream('example.txt');file.write('hello, ');file.end('world!');// Writing more now is not allowed!Parameters
Section titled “Parameters”chunk?
Section titled “chunk?”unknown
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
encoding?
Section titled “encoding?”BufferEncoding | (() => void)
The encoding if chunk is a string
callback?
Section titled “callback?”() => void
Callback for when the stream is finished.
Returns
Section titled “Returns”this
v0.9.4
Inherited from
Section titled “Inherited from”OutgoingMessage.endgetHeader()
Section titled “getHeader()”getHeader(name): string | number | string[] | undefined;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string | number | string[] | undefined
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeadergetHeaderNames()
Section titled “getHeaderNames()”getHeaderNames(): string[];Returns
Section titled “Returns”string[]
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeaderNamesgetHeaders()
Section titled “getHeaders()”getHeaders(): OutgoingHttpHeaders;Returns
Section titled “Returns”OutgoingHttpHeaders
Inherited from
Section titled “Inherited from”OutgoingMessage.getHeadershasHeader()
Section titled “hasHeader()”hasHeader(name): boolean;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”OutgoingMessage.hasHeaderremoveHeader()
Section titled “removeHeader()”removeHeader(name): void;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”OutgoingMessage.removeHeadersetHeader()
Section titled “setHeader()”setHeader(name, value): this;Parameters
Section titled “Parameters”string
string | number | readonly string[]
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”OutgoingMessage.setHeadersetTimeout()
Section titled “setTimeout()”setTimeout(msecs, callback?): this;Parameters
Section titled “Parameters”number
callback?
Section titled “callback?”() => void
Returns
Section titled “Returns”this
write()
Section titled “write()”write( chunk, encoding?, callback?): boolean;The writable.write() method writes some data to the stream, and calls the
supplied callback once the data has been fully handled. If an error
occurs, the callback will be called with the error as its
first argument. The callback is called asynchronously and before 'error' is
emitted.
The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk.
If false is returned, further attempts to write data to the stream should
stop until the 'drain' event is emitted.
While a stream is not draining, calls to write() will buffer chunk, and
return false. Once all currently buffered chunks are drained (accepted for
delivery by the operating system), the 'drain' event will be emitted.
Once write() returns false, do not write more chunks
until the 'drain' event is emitted. While calling write() on a stream that
is not draining is allowed, Node.js will buffer all written chunks until
maximum memory usage occurs, at which point it will abort unconditionally.
Even before it aborts, high memory usage will cause poor garbage collector
performance and high RSS (which is not typically released back to the system,
even after the memory is no longer required). Since TCP sockets may never
drain if the remote peer does not read the data, writing a socket that is
not draining can keep buffering until the process runs out of memory.
Writing data while the stream is not draining is particularly
problematic for a Transform, because the Transform streams are paused
by default until they are piped or a 'data' or 'readable' event handler
is added.
If the data to be written can be generated or fetched on demand, it is
recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is
possible to respect backpressure and avoid memory issues using the 'drain' event:
function write(data, cb) { if (!stream.write(data)) { stream.once('drain', cb); } else { process.nextTick(cb); }}
// Wait for cb to be called before doing any other write.write('hello', () => { console.log('Write completed, do more writes now.');});A Writable stream in object mode will always ignore the encoding argument.
Parameters
Section titled “Parameters”unknown
Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
encoding?
Section titled “encoding?”BufferEncoding | ((error) => void)
The encoding, if chunk is a string.
callback?
Section titled “callback?”(error) => void
Callback for when this chunk of data is flushed.
Returns
Section titled “Returns”boolean
false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.
v0.9.4
Inherited from
Section titled “Inherited from”OutgoingMessage.writewriteContinue()
Section titled “writeContinue()”writeContinue(): void;Returns
Section titled “Returns”void
writeHead()
Section titled “writeHead()”writeHead( statusCode, statusMessage?, headers?): this;Parameters
Section titled “Parameters”statusCode
Section titled “statusCode”number
statusMessage?
Section titled “statusMessage?”string | OutgoingHttpHeaders | (OutgoingHttpHeader | undefined)[]
headers?
Section titled “headers?”OutgoingHttpHeaders
Returns
Section titled “Returns”this
Interfaces
Section titled “Interfaces”ClientRequestArgs
Section titled “ClientRequestArgs”Extends
Section titled “Extends”RequestOptions
Properties
Section titled “Properties”optional host?: string;Overrides
Section titled “Overrides”RequestOptions.hosthostname?
Section titled “hostname?”optional hostname?: string;Overrides
Section titled “Overrides”RequestOptions.hostnameoptional path?: string;Overrides
Section titled “Overrides”RequestOptions.pathoptional port?: string | number;Overrides
Section titled “Overrides”RequestOptions.portParsedHead
Section titled “ParsedHead”Properties
Section titled “Properties”headers
Section titled “headers”headers: IncomingHttpHeaders;httpVersion
Section titled “httpVersion”httpVersion: string;httpVersionMajor
Section titled “httpVersionMajor”httpVersionMajor: number;httpVersionMinor
Section titled “httpVersionMinor”httpVersionMinor: number;method?
Section titled “method?”optional method?: string;request only
rawHeaders
Section titled “rawHeaders”rawHeaders: string[];statusCode?
Section titled “statusCode?”optional statusCode?: number;response only
statusMessage?
Section titled “statusMessage?”optional statusMessage?: string;response only
optional url?: string;request only
ServerResponseOptions
Section titled “ServerResponseOptions”Properties
Section titled “Properties”req: IncomingMessage;Type Aliases
Section titled “Type Aliases”RequestListener
Section titled “RequestListener”type RequestListener = (req, res) => void;Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Server
Section titled “Server”type Server = ServerImpl;Variables
Section titled “Variables”_default
Section titled “_default”const _default: object;Type Declaration
Section titled “Type Declaration”Agent: typeof Agent;ClientRequest
Section titled “ClientRequest”ClientRequest: typeof ClientRequest;createServer
Section titled “createServer”createServer: (options?, requestListener?) => ServerImpl;Parameters
Section titled “Parameters”options?
Section titled “options?”object | RequestListener
requestListener?
Section titled “requestListener?”Returns
Section titled “Returns”ServerImpl
get: (...args) => ClientRequest;Parameters
Section titled “Parameters”| [string | URL | ClientRequestArgs, (res) => void]
| [string | URL, ClientRequestArgs, (res) => void]
Returns
Section titled “Returns”globalAgent
Section titled “globalAgent”globalAgent: Agent;IncomingMessage
Section titled “IncomingMessage”IncomingMessage: typeof IncomingMessage;METHODS
Section titled “METHODS”METHODS: string[];OutgoingMessage
Section titled “OutgoingMessage”OutgoingMessage: typeof OutgoingMessage;request
Section titled “request”request: (...args) => ClientRequest;Parameters
Section titled “Parameters”| [string | URL | ClientRequestArgs, (res) => void]
| [string | URL, ClientRequestArgs, (res) => void]
Returns
Section titled “Returns”Server
Section titled “Server”Server: typeof ServerImpl;ServerResponse
Section titled “ServerResponse”ServerResponse: typeof ServerResponse;STATUS_CODES
Section titled “STATUS_CODES”STATUS_CODES: Record<number, string>;globalAgent
Section titled “globalAgent”const globalAgent: Agent;METHODS
Section titled “METHODS”const METHODS: string[];Server
Section titled “Server”const Server: typeof ServerImpl;STATUS_CODES
Section titled “STATUS_CODES”const STATUS_CODES: Record<number, string>;Functions
Section titled “Functions”createServer()
Section titled “createServer()”function createServer(options?, requestListener?): ServerImpl;Parameters
Section titled “Parameters”options?
Section titled “options?”object | RequestListener
requestListener?
Section titled “requestListener?”Returns
Section titled “Returns”ServerImpl
function get(...args): ClientRequest;Parameters
Section titled “Parameters”| [string | URL | ClientRequestArgs, (res) => void]
| [string | URL, ClientRequestArgs, (res) => void]
Returns
Section titled “Returns”request()
Section titled “request()”function request(...args): ClientRequest;Parameters
Section titled “Parameters”| [string | URL | ClientRequestArgs, (res) => void]
| [string | URL, ClientRequestArgs, (res) => void]
Returns
Section titled “Returns”References
Section titled “References”default
Section titled “default”Renames and re-exports _default