| 1 |
'use strict'; |
| 2 |
|
| 3 |
const Readable = require('stream').Readable; |
| 4 |
const lowercaseKeys = require('lowercase-keys'); |
| 5 |
|
| 6 |
class Response extends Readable { |
| 7 |
constructor(statusCode, headers, body, url) { |
| 8 |
if (typeof statusCode !== 'number') { |
| 9 |
throw new TypeError('Argument `statusCode` should be a number'); |
| 10 |
} |
| 11 |
if (typeof headers !== 'object') { |
| 12 |
throw new TypeError('Argument `headers` should be an object'); |
| 13 |
} |
| 14 |
if (!(body instanceof Buffer)) { |
| 15 |
throw new TypeError('Argument `body` should be a buffer'); |
| 16 |
} |
| 17 |
if (typeof url !== 'string') { |
| 18 |
throw new TypeError('Argument `url` should be a string'); |
| 19 |
} |
| 20 |
|
| 21 |
super(); |
| 22 |
this.statusCode = statusCode; |
| 23 |
this.headers = lowercaseKeys(headers); |
| 24 |
this.body = body; |
| 25 |
this.url = url; |
| 26 |
} |
| 27 |
|
| 28 |
_read() { |
| 29 |
this.push(this.body); |
| 30 |
this.push(null); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
module.exports = Response; |