summaryrefslogtreecommitdiff
path: root/node_modules/http-response-object
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/http-response-object')
-rw-r--r--node_modules/http-response-object/.npmignore13
-rw-r--r--node_modules/http-response-object/.travis.yml3
-rw-r--r--node_modules/http-response-object/LICENSE19
-rw-r--r--node_modules/http-response-object/README.md44
-rw-r--r--node_modules/http-response-object/index.js43
-rw-r--r--node_modules/http-response-object/package.json53
-rw-r--r--node_modules/http-response-object/test/index.js37
7 files changed, 212 insertions, 0 deletions
diff --git a/node_modules/http-response-object/.npmignore b/node_modules/http-response-object/.npmignore
new file mode 100644
index 0000000..b83202d
--- /dev/null
+++ b/node_modules/http-response-object/.npmignore
@@ -0,0 +1,13 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+pids
+logs
+results
+npm-debug.log
+node_modules
diff --git a/node_modules/http-response-object/.travis.yml b/node_modules/http-response-object/.travis.yml
new file mode 100644
index 0000000..6e5919d
--- /dev/null
+++ b/node_modules/http-response-object/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - "0.10"
diff --git a/node_modules/http-response-object/LICENSE b/node_modules/http-response-object/LICENSE
new file mode 100644
index 0000000..27cc9f3
--- /dev/null
+++ b/node_modules/http-response-object/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2014 Forbes Lindesay
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/node_modules/http-response-object/README.md b/node_modules/http-response-object/README.md
new file mode 100644
index 0000000..7b1ad2a
--- /dev/null
+++ b/node_modules/http-response-object/README.md
@@ -0,0 +1,44 @@
+# http-response-object
+
+A simple object to represent an http response
+
+[![Build Status](https://img.shields.io/travis/ForbesLindesay/http-response-object/master.svg)](https://travis-ci.org/ForbesLindesay/http-response-object)
+[![Dependency Status](https://img.shields.io/gemnasium/ForbesLindesay/http-response-object.svg)](https://gemnasium.com/ForbesLindesay/http-response-object)
+[![NPM version](https://img.shields.io/npm/v/http-response-object.svg)](https://www.npmjs.org/package/http-response-object)
+
+
+## Installation
+
+ npm install http-response-object
+
+## Usage
+
+```js
+var Response = require('http-response-object');
+var res = new Response(200, {}, new Buffer('A ok'), 'http://example.com');
+//res.statusCode === 200
+//res.headers === {}
+//res.body === new Buffer('A ok')
+//res.url === 'http://example.com'
+res.getBody();
+// => new Buffer('A ok')
+
+var res = new Response(404, {'Header': 'value'}, new Buffer('Wheres this page'), 'http://example.com');
+//res.statusCode === 404
+//res.headers === {header: 'value'}
+//res.body === new Buffer('Wheres this page')
+//res.url === 'http://example.com'
+res.getBody();
+// => throws error with `statusCode`, `headers`, `body` and `url` properties copied from the response
+```
+
+## Properties
+
+ - `statusCode`: Number - the status code of the response
+ - `headers`: Object - the headers of the response. The keys are automatically made lower case.
+ - `body`: Buffer | String - the body of the response. Should be a buffer on the server side, but may be a simple string for lighter weight clients.
+ - `url`: String - the url that was requested. If there were redirects, this should be the last url to get requested.
+
+## License
+
+ MIT
diff --git a/node_modules/http-response-object/index.js b/node_modules/http-response-object/index.js
new file mode 100644
index 0000000..70542d4
--- /dev/null
+++ b/node_modules/http-response-object/index.js
@@ -0,0 +1,43 @@
+'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;
+};
diff --git a/node_modules/http-response-object/package.json b/node_modules/http-response-object/package.json
new file mode 100644
index 0000000..d3e2c6e
--- /dev/null
+++ b/node_modules/http-response-object/package.json
@@ -0,0 +1,53 @@
+{
+ "_from": "http-response-object@^1.0.1",
+ "_id": "[email protected]",
+ "_inBundle": false,
+ "_integrity": "sha1-p8TnWq6C87tJBOT0P2FWc7TVGMM=",
+ "_location": "/http-response-object",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "http-response-object@^1.0.1",
+ "name": "http-response-object",
+ "escapedName": "http-response-object",
+ "rawSpec": "^1.0.1",
+ "saveSpec": null,
+ "fetchSpec": "^1.0.1"
+ },
+ "_requiredBy": [
+ "/http-basic",
+ "/sync-request",
+ "/then-request"
+ ],
+ "_resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-1.1.0.tgz",
+ "_shasum": "a7c4e75aae82f3bb4904e4f43f615673b4d518c3",
+ "_spec": "http-response-object@^1.0.1",
+ "_where": "E:\\Documents\\GitHub\\s5nical\\node_modules\\sync-request",
+ "author": {
+ "name": "ForbesLindesay"
+ },
+ "bugs": {
+ "url": "https://github.com/ForbesLindesay/http-response-object/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "A simple object to represent an http response",
+ "homepage": "https://github.com/ForbesLindesay/http-response-object#readme",
+ "keywords": [
+ "http",
+ "https",
+ "response",
+ "request"
+ ],
+ "license": "MIT",
+ "name": "http-response-object",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/ForbesLindesay/http-response-object.git"
+ },
+ "scripts": {
+ "test": "node test"
+ },
+ "version": "1.1.0"
+}
diff --git a/node_modules/http-response-object/test/index.js b/node_modules/http-response-object/test/index.js
new file mode 100644
index 0000000..0ff4e16
--- /dev/null
+++ b/node_modules/http-response-object/test/index.js
@@ -0,0 +1,37 @@
+'use strict';
+
+var assert = require('assert');
+var Response = require('../');
+
+var res = new Response(200, {
+ 'Foo-Bar': 'baz-Bosh',
+ 'bar-foo': 'bish-Bosh'
+}, 'foo bar baz', 'http://example.com');
+assert(res.statusCode = 200);
+assert(res.headers['foo-bar'] === 'baz-Bosh');
+assert(res.headers['bar-foo'] === 'bish-Bosh');
+assert(res.body === 'foo bar baz');
+assert(res.url === 'http://example.com');
+assert(res.getBody() === 'foo bar baz');
+
+res = new Response(404, {
+ 'Foo-Bar': 'baz-Bosh'
+}, 'Could not find page', 'http://example.com');
+assert(res.statusCode = 404);
+assert(res.headers['foo-bar'] === 'baz-Bosh');
+assert(res.body === 'Could not find page');
+assert(res.url === 'http://example.com');
+var errored = false;
+try {
+ res.getBody();
+} catch (ex) {
+ assert(ex.statusCode === 404);
+ assert(ex.headers['foo-bar'] === 'baz-Bosh');
+ assert(ex.body === 'Could not find page');
+ assert(ex.url === 'http://example.com');
+ errored = true;
+}
+if (!errored) {
+ throw new Error('res.getBody() should throw an error when the status code is 404');
+}
+console.log('tests passed');