UNPKG

@foxxie/centra

Version:

A fork of Centra to support shortcut methods in Foxxie, and with typescript support.

34 lines (25 loc) 767 B
import { IncomingMessage } from 'node:http'; import { ResOptions } from '../index'; export class CentraResponse { public coreRes: IncomingMessage; public headers: IncomingMessage['headers']; public statusCode: IncomingMessage['statusCode']; public body: Buffer | string; public resOptions: ResOptions; constructor(res: any, resOptions: ResOptions) { this.coreRes = res; this.resOptions = resOptions; this.body = Buffer.alloc(0); this.headers = res.headers; this.statusCode = res.statusCode; } _addChunk(chunk) { this.body = Buffer.concat([this.body, chunk]); } async json(): Promise<any> { return this.statusCode === 204 ? null : JSON.parse(this.body as string); } async text(): Promise<string> { return this.body.toString(); } }