Instead of "stream-to-array". Makes tests a bit shorter as well.
This commit is contained in:
Nathan Rajlich 2015-07-07 12:09:41 -07:00
Родитель 138a3728a1
Коммит a5683abb18
3 изменённых файлов: 14 добавлений и 26 удалений

Просмотреть файл

@ -31,7 +31,7 @@ var HttpProxyAgent = require('http-proxy-agent');
var HttpsProxyAgent = require('https-proxy-agent'); var HttpsProxyAgent = require('https-proxy-agent');
var SocksProxyAgent = require('socks-proxy-agent'); var SocksProxyAgent = require('socks-proxy-agent');
var PacResolver = require('pac-resolver'); var PacResolver = require('pac-resolver');
var toArray = require('stream-to-array'); var toBuffer = require('stream-to-buffer');
var inherits = require('util').inherits; var inherits = require('util').inherits;
var debug = require('debug')('pac-proxy-agent'); var debug = require('debug')('pac-proxy-agent');
@ -161,12 +161,11 @@ PacProxyAgent.prototype.loadPacFile = function (fn) {
if (err) return fn(err); if (err) return fn(err);
debug('got stream.Readable instance for URI'); debug('got stream.Readable instance for URI');
self.cache = rs; self.cache = rs;
toArray(rs, onarray); toBuffer(rs, onbuffer);
} }
function onarray (err, arr) { function onbuffer (err, buf) {
if (err) return fn(err); if (err) return fn(err);
var buf = Buffer.concat(arr);
debug('read %o byte PAC file from URI', buf.length); debug('read %o byte PAC file from URI', buf.length);
fn(null, buf.toString('utf8')); fn(null, buf.toString('utf8'));
} }

Просмотреть файл

@ -35,7 +35,7 @@
"https-proxy-agent": "^0.3.5", "https-proxy-agent": "^0.3.5",
"pac-resolver": "~1.2.1", "pac-resolver": "~1.2.1",
"socks-proxy-agent": "^1.0.2", "socks-proxy-agent": "^1.0.2",
"stream-to-array": "~1.0.0" "stream-to-buffer": "^0.1.0"
}, },
"devDependencies": { "devDependencies": {
"mocha": "2", "mocha": "2",

Просмотреть файл

@ -8,6 +8,7 @@ var url = require('url');
var http = require('http'); var http = require('http');
var https = require('https'); var https = require('https');
var assert = require('assert'); var assert = require('assert');
var toBuffer = require('stream-to-buffer');
var Proxy = require('proxy'); var Proxy = require('proxy');
var socks = require('socksv5'); var socks = require('socksv5');
var PacProxyAgent = require('../'); var PacProxyAgent = require('../');
@ -156,13 +157,9 @@ describe('PacProxyAgent', function () {
opts.agent = agent; opts.agent = agent;
var req = http.get(opts, function (res) { var req = http.get(opts, function (res) {
var data = ''; toBuffer(res, function (err, buf) {
res.setEncoding('utf8'); if (err) return done(err);
res.on('data', function (b) { var data = JSON.parse(buf.toString('utf8'));
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('127.0.0.1:' + httpPort, data.host); assert.equal('127.0.0.1:' + httpPort, data.host);
assert('via' in data); assert('via' in data);
done(); done();
@ -189,13 +186,9 @@ describe('PacProxyAgent', function () {
opts.agent = agent; opts.agent = agent;
var req = http.get(opts, function (res) { var req = http.get(opts, function (res) {
var data = ''; toBuffer(res, function (err, buf) {
res.setEncoding('utf8'); if (err) return done(err);
res.on('data', function (b) { var data = JSON.parse(buf.toString('utf8'));
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('127.0.0.1:' + httpPort, data.host); assert.equal('127.0.0.1:' + httpPort, data.host);
assert('via' in data); assert('via' in data);
done(); done();
@ -220,13 +213,9 @@ describe('PacProxyAgent', function () {
opts.agent = agent; opts.agent = agent;
var req = http.get(opts, function (res) { var req = http.get(opts, function (res) {
var data = ''; toBuffer(res, function (err, buf) {
res.setEncoding('utf8'); if (err) return done(err);
res.on('data', function (b) { var data = JSON.parse(buf.toString('utf8'));
data += b;
});
res.on('end', function () {
data = JSON.parse(data);
assert.equal('127.0.0.1:' + httpPort, data.host); assert.equal('127.0.0.1:' + httpPort, data.host);
done(); done();
}); });