#
Class: PetitioResponsePetitioResponse.PetitioResponse
#
Constructors#
constructor+ new PetitioResponse(): PetitioResponse
Returns: PetitioResponse
#
Properties#
body• body: Buffer
The response body received from the server. This is updated in chunks through PetitioResponse._addChunk, either from PetitioRequest.send or directly on a response object from another source.
Defined in: lib/PetitioResponse.ts:12
#
headers• headers: object
The response headers received from the server. This is updated through PetitioResponse._parseHeaders.
#
Type declaration:Defined in: lib/PetitioResponse.ts:17
#
statusCode• statusCode: null | number= null
The status code received from the server. This is set only after the response is complete when headers are received or it can be set manually.
Defined in: lib/PetitioResponse.ts:23
#
Methods#
_addChunkâ–¸ _addChunk(chunk
: Buffer | Uint8Array): void
This appends data to the body, dynamically reallocating the buffer size as chunks are added. Therefore, this is currently unsuitable for handling large responses, as the exact size is allocated in memory as a buffer.
#
Parameters:Name | Type | Description |
---|---|---|
chunk | Buffer | Uint8Array | The chunk of data to append to the body. |
Returns: void
In place operation with no return.
Defined in: lib/PetitioResponse.ts:32
#
_parseHeadersâ–¸ _parseHeaders(headers
: string[]): void
#
Parameters:Name | Type | Description |
---|---|---|
headers | string[] | The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists. |
Returns: void
In place operation with no return.
Defined in: lib/PetitioResponse.ts:43
#
jsonâ–¸ json<T>(encoding?
: BufferEncoding): T
#
Type parameters:Name | Default | Description |
---|---|---|
T | any | Type casting parameter for the JSON result. |
#
Parameters:Name | Type | Default value |
---|---|---|
encoding | BufferEncoding | "utf8" |
Returns: T
A serialized object result parsed from the response body.
Defined in: lib/PetitioResponse.ts:62
#
textâ–¸ text(encoding?
: BufferEncoding): string
#
Parameters:Name | Type | Default value |
---|---|---|
encoding | BufferEncoding | "utf8" |
Returns: string
The response body decoded as as a string from the buffer, using either the encoding specified in encoding
or UTF-8 by default..
Defined in: lib/PetitioResponse.ts:70