then-request
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -0,0 +0,0 @@ 'use strict'; |
14
index.js
'use strict'; | ||
var assert = require('assert'); | ||
var parseUrl = require('url').parse; | ||
@@ -50,13 +49,6 @@ var Promise = require('promise'); | ||
var body = options.body ? options.body : new Buffer(0); | ||
if (typeof body === 'string') body = new Buffer(body); | ||
assert(Buffer.isBuffer(body), 'body should be a Buffer or a String'); | ||
if (!Object.keys(options.headers).some(function (name) { return name.toLowerCase() === 'content-length'; })) { | ||
options.headers['content-length'] = body.length; | ||
} | ||
var req = module.exports._request(method, url, { | ||
headers: options.headers, | ||
followRedirects: options.followRedirects !== false, | ||
gzip: options.gzip !== false, | ||
followRedirects: true, | ||
gzip: true, | ||
cache: options.cache | ||
@@ -72,3 +64,3 @@ }, function (err, res) { | ||
if (req) { | ||
req.end(body); | ||
req.end(options.body ? options.body : new Buffer(0)); | ||
} | ||
@@ -75,0 +67,0 @@ }); |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "then-request", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "A request library that returns promises, inspired by request", | ||
@@ -8,11 +8,11 @@ "keywords": [], | ||
"dependencies": { | ||
"promise": "^6.0.1", | ||
"concat-stream": "^1.4.7", | ||
"qs": "^2.3.3", | ||
"promise": "^5.0.0", | ||
"concat-stream": "^1.4.6", | ||
"qs": "^1.1.0", | ||
"http-response-object": "^1.0.1", | ||
"http-basic": "^1.1.1" | ||
"http-basic": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"testit": "^1.2.0", | ||
"istanbul": "^0.3.5" | ||
"istanbul": "^0.3.0" | ||
}, | ||
@@ -28,2 +28,2 @@ "scripts": { | ||
"license": "MIT" | ||
} | ||
} |
@@ -40,8 +40,6 @@ # then-request | ||
- `cache` - only used in node.js (browsers already have their own caches) Can be `'memory'`, `'file'` or your own custom implementaton (see https://github.com/ForbesLindesay/http-basic#implementing-a-cache). | ||
- `followRedirects` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request following redirects automatically. | ||
- `gzip` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request automatically supporting the gzip encoding on responses. | ||
**Callback / Returns:** | ||
If a callback is provided it is called with `err` and `res`. If no callback is provided, a [Promise](https://www.promisejs.org/) is returned that eventually resolves to `res`. The resulting Promise also has an additional `.getBody(encoding?)` method that is equivallent to calling `.then(function (res) { return res.getBody(encoding?); })`. | ||
If a callback is provided it is called with `err` and `res`. If no callback is provided, a [Promise](https://www.promisejs.org/) is returned that eventually resolves to `res`. The resulting Promise also has an additional `.getBody(encoding?)` method that is equivallent to calling `.then(function (res) { return res.getBody(); })`. | ||
@@ -48,0 +46,0 @@ ### Response |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var test = require('testit'); | ||
var Promise = require('promise'); | ||
@@ -11,4 +10,2 @@ test('./lib/handle-qs.js', function () { | ||
assert(handleQs('http://example.com/', {}) === 'http://example.com/'); | ||
assert(handleQs('http://example.com/?foo=bar', {}) === 'http://example.com/?foo=bar'); | ||
assert(handleQs('http://example.com/', {foo: 'bar'}) === 'http://example.com/?foo=bar'); | ||
@@ -75,26 +72,4 @@ assert(handleQs('http://example.com/', {foo: {bar: 'baz'}}) === 'http://example.com/?foo%5Bbar%5D=baz'); | ||
}); | ||
test(env + ' - Callbacks', function () { | ||
return new Promise(function (resolve, reject) { | ||
return request('GET', 'http://example.com', function (err, res) { | ||
if (err) return reject(err); | ||
assert(res.statusCode === 200); | ||
assert(res.headers['foo'] === 'bar'); | ||
assert(res.body.toString() === 'body'); | ||
resolve(null); | ||
}); | ||
}); | ||
}); | ||
test(env + ' - Callbacks', function () { | ||
return new Promise(function (resolve, reject) { | ||
return request('GET', 'http://example.com', {}, function (err, res) { | ||
if (err) return reject(err); | ||
assert(res.statusCode === 200); | ||
assert(res.headers['foo'] === 'bar'); | ||
assert(res.body.toString() === 'body'); | ||
resolve(null); | ||
}); | ||
}); | ||
}); | ||
} | ||
testEnv('browser'); | ||
testEnv('server'); |
@@ -0,0 +0,0 @@ 'use strict'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15138
12
304
1
71
+ Addedcaseless@0.11.0(transitive)
+ Addedhttp-basic@2.5.1(transitive)
+ Addedpromise@5.0.0(transitive)
+ Addedqs@1.2.2(transitive)
- Removedhttp-basic@1.1.1(transitive)
- Removedpromise@6.1.0(transitive)
- Removedqs@2.4.2(transitive)
Updatedconcat-stream@^1.4.6
Updatedhttp-basic@^2.0.0
Updatedpromise@^5.0.0
Updatedqs@^1.1.0