HttpUtils
@codification/cutwater-node-core > HttpUtils
Class
Utility for handling common HTTP related tasks.
beta:
Hierarchy
HttpUtils
Methods
Methods
<Static>
isResponseOk
▸ isResponseOk(response: IncomingMessage
): boolean
Defined in HttpUtils.ts:17
Returns true
if the response status is between 200 and 399 inclusive.
Parameters:
Name | Type | Description |
---|---|---|
response | IncomingMessage | response from the Node.js `http` module |
Returns: boolean
<Static>
mergeHeaders
▸ mergeHeaders(dst: IncomingHttpHeaders
| OutgoingHttpHeaders
, src: IncomingHttpHeaders
| OutgoingHttpHeaders
, overwrite?: boolean
): IncomingHttpHeaders
Defined in HttpUtils.ts:65
Returns the result of merging the src
headers into the initial dst
headers.
Parameters:
Name | Type | Default value | Description | |
---|---|---|---|---|
dst | IncomingHttpHeaders \ | OutgoingHttpHeaders | - | the initial set of headers |
src | IncomingHttpHeaders \ | OutgoingHttpHeaders | - | the headers to be merged into the `dst` |
Default value overwrite | boolean | true | if `true`, headers in the `src` will overwrite existing headers in the `dst` |
Returns: IncomingHttpHeaders
a new object containing the results of the merge
<Static>
toBodyText
▸ toBodyText(response: IncomingMessage
): Promise
<string
>
Defined in HttpUtils.ts:27
Returns a Promise
that resolves to the text data contained in the response body.
Parameters:
Name | Type | Description |
---|---|---|
response | IncomingMessage | response from the Node.js `http` module |
Returns: Promise
<string
>
<Static>
toBuffer
▸ toBuffer(response: IncomingMessage
): Promise
<Buffer
>
Defined in HttpUtils.ts:40
Returns a Promise
that resolves to the raw data contained in the response body.
Parameters:
Name | Type | Description |
---|---|---|
response | IncomingMessage | response from the Node.js `http` module |
Returns: Promise
<Buffer
>
<Static>
toIncomingHttpHeaders
▸ toIncomingHttpHeaders(headers: IncomingHttpHeaders
| OutgoingHttpHeaders
): IncomingHttpHeaders
Defined in HttpUtils.ts:85
Converts a set of headers, either incoming or outgoing, to the incoming format used by the http
module in Node.js.
Parameters:
Name | Type | Description | |
---|---|---|---|
headers | IncomingHttpHeaders \ | OutgoingHttpHeaders | headers to be converted to the incoming format |
Returns: IncomingHttpHeaders