diff options
| author | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
| commit | f9159ea2d994e14180fb02ab562f0119513e67cf (patch) | |
| tree | 09d14cdf05456567156738b681379d4bccd64e5c /node_modules/http-response-object/index.js | |
| parent | 2020/04/03, 02:42, V1.2.1 (diff) | |
| download | s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip | |
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/http-response-object/index.js')
| -rw-r--r-- | node_modules/http-response-object/index.js | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/node_modules/http-response-object/index.js b/node_modules/http-response-object/index.js deleted file mode 100644 index 70542d4..0000000 --- a/node_modules/http-response-object/index.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -module.exports = Response; - -/** - * A response from a web request - * - * @param {Number} statusCode - * @param {Object} headers - * @param {Buffer} body - * @param {String} url - */ -function Response(statusCode, headers, body, url) { - if (typeof statusCode !== 'number') { - throw new TypeError('statusCode must be a number but was ' + (typeof statusCode)); - } - if (headers === null) { - throw new TypeError('headers cannot be null'); - } - if (typeof headers !== 'object') { - throw new TypeError('headers must be an object but was ' + (typeof headers)); - } - this.statusCode = statusCode; - this.headers = {}; - for (var key in headers) { - this.headers[key.toLowerCase()] = headers[key]; - } - this.body = body; - this.url = url; -} - -Response.prototype.getBody = function (encoding) { - if (this.statusCode >= 300) { - var err = new Error('Server responded with status code ' - + this.statusCode + ':\n' + this.body.toString()); - err.statusCode = this.statusCode; - err.headers = this.headers; - err.body = this.body; - err.url = this.url; - throw err; - } - return encoding ? this.body.toString(encoding) : this.body; -}; |