Skip to content

SageHttpResponse

Type parameters

T = any

Constructors

new SageHttpResponse(props)

new SageHttpResponse<T>(props): SageHttpResponse<T>

Parameters

props: Omit<SageHttpResponse<any>, "get" | "headers" | "wrapHeaders"> & SageHttpResponseProps

Returns

SageHttpResponse<T>

Source

src/SageHttpResponse.ts:71

Properties

body

body: T

Beware that body will fall back to buffer if the response is a file or server has redirected the request. If you want to stream the file, the response promise implements NodeJS Readable, just don’t await it. The type includes “any” to ease the migration from supertest. If you stand against it, please open an issue here https://github.com/eddienubes/sagetest

Source

src/SageHttpResponse.ts:16


buffer

buffer: Buffer

Buffer representation of the body. Useful for file downloads.

Source

src/SageHttpResponse.ts:26


cookies

cookies: Record<string, CookieOptions>

Cookies sent by the server. Also, accessible from headers[‘set-cookie’]

Source

src/SageHttpResponse.ts:69


error

error: boolean

True if the status code is 400 or higher

Source

src/SageHttpResponse.ts:59


headers

headers: SageResponseHeaders

Contains the response headers. If the header is not present, it will be undefined. If header is present multiple times, the values are joined with a comma. It’s done for the sake of testing simplicity.

Source

src/SageHttpResponse.ts:44


location?

optional location: string

Location header. Defined only if redirect is true

Source

src/SageHttpResponse.ts:64


ok

ok: boolean

True if the status code falls in the range 200-299

Source

src/SageHttpResponse.ts:49


redirect

redirect: boolean

True if the status code is 301, 302, 303, 307, or 308

Source

src/SageHttpResponse.ts:54


status

status: number

Alias of statusCode

Source

src/SageHttpResponse.ts:32


statusCode

statusCode: number

Source

src/SageHttpResponse.ts:28


statusText

statusText: HttpStatusText

The mapping of status codes to status messages as defined in the HTTP/1.1 specification

Source

src/SageHttpResponse.ts:36


text

text: string

Text representation of the body. Be careful, sometimes buffer-string to string comparison is slow or unreliable in tests (jest/vitest)

Source

src/SageHttpResponse.ts:22

Methods

get()

get(header): null | string

Get the value of the header field. Multiple headers are joined with a comma. If the header is not present, it will return null.

Parameters

header: string

Returns

null | string

Source

src/SageHttpResponse.ts:87