Sha256: d3dd6a98537a07a7ad526487bc891f1de18b50cd1f2e21ce4e592f314cb80806

Contents?: true

Size: 861 Bytes

Versions: 24

Compression:

Stored size: 861 Bytes

Contents

import {Readable as ReadableStream} from 'node:stream';
import lowercaseKeys from 'lowercase-keys';

export default class Response extends ReadableStream {
	statusCode;
	headers;
	body;
	url;

	constructor({statusCode, headers, body, url}) {
		if (typeof statusCode !== 'number') {
			throw new TypeError('Argument `statusCode` should be a number');
		}

		if (typeof headers !== 'object') {
			throw new TypeError('Argument `headers` should be an object');
		}

		if (!(body instanceof Uint8Array)) {
			throw new TypeError('Argument `body` should be a buffer');
		}

		if (typeof url !== 'string') {
			throw new TypeError('Argument `url` should be a string');
		}

		super({
			read() {
				this.push(body);
				this.push(null);
			},
		});

		this.statusCode = statusCode;
		this.headers = lowercaseKeys(headers);
		this.body = body;
		this.url = url;
	}
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/responselike/index.js
immosquare-cleaner-0.1.50 node_modules/responselike/index.js
immosquare-cleaner-0.1.49 node_modules/responselike/index.js
immosquare-cleaner-0.1.48 node_modules/responselike/index.js
immosquare-cleaner-0.1.47 node_modules/responselike/index.js
immosquare-cleaner-0.1.46 node_modules/responselike/index.js
immosquare-cleaner-0.1.45 node_modules/responselike/index.js
immosquare-cleaner-0.1.44 node_modules/responselike/index.js
immosquare-cleaner-0.1.43 node_modules/responselike/index.js
immosquare-cleaner-0.1.42 node_modules/responselike/index.js
immosquare-cleaner-0.1.41 node_modules/responselike/index.js
immosquare-cleaner-0.1.40 node_modules/responselike/index.js
immosquare-cleaner-0.1.39 node_modules/responselike/index.js
immosquare-cleaner-0.1.38 node_modules/responselike/index.js
immosquare-cleaner-0.1.32 node_modules/responselike/index.js
immosquare-cleaner-0.1.31 node_modules/responselike/index.js
immosquare-cleaner-0.1.30 node_modules/responselike/index.js
immosquare-cleaner-0.1.29 node_modules/responselike/index.js
immosquare-cleaner-0.1.28 node_modules/responselike/index.js
immosquare-cleaner-0.1.27 node_modules/responselike/index.js