Comparing version 5.0.1 to 5.1.0
@@ -11,5 +11,5 @@ # How to contribute | ||
* Fork the repository on GitHub. | ||
* Fix the issue ensuring that your code follows the [style guide](https://github.com/hapijs/hapi/blob/master/docs/Style.md). | ||
* Fix the issue ensuring that your code follows the [style guide](https://github.com/hapijs/contrib/blob/master/Style.md). | ||
* Add tests for your new code ensuring that you have 100% code coverage (we can help you reach 100% but will not merge without it). | ||
* Run `make test-cov-html` to generate a report of test coverage | ||
* [Pull requests](http://help.github.com/send-pull-requests/) should be made to the [master branch](https://github.com/hapijs/wreck/tree/master). |
@@ -70,2 +70,6 @@ | ||
if (options.secureProtocol !== undefined) { | ||
uri.secureProtocol = options.secureProtocol; | ||
} | ||
var req = client.request(uri); | ||
@@ -231,2 +235,6 @@ | ||
if (buffer.length === 0) { | ||
return callback(null, null); | ||
} | ||
try { | ||
@@ -233,0 +241,0 @@ var json = JSON.parse(buffer.toString()); |
{ | ||
"name": "wreck", | ||
"description": "HTTP Client Utilities", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"repository": "git://github.com/hapijs/wreck", | ||
@@ -20,3 +20,4 @@ "main": "index", | ||
"devDependencies": { | ||
"lab": "4.x.x" | ||
"lab": "5.x.x", | ||
"code": "1.x.x" | ||
}, | ||
@@ -23,0 +24,0 @@ "scripts": { |
@@ -36,3 +36,4 @@ ![wreck Logo](https://raw.github.com/hapijs/wreck/master/images/wreck.png) | ||
downstreamRes: null, | ||
agent: null // Node Core http.Agent | ||
agent: null, // Node Core http.Agent | ||
secureProtocol: 'SSLv3_method' // The SSL method to use | ||
}; | ||
@@ -72,2 +73,5 @@ | ||
before aborting the request. Defaults to unlimited. | ||
- `secureProtocol` - [TLS](http://nodejs.org/api/tls.html) flag indicating the SSL method to use, e.g. `SSLv3_method` | ||
to force SSL version 3. The possible values depend on your installation of OpenSSL. Read the official OpenSSL docs | ||
for possible [SSL_METHODS](http://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_PROTOCOL_METHODS). | ||
- `callback` - The optional callback function using the signature `function (err, response)` where: | ||
@@ -194,2 +198,2 @@ - `err` - Any error that may have occurred during the handling of the request. | ||
Wreck.agents.http.maxSockets = 20; | ||
``` | ||
``` |
1723
test/index.js
@@ -9,2 +9,3 @@ // Load modules | ||
var Stream = require('stream'); | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
@@ -14,322 +15,295 @@ var Wreck = require('../'); | ||
// Declare internals | ||
var internals = {}; | ||
// Test shortcuts | ||
var lab = exports.lab = Lab.script(); | ||
var before = lab.before; | ||
var after = lab.after; | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Lab.expect; | ||
var expect = Code.expect; | ||
describe('Wreck', function () { | ||
var payload = new Array(1640).join('0123456789'); // make sure we have a payload larger than 16384 bytes for chunking coverage | ||
var payload = new Array(1640).join('0123456789'); // make sure we have a payload larger than 16384 bytes for chunking coverage | ||
describe('request()', function () { | ||
describe('#request', function () { | ||
it('requests a resource with callback', function (done) { | ||
it('requests a resource with callback', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests a POST resource', function (done) { | ||
it('requests a POST resource', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
expect(req.headers['content-length']).to.equal('16390'); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
expect(req.headers['content-length']).to.equal('16390'); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: payload }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: payload }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests a POST resource with unicode characters in payload', function (done) { | ||
it('requests a POST resource with unicode characters in payload', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
expect(req.headers['content-length']).to.equal('14'); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
expect(req.headers['content-length']).to.equal('14'); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var unicodePayload = JSON.stringify({ field: 'ć' }); | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: unicodePayload }, function (err, res) { | ||
var unicodePayload = JSON.stringify({ field: 'ć' }); | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: unicodePayload }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(unicodePayload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(unicodePayload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests a POST resource with headers', function (done) { | ||
it('requests a POST resource with headers', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { headers: { 'user-agent': 'wreck' }, payload: payload }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { headers: { 'user-agent': 'wreck' }, payload: payload }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests a POST resource with stream payload', function (done) { | ||
it('requests a POST resource with stream payload', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: Wreck.toReadableStream(payload) }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: Wreck.toReadableStream(payload) }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests a resource without callback', function (done) { | ||
it('requests a resource without callback', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}); | ||
}); | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}); | ||
}); | ||
}); | ||
it('cannot set agent and rejectUnauthorized at the same time', function (done) { | ||
it('cannot set agent and rejectUnauthorized at the same time', function (done) { | ||
var fn = function () { | ||
var fn = function () { | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: true, agent: new Https.Agent() }, function (err, res) {}); | ||
}; | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: true, agent: new Https.Agent() }, function (err, res) {}); | ||
}; | ||
expect(fn).to.throw(); | ||
done(); | ||
}); | ||
expect(fn).to.throw(); | ||
done(); | ||
}); | ||
it('cannot set a false agent and rejectUnauthorized at the same time', function (done) { | ||
it('cannot set a false agent and rejectUnauthorized at the same time', function (done) { | ||
var fn = function () { | ||
var fn = function () { | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: false, agent: false }, function (err, res) {}); | ||
}; | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: false, agent: false }, function (err, res) {}); | ||
}; | ||
expect(fn).to.throw(); | ||
done(); | ||
}); | ||
expect(fn).to.throw(); | ||
done(); | ||
}); | ||
it('can set a null agent and rejectUnauthorized at the same time', function (done) { | ||
it('can set a null agent and rejectUnauthorized at the same time', function (done) { | ||
var fn = function () { | ||
var fn = function () { | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: false, agent: null }, function (err, res) {}); | ||
}; | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: false, agent: null }, function (err, res) {}); | ||
}; | ||
expect(fn).to.not.throw(); | ||
done(); | ||
}); | ||
expect(fn).to.not.throw(); | ||
done(); | ||
}); | ||
it('requests an https resource', function (done) { | ||
it('requests an https resource', function (done) { | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: true }, function (err, res) { | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: true }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.contain('<HTML>'); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.contain('<HTML>'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('fails when an https resource has invalid certs and the default rejectUnauthorized', function (done) { | ||
it('requests an https resource with secure protocol set', function (done) { | ||
var httpsOptions = { | ||
key: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA0UqyXDCqWDKpoNQQK/fdr0OkG4gW6DUafxdufH9GmkX/zoKz\ng/SFLrPipzSGINKWtyMvo7mPjXqqVgE10LDI3VFV8IR6fnART+AF8CW5HMBPGt/s\nfQW4W4puvBHkBxWSW1EvbecgNEIS9hTGvHXkFzm4xJ2e9DHp2xoVAjREC73B7JbF\nhc5ZGGchKw+CFmAiNysU0DmBgQcac0eg2pWoT+YGmTeQj6sRXO67n2xy/hA1DuN6\nA4WBK3wM3O4BnTG0dNbWUEbe7yAbV5gEyq57GhJIeYxRvveVDaX90LoAqM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zqYYZEwmst36fJRRrVaFuAM/1DYAmT\nWMhU+yTfA+vCS4tql9b9zUhPw/IDHpBDWyR01spoZFBF/hE1MGNpCSXXsAbmCiVf\naxrIgR2DNketbDxkQx671KwF1+1JOMo9ffXp+OhuRo5NaGIxhTsZ+f/MA4y084Aj\nDI39av50sTRTWWShlN+J7PtdQVA5SZD97oYbeUeL7gI18kAJww9eUdmT0nEjcwKs\nxsQT1fyKbo7AlZBY4KSlUMuGnn0VnAsB9b+LxtXlDfnjyM8bVQx1uAfRo0DO8p/5\n3J5DTjAU55deBQ==\n-----END CERTIFICATE-----\n' | ||
}; | ||
Wreck.request('get', 'https://google.com', { rejectUnauthorized: true, secureProtocol: 'SSLv3_method' }, function (err, res) { | ||
var server = Https.createServer(httpsOptions, function (req, res) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
res.writeHead(200); | ||
res.end(); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.contain('<HTML>'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
server.listen(0, function (err) { | ||
it('fails when an https resource has invalid certs and the default rejectUnauthorized', function (done) { | ||
expect(err).to.not.exist; | ||
var httpsOptions = { | ||
key: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA0UqyXDCqWDKpoNQQK/fdr0OkG4gW6DUafxdufH9GmkX/zoKz\ng/SFLrPipzSGINKWtyMvo7mPjXqqVgE10LDI3VFV8IR6fnART+AF8CW5HMBPGt/s\nfQW4W4puvBHkBxWSW1EvbecgNEIS9hTGvHXkFzm4xJ2e9DHp2xoVAjREC73B7JbF\nhc5ZGGchKw+CFmAiNysU0DmBgQcac0eg2pWoT+YGmTeQj6sRXO67n2xy/hA1DuN6\nA4WBK3wM3O4BnTG0dNbWUEbe7yAbV5gEyq57GhJIeYxRvveVDaX90LoAqM4cUH06\n6rciON0UbDHV2LP/JaH5jzBjUyCnKLLo5snlbwIDAQABAoIBAQDJm7YC3pJJUcxb\nc8x8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E1MGNpCSXXsAbmCiVf\naxrIgR2DNketbDxkQx671KwF1+1JOMo9ffXp+OhuRo5NaGIxhTsZ+f/MA4y084Aj\nDI39av50sTRTWWShlN+J7PtdQVA5SZD97oYbeUeL7gI18kAJww9eUdmT0nEjcwKs\nxsQT1fyKbo7AlZBY4KSlUMuGnn0VnAsB9b+LxtXlDfnjyM8bVQx1uAfRo0DO8p/5\n3J5DTjAU55deBQ==\n-----END CERTIFICATE-----\n' | ||
}; | ||
Wreck.request('get', 'https://localhost:' + server.address().port, {}, function (err, res) { | ||
var server = Https.createServer(httpsOptions, function (req, res) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
}); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
it('succeeds when an https resource has unauthorized certs and rejectUnauthorized is false', function (done) { | ||
server.listen(0, function (err) { | ||
var httpsOptions = { | ||
key: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA0UqyXDCqWDKpoNQQK/fdr0OkG4gW6DUafxdufH9GmkX/zoKz\ng/SFLrPipzSGINKWtyMvo7mPjXqqVgE10LDI3VFV8IR6fnART+AF8CW5HMBPGt/s\nfQW4W4puvBHkBxWSW1EvbecgNEIS9hTGvHXkFzm4xJ2e9DHp2xoVAjREC73B7JbF\nhc5ZGGchKw+CFmAiNysU0DmBgQcac0eg2pWoT+YGmTeQj6sRXO67n2xy/hA1DuN6\nA4WBK3wM3O4BnTG0dNbWUEbe7yAbV5gEyq57GhJIeYxRvveVDaX90LoAqM4cUH06\n6rciON0UbDHV2LP/JaH5jzBjUyCnKLLo5snlbwIDAQABAoIBAQDJm7YC3pJJUcxb\nc8x8PlHbUkJUjxzZ5MW4Zb71yLkfRYzsxrTcyQA+g+QzA4KtPY8XrZpnkgm51M8e\n+B16AcIMiBxMC6HgCF503i16LyyJiKrrDYfGy2rTK6AOJQHO3TXWJ3eT3BAGpxuS\n12K2Cq6EvQLCy79iJm7Ks+5G6EggMZPfCVdEhffRm2Epl4T7Lp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b+LxtXlDfnjyM8bVQx1uAfRo0DO8p/5\n3J5DTjAU55deBQ==\n-----END CERTIFICATE-----\n' | ||
}; | ||
expect(err).to.not.exist(); | ||
var server = Https.createServer(httpsOptions, function (req, res) { | ||
Wreck.request('get', 'https://localhost:' + server.address().port, {}, function (err, res) { | ||
res.writeHead(200); | ||
res.end(); | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
server.listen(0, function (err) { | ||
it('succeeds when an https resource has unauthorized certs and rejectUnauthorized is false', function (done) { | ||
expect(err).to.not.exist; | ||
var httpsOptions = { | ||
key: '-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA0UqyXDCqWDKpoNQQK/fdr0OkG4gW6DUafxdufH9GmkX/zoKz\ng/SFLrPipzSGINKWtyMvo7mPjXqqVgE10LDI3VFV8IR6fnART+AF8CW5HMBPGt/s\nfQW4W4puvBHkBxWSW1EvbecgNEIS9hTGvHXkFzm4xJ2e9DHp2xoVAjREC73B7JbF\nhc5ZGGchKw+CFmAiNysU0DmBgQcac0eg2pWoT+YGmTeQj6sRXO67n2xy/hA1DuN6\nA4WBK3wM3O4BnTG0dNbWUEbe7yAbV5gEyq57GhJIeYxRvveVDaX90LoAqM4cUH06\n6rciON0UbDHV2LP/JaH5jzBjUyCnKLLo5snlbwIDAQABAoIBAQDJm7YC3pJJUcxb\nc8x8PlHbUkJUjxzZ5MW4Zb71yLkfRYzsxrTcyQA+g+QzA4KtPY8XrZpnkgm51M8e\n+B16AcIMiBxMC6HgCF503i16LyyJiKrrDYfGy2rTK6AOJQHO3TXWJ3eT3BAGpxuS\n12K2Cq6EvQLCy79iJm7Ks+5G6EggMZPfCVdEhffRm2Epl4T7LpIAqWiUDcDfS05n\nNNfAGxxvALPn+D+kzcSF6hpmCVrFVTf9ouhvnr+0DpIIVPwSK/REAF3Ux5SQvFuL\njPmh3bGwfRtcC5d21QNrHdoBVSN2UBLmbHUpBUcOBI8FyivAWJhRfKnhTvXMFG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ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0\ncyBQdHkgTHRkMB4XDTE0MDEyNTIxMjIxOFoXDTE1MDEyNTIxMjIxOFowRTELMAkG\nA1UEBhMCVVMxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0\nIFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\nANFKslwwqlgyqaDUECv33a9DpBuIFug1Gn8Xbnx/RppF/86Cs4P0hS6z4qc0hiDS\nlrcjL6O5j416qlYBNdCwyN1RVfCEen5wEU/gBfAluRzATxrf7H0FuFuKbrwR5AcV\nkltRL23nIDRCEvYUxrx15Bc5uMSdnvQx6dsaFQI0RAu9weyWxYXOWRhnISsPghZg\nIjcrFNA5gYEHGnNHoNqVqE/mBpk3kI+rEVzuu59scv4QNQ7jegOFgSt8DNzuAZ0x\ntHTW1lBG3u8gG1eYBMquexoSSHmMUb73lQ2l/dC6AKjOHFB9Ouq3IjjdFGwx1diz\n/yWh+Y8wY1Mgpyiy6ObJ5W8CAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAoSc6Skb4\ng1e0ZqPKXBV2qbx7hlqIyYpubCl1rDiEdVzqYYZEwmst36fJRRrVaFuAM/1DYAmT\nWMhU+yTfA+vCS4tql9b9zUhPw/IDHpBDWyR01spoZFBF/hE1MGNpCSXXsAbmCiVf\naxrIgR2DNketbDxkQx671KwF1+1JOMo9ffXp+OhuRo5NaGIxhTsZ+f/MA4y084Aj\nDI39av50sTRTWWShlN+J7PtdQVA5SZD97oYbeUeL7gI18kAJww9eUdmT0nEjcwKs\nxsQT1fyKbo7AlZBY4KSlUMuGnn0VnAsB9b+LxtXlDfnjyM8bVQx1uAfRo0DO8p/5\n3J5DTjAU55deBQ==\n-----END CERTIFICATE-----\n' | ||
}; | ||
Wreck.request('get', 'https://localhost:' + server.address().port, { rejectUnauthorized: false }, function (err, res) { | ||
var server = Https.createServer(httpsOptions, function (req, res) { | ||
expect(err).to.not.exist; | ||
done(); | ||
}); | ||
}); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
it('requests a resource with downstream dependency', function (done) { | ||
server.listen(0, function (err) { | ||
var up = Http.createServer(function (req, res) { | ||
expect(err).to.not.exist(); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
Wreck.request('get', 'https://localhost:' + server.address().port, { rejectUnauthorized: false }, function (err, res) { | ||
expect(err).to.not.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
up.listen(0, function () { | ||
it('requests a resource with downstream dependency', function (done) { | ||
var down = Http.createServer(function (req, res1) { | ||
var up = Http.createServer(function (req, res) { | ||
res1.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Wreck.request('get', 'http://localhost:' + up.address().port, { downstreamRes: res1 }, function (err, res2) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
}); | ||
expect(err).to.not.exist; | ||
res2.pipe(res1); | ||
}); | ||
}); | ||
up.listen(0, function () { | ||
down.listen(0, function () { | ||
var down = Http.createServer(function (req, res1) { | ||
Wreck.request('get', 'http://localhost:' + down.address().port, {}, function (err, res) { | ||
res1.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Wreck.request('get', 'http://localhost:' + up.address().port, { downstreamRes: res1 }, function (err, res2) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
up.close(); | ||
down.close(); | ||
done(); | ||
}); | ||
}); | ||
expect(err).to.not.exist(); | ||
res2.pipe(res1); | ||
}); | ||
}); | ||
}); | ||
it('does not follow redirections by default', function (done) { | ||
down.listen(0, function () { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('get', 'http://localhost:' + down.address().port, {}, function (err, res) { | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(301); | ||
server.close(); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
up.close(); | ||
down.close(); | ||
done(); | ||
@@ -340,85 +314,90 @@ }); | ||
}); | ||
}); | ||
it('handles redirections', function (done) { | ||
it('does not follow redirections by default', function (done) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(301); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('handles redirections with relative location', function (done) { | ||
it('handles redirections', function (done) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': '/' }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('reaches max redirections count', function (done) { | ||
it('handles redirections with relative location', function (done) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
if (gen++ < 2) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
if (!gen++) { | ||
res.writeHead(301, { 'Location': '/' }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
expect(err.message).to.equal('Maximum redirections reached'); | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
@@ -429,120 +408,135 @@ done(); | ||
}); | ||
}); | ||
it('handles malformed redirection response', function (done) { | ||
it('reaches max redirections count', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(301); | ||
if (gen++ < 2) { | ||
res.writeHead(301, { 'Location': 'http://localhost:' + server.address().port }); | ||
res.end(); | ||
}); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end(payload); | ||
} | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
expect(err.message).to.equal('Received redirection without location'); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err.message).to.equal('Maximum redirections reached'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('handles redirections with POST stream payload', function (done) { | ||
it('handles malformed redirection response', function (done) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
if (!gen++) { | ||
res.writeHead(307, { 'Location': '/' }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Wreck.read(req, null, function (err, res2) { | ||
res.writeHead(301); | ||
res.end(); | ||
}); | ||
res.end(res2); | ||
}); | ||
} | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { redirects: 1 }, function (err, res) { | ||
expect(err.message).to.equal('Received redirection without location'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
server.listen(0, function () { | ||
it('handles redirections with POST stream payload', function (done) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { redirects: 1, payload: Wreck.toReadableStream(payload) }, function (err, res) { | ||
var gen = 0; | ||
var server = Http.createServer(function (req, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
if (!gen++) { | ||
res.writeHead(307, { 'Location': '/' }); | ||
res.end(); | ||
} | ||
else { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
Wreck.read(req, null, function (err, res2) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
res.end(res2); | ||
}); | ||
}); | ||
} | ||
}); | ||
it('handles request errors with a boom response', function (done) { | ||
server.listen(0, function () { | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { redirects: 1, payload: Wreck.toReadableStream(payload) }, function (err, res) { | ||
req.destroy(); | ||
res.end(); | ||
}); | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
server.once('listening', function () { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
expect(err.code).to.equal('ECONNRESET'); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
server.listen(0); | ||
it('handles request errors with a boom response', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
req.destroy(); | ||
res.end(); | ||
}); | ||
it('handles request errors with a boom response when payload is being sent', function (done) { | ||
server.once('listening', function () { | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
req.destroy(); | ||
res.end(); | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
}); | ||
server.once('listening', function () { | ||
server.listen(0); | ||
}); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
it('handles request errors with a boom response when payload is being sent', function (done) { | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
server.listen(0); | ||
req.destroy(); | ||
res.end(); | ||
}); | ||
it('handles response errors with a boom response', function (done) { | ||
server.once('listening', function () { | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
res.destroy(); | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
}); | ||
server.once('listening', function () { | ||
server.listen(0); | ||
}); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
it('handles response errors with a boom response', function (done) { | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
server.listen(0); | ||
res.destroy(); | ||
}); | ||
it('handles errors when remote server is unavailable', function (done) { | ||
server.once('listening', function () { | ||
Wreck.request('get', 'http://127.0.0.1:10', { payload: '' }, function (err) { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '' }, function (err) { | ||
expect(err).to.exist; | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
@@ -552,173 +546,184 @@ }); | ||
it('handles a timeout during a socket close', function (done) { | ||
server.listen(0); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
it('handles errors when remote server is unavailable', function (done) { | ||
req.once('error', function () { }); | ||
res.once('error', function () { }); | ||
Wreck.request('get', 'http://127.0.0.1:10', { payload: '' }, function (err) { | ||
setTimeout(function () { | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
req.destroy(); | ||
}, 5); | ||
}); | ||
it('handles a timeout during a socket close', function (done) { | ||
server.once('error', function () { }); | ||
var server = Http.createServer(function (req, res) { | ||
server.once('listening', function () { | ||
req.once('error', function () { }); | ||
res.once('error', function () { }); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '', timeout: 5 }, function (err) { | ||
setTimeout(function () { | ||
expect(err).to.exist; | ||
server.close(); | ||
setTimeout(done, 5); | ||
}); | ||
}); | ||
server.listen(0); | ||
req.destroy(); | ||
}, 5); | ||
}); | ||
it('handles an error after a timeout', function (done) { | ||
server.once('error', function () { }); | ||
var server = Http.createServer(function (req, res) { | ||
server.once('listening', function () { | ||
req.once('error', function () { }); | ||
res.once('error', function () { }); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '', timeout: 5 }, function (err) { | ||
setTimeout(function () { | ||
expect(err).to.exist(); | ||
server.close(); | ||
res.socket.write('ERROR'); | ||
}, 5); | ||
setTimeout(done, 5); | ||
}); | ||
}); | ||
server.once('error', function () { }); | ||
server.listen(0); | ||
}); | ||
server.once('listening', function () { | ||
it('handles an error after a timeout', function (done) { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '', timeout: 5 }, function (err) { | ||
var server = Http.createServer(function (req, res) { | ||
expect(err).to.exist; | ||
server.close(); | ||
req.once('error', function () { }); | ||
res.once('error', function () { }); | ||
setTimeout(done, 5); | ||
}); | ||
}); | ||
setTimeout(function () { | ||
server.listen(0); | ||
res.socket.write('ERROR'); | ||
}, 5); | ||
}); | ||
it('allows request without a callback', function (done) { | ||
server.once('error', function () { }); | ||
var server = Http.createServer(function (req, res) { | ||
server.once('listening', function () { | ||
res.end('ok'); | ||
}); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port, { payload: '', timeout: 5 }, function (err) { | ||
server.once('listening', function () { | ||
expect(err).to.exist(); | ||
server.close(); | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port); | ||
done(); | ||
setTimeout(done, 5); | ||
}); | ||
}); | ||
server.listen(0); | ||
server.listen(0); | ||
}); | ||
it('allows request without a callback', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
res.end('ok'); | ||
}); | ||
it('requests can be aborted', function (done) { | ||
server.once('listening', function () { | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('get', 'http://127.0.0.1:' + server.address().port); | ||
done(); | ||
}); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
server.listen(0); | ||
}); | ||
server.listen(0, function () { | ||
it('requests can be aborted', function (done) { | ||
var req = Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err) { | ||
var server = Http.createServer(function (req, res) { | ||
expect(err).to.exist; | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
req.abort(); | ||
}); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
it('request shortcuts can be aborted', function (done) { | ||
server.listen(0, function () { | ||
var server = Http.createServer(function (req, res) { | ||
var req = Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err) { | ||
res.writeHead(200); | ||
res.end(); | ||
expect(err).to.exist(); | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
server.listen(0, function () { | ||
req.abort(); | ||
}); | ||
}); | ||
var req = Wreck.get('http://localhost:' + server.address().port, function (err) { | ||
it('request shortcuts can be aborted', function (done) { | ||
expect(err).to.exist; | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
req.abort(); | ||
}); | ||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
it('uses agent option', function (done) { | ||
server.listen(0, function () { | ||
var agent = new Http.Agent(); | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
var req = Wreck.get('http://localhost:' + server.address().port, function (err) { | ||
Wreck.request('get', 'http://localhost/', { agent: agent }, function (err, res) { | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
expect(err).to.exist(); | ||
expect(err.code).to.equal('ECONNRESET'); | ||
done(); | ||
}); | ||
req.abort(); | ||
}); | ||
}); | ||
it('pooling can be disabled by setting agent to false', function (done) { | ||
it('uses agent option', function (done) { | ||
var complete; | ||
var agent = new Http.Agent(); | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
var server = Http.createServer(function (req, res) { | ||
Wreck.request('get', 'http://localhost/', { agent: agent }, function (err, res) { | ||
res.writeHead(200); | ||
res.write('foo'); | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
done(); | ||
}); | ||
}); | ||
complete = complete || function () { | ||
it('pooling can be disabled by setting agent to false', function (done) { | ||
res.end(); | ||
}; | ||
}); | ||
var complete; | ||
server.listen(0, function () { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.write('foo'); | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { agent: false, timeout: 15 }, function (err, res) { | ||
complete = complete || function () { | ||
expect(err).to.not.exist; | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
res.end(); | ||
}; | ||
}); | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { agent: false, timeout: 15 }, function (err, innerRes) { | ||
server.listen(0, function () { | ||
expect(err).to.not.exist; | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { agent: false, timeout: 15 }, function (err, res) { | ||
complete(); | ||
expect(err).to.not.exist(); | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
Wreck.read(res, null, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { agent: false, timeout: 15 }, function (err, innerRes) { | ||
setTimeout(function () { | ||
expect(err).to.not.exist(); | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
done(); | ||
}, 100); | ||
}); | ||
complete(); | ||
Wreck.read(res, null, function () { | ||
setTimeout(function () { | ||
expect(Object.keys(Wreck.agents.http.sockets).length).to.equal(0); | ||
expect(Object.keys(Wreck.agents.http.requests).length).to.equal(0); | ||
done(); | ||
}, 100); | ||
}); | ||
@@ -728,147 +733,147 @@ }); | ||
}); | ||
}); | ||
it('requests payload in buffer', function (done) { | ||
it('requests payload in buffer', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var buf = new Buffer(payload, 'ascii'); | ||
var buf = new Buffer(payload, 'ascii'); | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: buf }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: buf }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(payload); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('requests head method', function (done) { | ||
it('requests head method', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
req.pipe(res); | ||
}); | ||
res.writeHead(200); | ||
req.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var buf = new Buffer(payload, 'ascii'); | ||
var buf = new Buffer(payload, 'ascii'); | ||
Wreck.request('head', 'http://localhost:' + server.address().port, { payload: null }, function (err, res) { | ||
Wreck.request('head', 'http://localhost:' + server.address().port, { payload: null }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(''); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(''); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('post null payload', function (done) { | ||
it('post null payload', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
res.statusCode = 500; | ||
res.end(); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
res.statusCode = 500; | ||
res.end(); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { headers: { connection: 'close' }, payload: null }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { headers: { connection: 'close' }, payload: null }, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, null, function (err, body) { | ||
expect(err).to.not.exist; | ||
expect(body.toString()).to.equal(''); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(body.toString()).to.equal(''); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('handles read timeout', function (done) { | ||
it('handles read timeout', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
setTimeout(function () { | ||
setTimeout(function () { | ||
res.writeHead(200); | ||
res.write(payload); | ||
res.end(); | ||
}, 2000); | ||
}); | ||
res.writeHead(200); | ||
res.write(payload); | ||
res.end(); | ||
}, 2000); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 100 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 100 }, function (err, res) { | ||
expect(err).to.exist; | ||
expect(err.output.statusCode).to.equal(504); | ||
done(); | ||
}); | ||
expect(err).to.exist(); | ||
expect(err.output.statusCode).to.equal(504); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('cleans socket on agent deferred read timeout', function (done) { | ||
it('cleans socket on agent deferred read timeout', function (done) { | ||
var complete; | ||
var complete; | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.write('foo'); | ||
res.writeHead(200); | ||
res.write('foo'); | ||
complete = complete || function () { | ||
complete = complete || function () { | ||
res.end(); | ||
}; | ||
}); | ||
res.end(); | ||
}; | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var agent = new Http.Agent({ maxSockets: 1 }); | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
var agent = new Http.Agent({ maxSockets: 1 }); | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { agent: agent, timeout: 15 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { agent: agent, timeout: 15 }, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
expect(Object.keys(agent.requests).length).to.equal(0); | ||
expect(err).to.not.exist(); | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
expect(Object.keys(agent.requests).length).to.equal(0); | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { agent: agent, timeout: 15 }, function (err, innerRes) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { agent: agent, timeout: 15 }, function (err, innerRes) { | ||
expect(err).to.exist; | ||
expect(err.output.statusCode).to.equal(504); | ||
expect(err).to.exist(); | ||
expect(err.output.statusCode).to.equal(504); | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
expect(Object.keys(agent.requests).length).to.equal(1); | ||
expect(Object.keys(agent.sockets).length).to.equal(1); | ||
expect(Object.keys(agent.requests).length).to.equal(1); | ||
complete(); | ||
complete(); | ||
Wreck.read(res, null, function () { | ||
Wreck.read(res, null, function () { | ||
setTimeout(function () { | ||
setTimeout(function () { | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
expect(Object.keys(agent.requests).length).to.equal(0); | ||
expect(Object.keys(agent.sockets).length).to.equal(0); | ||
expect(Object.keys(agent.requests).length).to.equal(0); | ||
done(); | ||
}, 100); | ||
}); | ||
done(); | ||
}, 100); | ||
}); | ||
@@ -878,59 +883,59 @@ }); | ||
}); | ||
}); | ||
it('defaults maxSockets to Infinity', function (done) { | ||
it('defaults maxSockets to Infinity', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.write(payload); | ||
res.end(); | ||
}); | ||
res.writeHead(200); | ||
res.write(payload); | ||
res.end(); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 100 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 100 }, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(Wreck.agents.http.maxSockets).to.equal(Infinity); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(Wreck.agents.http.maxSockets).to.equal(Infinity); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('maxSockets on default agents can be changed', function (done) { | ||
it('maxSockets on default agents can be changed', function (done) { | ||
var complete; | ||
var complete; | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.write('foo'); | ||
res.writeHead(200); | ||
res.write('foo'); | ||
complete = complete || function () { | ||
complete = complete || function () { | ||
res.end(); | ||
}; | ||
}); | ||
res.end(); | ||
}; | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.agents.http.maxSockets = 1; | ||
Wreck.agents.http.maxSockets = 1; | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 15 }, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, { timeout: 15 }, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { timeout: 15 }, function (err, innerRes) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port + '/thatone', { timeout: 15 }, function (err, innerRes) { | ||
expect(err).to.exist; | ||
expect(err.output.statusCode).to.equal(504); | ||
expect(err).to.exist(); | ||
expect(err.output.statusCode).to.equal(504); | ||
complete(); | ||
complete(); | ||
Wreck.read(res, null, function () { | ||
Wreck.read(res, null, function () { | ||
Wreck.agents.http.maxSockets = Infinity; | ||
done(); | ||
}); | ||
Wreck.agents.http.maxSockets = Infinity; | ||
done(); | ||
}); | ||
@@ -941,437 +946,437 @@ }); | ||
}); | ||
}); | ||
describe('#read', function () { | ||
describe('read()', function () { | ||
it('handles errors with a boom response', function (done) { | ||
it('handles errors with a boom response', function (done) { | ||
var res = new Events.EventEmitter(); | ||
res.pipe = function () { }; | ||
var res = new Events.EventEmitter(); | ||
res.pipe = function () { }; | ||
Wreck.read(res, null, function (err) { | ||
Wreck.read(res, null, function (err) { | ||
expect(err.isBoom).to.equal(true); | ||
done(); | ||
}); | ||
res.emit('error', new Error('my error')); | ||
expect(err.isBoom).to.equal(true); | ||
done(); | ||
}); | ||
it('handles responses that close early', function (done) { | ||
res.emit('error', new Error('my error')); | ||
}); | ||
var res = new Events.EventEmitter(); | ||
res.pipe = function () { }; | ||
it('handles responses that close early', function (done) { | ||
Wreck.read(res, null, function (err) { | ||
var res = new Events.EventEmitter(); | ||
res.pipe = function () { }; | ||
expect(err.isBoom).to.equal(true); | ||
done(); | ||
}); | ||
Wreck.read(res, null, function (err) { | ||
res.emit('close'); | ||
expect(err.isBoom).to.equal(true); | ||
done(); | ||
}); | ||
it('times out when stream read takes too long', function (done) { | ||
res.emit('close'); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
it('times out when stream read takes too long', function (done) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.write(payload); | ||
}); | ||
var server = Http.createServer(function (req, res) { | ||
server.listen(0, function () { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.write(payload); | ||
}); | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
server.listen(0, function () { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, { timeout: 100 }, function (err, body) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.exist; | ||
expect(err.output.statusCode).to.equal(408); | ||
expect(body).to.not.exist; | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, { timeout: 100 }, function (err, body) { | ||
expect(err).to.exist(); | ||
expect(err.output.statusCode).to.equal(408); | ||
expect(body).to.not.exist(); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('errors when stream is too big', function (done) { | ||
it('errors when stream is too big', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.write(payload); | ||
res.end(payload); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.write(payload); | ||
res.end(payload); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist; | ||
Wreck.read(res, { maxBytes: 120 }, function (err, body) { | ||
expect(err).to.not.exist(); | ||
Wreck.read(res, { maxBytes: 120 }, function (err, body) { | ||
expect(err).to.exist; | ||
expect(err.output.statusCode).to.equal(400); | ||
expect(body).to.not.exist; | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.exist(); | ||
expect(err.output.statusCode).to.equal(400); | ||
expect(body).to.not.exist(); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('reads a file streamed via HTTP', function (done) { | ||
it('reads a file streamed via HTTP', function (done) { | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var fileStream = Fs.createReadStream(path); | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var fileStream = Fs.createReadStream(path); | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
fileStream.pipe(res); | ||
}); | ||
res.writeHead(200); | ||
fileStream.pipe(res); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
Wreck.read(res, null, function (err, body) { | ||
Wreck.read(res, null, function (err, body) { | ||
expect(body.length).to.equal(stats.size); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(body.length).to.equal(stats.size); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('reads a multiple buffers response', function (done) { | ||
it('reads a multiple buffers response', function (done) { | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var file = Fs.readFileSync(path); | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var file = Fs.readFileSync(path); | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.writeHead(200); | ||
res.write(file); | ||
setTimeout(function () { | ||
res.write(file); | ||
setTimeout(function () { | ||
res.end(); | ||
}, 100); | ||
}); | ||
res.write(file); | ||
res.end(); | ||
}, 100); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
Wreck.request('get', 'http://localhost:' + server.address().port, {}, function (err, res) { | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
Wreck.read(res, null, function (err, body) { | ||
Wreck.read(res, null, function (err, body) { | ||
expect(body.length).to.equal(stats.size * 2); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(body.length).to.equal(stats.size * 2); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('writes a file streamed via HTTP', function (done) { | ||
it('writes a file streamed via HTTP', function (done) { | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var fileStream = Fs.createReadStream(path); | ||
var path = Path.join(__dirname, '../images/wreck.png'); | ||
var stats = Fs.statSync(path); | ||
var fileStream = Fs.createReadStream(path); | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.writeHead(200); | ||
Wreck.read(req, null, function (err, body) { | ||
Wreck.read(req, null, function (err, body) { | ||
res.end(body); | ||
}); | ||
res.end(body); | ||
}); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: fileStream }, function (err, res) { | ||
Wreck.request('post', 'http://localhost:' + server.address().port, { payload: fileStream }, function (err, res) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
Wreck.read(res, null, function (err, body) { | ||
Wreck.read(res, null, function (err, body) { | ||
expect(body.length).to.equal(stats.size); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(body.length).to.equal(stats.size); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('handles responses with no headers', function (done) { | ||
it('handles responses with no headers', function (done) { | ||
var res = Wreck.toReadableStream(payload); | ||
Wreck.read(res, { json: true }, function (err) { | ||
var res = Wreck.toReadableStream(payload); | ||
Wreck.read(res, { json: true }, function (err) { | ||
expect(err).to.equal(null); | ||
done(); | ||
}); | ||
expect(err).to.equal(null); | ||
done(); | ||
}); | ||
}); | ||
describe('#parseCacheControl', function () { | ||
}); | ||
it('parses valid header', function (done) { | ||
describe('parseCacheControl()', function () { | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age=3600'); | ||
expect(header).to.exist; | ||
expect(header['must-revalidate']).to.equal(true); | ||
expect(header['max-age']).to.equal(3600); | ||
done(); | ||
}); | ||
it('parses valid header', function (done) { | ||
it('parses valid header with quoted string', function (done) { | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age=3600'); | ||
expect(header).to.exist(); | ||
expect(header['must-revalidate']).to.equal(true); | ||
expect(header['max-age']).to.equal(3600); | ||
done(); | ||
}); | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age="3600"'); | ||
expect(header).to.exist; | ||
expect(header['must-revalidate']).to.equal(true); | ||
expect(header['max-age']).to.equal(3600); | ||
done(); | ||
}); | ||
it('parses valid header with quoted string', function (done) { | ||
it('errors on invalid header', function (done) { | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age="3600"'); | ||
expect(header).to.exist(); | ||
expect(header['must-revalidate']).to.equal(true); | ||
expect(header['max-age']).to.equal(3600); | ||
done(); | ||
}); | ||
var header = Wreck.parseCacheControl('must-revalidate, b =3600'); | ||
expect(header).to.not.exist; | ||
done(); | ||
}); | ||
it('errors on invalid header', function (done) { | ||
it('errors on invalid max-age', function (done) { | ||
var header = Wreck.parseCacheControl('must-revalidate, b =3600'); | ||
expect(header).to.not.exist(); | ||
done(); | ||
}); | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age=a3600'); | ||
expect(header).to.not.exist; | ||
done(); | ||
}); | ||
it('errors on invalid max-age', function (done) { | ||
var header = Wreck.parseCacheControl('must-revalidate, max-age=a3600'); | ||
expect(header).to.not.exist(); | ||
done(); | ||
}); | ||
}); | ||
describe('Shortcut', function () { | ||
describe('Shortcut', function () { | ||
it('get request', function (done) { | ||
it('get request', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.get('http://localhost:' + server.address().port, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + server.address().port, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('post request', function (done) { | ||
it('post request', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.post('http://localhost:' + server.address().port, { payload: '123' }, function (err, res, payload) { | ||
Wreck.post('http://localhost:' + server.address().port, { payload: '123' }, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('put request', function (done) { | ||
it('put request', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.put('http://localhost:' + server.address().port, function (err, res, payload) { | ||
Wreck.put('http://localhost:' + server.address().port, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('delete request', function (done) { | ||
it('delete request', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
Wreck.delete('http://localhost:' + server.address().port, function (err, res, payload) { | ||
Wreck.delete('http://localhost:' + server.address().port, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.equal('ok'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('errors on bad request', function (done) { | ||
it('errors on bad request', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var port = server.address().port; | ||
server.close(); | ||
var port = server.address().port; | ||
server.close(); | ||
Wreck.get('http://localhost:' + port, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + port, function (err, res, payload) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
expect(err).to.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('json', function () { | ||
describe('json', function () { | ||
it('json requested and received', function (done) { | ||
it('json requested and received', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end(JSON.stringify({ foo: 'bar' })); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end(JSON.stringify({ foo: 'bar' })); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
expect(payload.foo).to.exist; | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
expect(payload.foo).to.exist(); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('json requested but not received - flag is ignored', function (done) { | ||
it('json requested but not received - flag is ignored', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('invalid json received', function (done) { | ||
it('invalid json received', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end('ok'); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end('ok'); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
expect(err).to.exist; | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.exist(); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('json not requested but received as string', function (done) { | ||
it('json not requested but received as string', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var server = Http.createServer(function (req, res) { | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end(JSON.stringify({ foo: 'bar' })); | ||
}); | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
res.end(JSON.stringify({ foo: 'bar' })); | ||
}); | ||
server.listen(0, function () { | ||
server.listen(0, function () { | ||
var port = server.address().port; | ||
var options = { | ||
json: false | ||
}; | ||
var port = server.address().port; | ||
var options = { | ||
json: false | ||
}; | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
expect(err).to.not.exist; | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
server.close(); | ||
done(); | ||
}); | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(200); | ||
expect(payload).to.not.equal(null); | ||
server.close(); | ||
done(); | ||
}); | ||
@@ -1381,44 +1386,70 @@ }); | ||
describe('#toReadableStream', function () { | ||
it('should not be parsed on empty buffer', function (done) { | ||
it('handle empty payload', function (done) { | ||
var server = Http.createServer(function (req, res) { | ||
var stream = Wreck.toReadableStream(); | ||
expect(stream instanceof Stream).to.be.true; | ||
var read = stream.read(); // Make sure read has no problems | ||
expect(read).to.be.null; | ||
done(); | ||
res.writeHead(204, { 'Content-Type': 'application/json' }); | ||
res.end(); | ||
}); | ||
it('handle explicit encoding', function (done) { | ||
server.listen(0, function () { | ||
var data = 'Hello'; | ||
var buf = new Buffer(data, 'ascii'); | ||
var stream = Wreck.toReadableStream(data, 'ascii'); | ||
expect(stream instanceof Stream).to.be.true; | ||
var read = stream.read(); | ||
expect(read.toString()).to.equal(data); | ||
done(); | ||
var port = server.address().port; | ||
var options = { | ||
json: true | ||
}; | ||
Wreck.get('http://localhost:' + port, options, function (err, res, payload) { | ||
expect(err).to.not.exist(); | ||
expect(res.statusCode).to.equal(204); | ||
expect(payload).to.equal(null); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('chunks to requested size', function (done) { | ||
var buf; | ||
var data = new Array(101).join('0123456789'); | ||
var stream = Wreck.toReadableStream(data); | ||
describe('toReadableStream()', function () { | ||
buf = stream.read(100); | ||
expect(buf.length).to.equal(100); | ||
it('handle empty payload', function (done) { | ||
buf = stream.read(400); | ||
expect(buf.length).to.equal(400); | ||
var stream = Wreck.toReadableStream(); | ||
expect(stream instanceof Stream).to.be.true; | ||
var read = stream.read(); // Make sure read has no problems | ||
expect(read).to.be.null; | ||
done(); | ||
}); | ||
buf = stream.read(); | ||
expect(buf.length).to.equal(500); | ||
it('handle explicit encoding', function (done) { | ||
buf = stream.read(); | ||
expect(buf).to.equal(null); | ||
var data = 'Hello'; | ||
var buf = new Buffer(data, 'ascii'); | ||
var stream = Wreck.toReadableStream(data, 'ascii'); | ||
expect(stream instanceof Stream).to.be.true; | ||
var read = stream.read(); | ||
expect(read.toString()).to.equal(data); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
it('chunks to requested size', function (done) { | ||
var buf; | ||
var data = new Array(101).join('0123456789'); | ||
var stream = Wreck.toReadableStream(data); | ||
buf = stream.read(100); | ||
expect(buf.length).to.equal(100); | ||
buf = stream.read(400); | ||
expect(buf.length).to.equal(400); | ||
buf = stream.read(); | ||
expect(buf.length).to.equal(500); | ||
buf = stream.read(); | ||
expect(buf).to.equal(null); | ||
done(); | ||
}); | ||
}); |
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
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
1354
197
102107
2
14