Cutwater

Cutwater

  • Docs
  • Help
  • GitHub

HttpUtils

@codification/cutwater-node-core > HttpUtils

Class

Utility for handling common HTTP related tasks.

beta:

Hierarchy

HttpUtils

Methods

  • isResponseOk
  • mergeHeaders
  • toBodyText
  • toBuffer
  • toIncomingHttpHeaders

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:

NameTypeDescription
responseIncomingMessageresponse 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:

NameTypeDefault valueDescription
dstIncomingHttpHeaders \OutgoingHttpHeaders-the initial set of headers
srcIncomingHttpHeaders \OutgoingHttpHeaders-the headers to be merged into the `dst`
Default value overwritebooleantrueif `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:

NameTypeDescription
responseIncomingMessageresponse 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:

NameTypeDescription
responseIncomingMessageresponse 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:

NameTypeDescription
headersIncomingHttpHeaders \OutgoingHttpHeadersheaders to be converted to the incoming format

Returns: IncomingHttpHeaders


  • Class
  • Hierarchy
    • Methods
  • Methods
    • `` isResponseOk
    • `` mergeHeaders
    • `` toBodyText
    • `` toBuffer
    • `` toIncomingHttpHeaders
Cutwater
Docs
Getting Started
Community
Stack Overflow
More
GitHubStar
Copyright © 2019 Codification.org