Comparing version 6.3.0 to 7.0.0
175
lib/index.js
@@ -0,14 +1,15 @@ | ||
'use strict'; | ||
// Load modules | ||
var Events = require('events'); | ||
var Url = require('url'); | ||
var Http = require('http'); | ||
var Https = require('https'); | ||
var Stream = require('stream'); | ||
var Hoek = require('hoek'); | ||
var Boom = require('boom'); | ||
var Payload = require('./payload'); | ||
var Recorder = require('./recorder'); | ||
var Tap = require('./tap'); | ||
const Events = require('events'); | ||
const Url = require('url'); | ||
const Http = require('http'); | ||
const Https = require('https'); | ||
const Stream = require('stream'); | ||
const Hoek = require('hoek'); | ||
const Boom = require('boom'); | ||
const Payload = require('./payload'); | ||
const Recorder = require('./recorder'); | ||
const Tap = require('./tap'); | ||
@@ -18,3 +19,3 @@ | ||
var internals = { | ||
const internals = { | ||
jsonRegex: /^application\/[a-z.+-]*json$/, | ||
@@ -56,6 +57,6 @@ shallowOptions: ['agent', 'payload', 'downstreamRes', 'beforeRedirect', 'redirected'] | ||
var parsedBase = Url.parse(baseUrl); | ||
var parsedPath = Url.parse(path); | ||
const parsedBase = Url.parse(baseUrl); | ||
const parsedPath = Url.parse(path); | ||
parsedBase.pathname += parsedPath.pathname; | ||
parsedBase.pathname = parsedBase.pathname + parsedPath.pathname; | ||
parsedBase.pathname = parsedBase.pathname.replace(/[/]{2,}/g, '/'); | ||
@@ -70,4 +71,2 @@ parsedBase.search = parsedPath.search; // Always use the querystring from the path argument | ||
var self = this; | ||
options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, internals.shallowOptions); | ||
@@ -93,8 +92,7 @@ | ||
var uri = Url.parse(url); | ||
var timeoutId; | ||
const uri = Url.parse(url); | ||
uri.method = method.toUpperCase(); | ||
uri.headers = options.headers; | ||
var payloadSupported = (uri.method !== 'GET' && uri.method !== 'HEAD' && options.payload !== null && options.payload !== undefined); | ||
const payloadSupported = (uri.method !== 'GET' && uri.method !== 'HEAD' && options.payload !== null && options.payload !== undefined); | ||
if (payloadSupported && | ||
@@ -107,3 +105,3 @@ (typeof options.payload === 'string' || Buffer.isBuffer(options.payload))) { | ||
var redirects = (options.hasOwnProperty('redirects') ? options.redirects : false); // Needed to allow 0 as valid value when passed recursively | ||
let redirects = (options.hasOwnProperty('redirects') ? options.redirects : false); // Needed to allow 0 as valid value when passed recursively | ||
@@ -113,3 +111,3 @@ _trace = (_trace || []); | ||
var client = (uri.protocol === 'https:' ? Https : Http); | ||
const client = (uri.protocol === 'https:' ? Https : Http); | ||
@@ -130,10 +128,14 @@ if (options.rejectUnauthorized !== undefined && uri.protocol === 'https:') { | ||
var start = Date.now(); | ||
var req = client.request(uri); | ||
const start = Date.now(); | ||
const req = client.request(uri); | ||
var shadow = null; // A copy of the streamed request payload when redirects are enabled | ||
let shadow = null; // A copy of the streamed request payload when redirects are enabled | ||
let onResponse; | ||
let onError; | ||
let timeoutId; | ||
// Register handlers | ||
var finish = function (err, res) { | ||
const finish = (err, res) => { | ||
@@ -148,3 +150,3 @@ if (!callback || err) { | ||
clearTimeout(timeoutId); | ||
self.emit('response', err, req, res, start, uri); | ||
this.emit('response', err, req, res, start, uri); | ||
@@ -156,8 +158,8 @@ if (callback) { | ||
finish = Hoek.once(finish); | ||
const finishOnce = Hoek.once(finish); | ||
var onError = function (err) { | ||
onError = (err) => { | ||
err.trace = _trace; | ||
return finish(Boom.badGateway('Client request error', err)); | ||
return finishOnce(Boom.badGateway('Client request error', err)); | ||
}; | ||
@@ -167,7 +169,7 @@ | ||
var onResponse = function (res) { | ||
onResponse = (res) => { | ||
// Pass-through response | ||
var statusCode = res.statusCode; | ||
const statusCode = res.statusCode; | ||
@@ -177,3 +179,3 @@ if (redirects === false || | ||
return finish(null, res); | ||
return finishOnce(null, res); | ||
} | ||
@@ -183,4 +185,4 @@ | ||
var redirectMethod = (statusCode === 301 || statusCode === 302 ? 'GET' : uri.method); | ||
var location = res.headers.location; | ||
const redirectMethod = (statusCode === 301 || statusCode === 302 ? 'GET' : uri.method); | ||
let location = res.headers.location; | ||
@@ -190,7 +192,7 @@ res.destroy(); | ||
if (redirects === 0) { | ||
return finish(Boom.badGateway('Maximum redirections reached', _trace)); | ||
return finishOnce(Boom.badGateway('Maximum redirections reached', _trace)); | ||
} | ||
if (!location) { | ||
return finish(Boom.badGateway('Received redirection without location', _trace)); | ||
return finishOnce(Boom.badGateway('Received redirection without location', _trace)); | ||
} | ||
@@ -202,3 +204,3 @@ | ||
var redirectOptions = Hoek.cloneWithShallow(options, internals.shallowOptions); | ||
const redirectOptions = Hoek.cloneWithShallow(options, internals.shallowOptions); | ||
@@ -212,3 +214,3 @@ redirectOptions.payload = shadow || options.payload; // shadow must be ready at this point if set | ||
var redirectReq = self.request(redirectMethod, location, redirectOptions, finish, _trace); | ||
const redirectReq = this.request(redirectMethod, location, redirectOptions, finishOnce, _trace); | ||
@@ -223,5 +225,5 @@ if (options.redirected) { | ||
if (options.timeout) { | ||
timeoutId = setTimeout(function () { | ||
timeoutId = setTimeout(() => { | ||
return finish(Boom.gatewayTimeout('Client request timeout')); | ||
return finishOnce(Boom.gatewayTimeout('Client request timeout')); | ||
}, options.timeout); | ||
@@ -235,7 +237,7 @@ delete options.timeout; | ||
if (options.payload instanceof Stream) { | ||
var stream = options.payload; | ||
let stream = options.payload; | ||
if (redirects) { | ||
var collector = new Tap(); | ||
collector.once('finish', function () { | ||
const collector = new Tap(); | ||
collector.once('finish', () => { | ||
@@ -257,14 +259,14 @@ shadow = collector.collect(); | ||
var _abort = req.abort; | ||
var aborted = false; | ||
req.abort = function () { | ||
const _abort = req.abort; | ||
let aborted = false; | ||
req.abort = () => { | ||
if (!aborted && !req.res && !req.socket) { | ||
process.nextTick(function () { | ||
process.nextTick(() => { | ||
// Fake an ECONNRESET error | ||
var error = new Error('socket hang up'); | ||
const error = new Error('socket hang up'); | ||
error.code = 'ECONNRESET'; | ||
finish(error); | ||
finishOnce(error); | ||
}); | ||
@@ -293,17 +295,8 @@ } | ||
var clientTimeout = options.timeout; | ||
var clientTimeoutId = null; | ||
const clientTimeout = options.timeout; | ||
let clientTimeoutId = null; | ||
if (clientTimeout && | ||
clientTimeout > 0) { | ||
clientTimeoutId = setTimeout(function () { | ||
finish(Boom.clientTimeout()); | ||
}, clientTimeout); | ||
} | ||
// Finish once | ||
var finish = function (err, buffer) { | ||
const finish = (err, buffer) => { | ||
@@ -325,3 +318,3 @@ clearTimeout(clientTimeoutId); | ||
var result; | ||
let result; | ||
if (buffer.length === 0) { | ||
@@ -338,4 +331,4 @@ return callback(null, null); | ||
var contentType = (res.headers && res.headers['content-type']) || ''; | ||
var mime = contentType.split(';')[0].trim().toLowerCase(); | ||
const contentType = (res.headers && res.headers['content-type']) || ''; | ||
const mime = contentType.split(';')[0].trim().toLowerCase(); | ||
@@ -350,14 +343,23 @@ if (!internals.jsonRegex.test(mime)) { | ||
finish = Hoek.once(finish); | ||
const finishOnce = Hoek.once(finish); | ||
if (clientTimeout && | ||
clientTimeout > 0) { | ||
clientTimeoutId = setTimeout(() => { | ||
finishOnce(Boom.clientTimeout()); | ||
}, clientTimeout); | ||
} | ||
// Hander errors | ||
var onResError = function (err) { | ||
const onResError = (err) => { | ||
return finish(Boom.internal('Payload stream error', err)); | ||
return finishOnce(Boom.internal('Payload stream error', err)); | ||
}; | ||
var onResClose = function () { | ||
const onResClose = () => { | ||
return finish(Boom.internal('Payload stream closed prematurely')); | ||
return finishOnce(Boom.internal('Payload stream closed prematurely')); | ||
}; | ||
@@ -370,5 +372,5 @@ | ||
var reader = new Recorder({ maxBytes: options.maxBytes }); | ||
const reader = new Recorder({ maxBytes: options.maxBytes }); | ||
var onReaderError = function (err) { | ||
const onReaderError = (err) => { | ||
@@ -379,3 +381,3 @@ if (res.destroy) { // GZip stream has no destroy() method | ||
return finish(err); | ||
return finishOnce(err); | ||
}; | ||
@@ -385,5 +387,5 @@ | ||
var onReaderFinish = function () { | ||
const onReaderFinish = () => { | ||
return finish(null, reader.collect()); | ||
return finishOnce(null, reader.collect()); | ||
}; | ||
@@ -417,8 +419,8 @@ | ||
// 1: directive = 2: token 3: quoted-string | ||
var regex = /(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g; | ||
const regex = /(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g; | ||
var header = {}; | ||
var error = field.replace(regex, function ($0, $1, $2, $3) { | ||
const header = {}; | ||
const error = field.replace(regex, ($0, $1, $2, $3) => { | ||
var value = $2 || $3; | ||
const value = $2 || $3; | ||
header[$1] = value ? value.toLowerCase() : true; | ||
@@ -430,3 +432,3 @@ return ''; | ||
try { | ||
var maxAge = parseInt(header['max-age'], 10); | ||
const maxAge = parseInt(header['max-age'], 10); | ||
if (isNaN(maxAge)) { | ||
@@ -458,2 +460,3 @@ return null; | ||
internals.Client.prototype.patch = function (uri, options, callback) { | ||
@@ -481,4 +484,4 @@ | ||
var options = (typeof arguments[2] === 'function' ? {} : arguments[2]); | ||
var callback = (typeof arguments[2] === 'function' ? arguments[2] : arguments[3]); | ||
const options = (typeof arguments[2] === 'function' ? {} : arguments[2]); | ||
const callback = (typeof arguments[2] === 'function' ? arguments[2] : arguments[3]); | ||
@@ -491,6 +494,4 @@ return this._shortcut(method, uri, options, callback); | ||
var self = this; | ||
return this.request(method, uri, options, (err, res) => { | ||
return this.request(method, uri, options, function (err, res) { | ||
if (err) { | ||
@@ -500,3 +501,3 @@ return callback(err); | ||
self.read(res, options, function (err, payload) { | ||
this.read(res, options, (err, payload) => { | ||
@@ -511,3 +512,3 @@ return callback(err, res, payload); | ||
var result = { | ||
const result = { | ||
json: null, | ||
@@ -517,3 +518,3 @@ err: null | ||
try { | ||
var json = JSON.parse(buffer.toString()); | ||
const json = JSON.parse(buffer.toString()); | ||
result.json = json; | ||
@@ -520,0 +521,0 @@ } |
@@ -0,6 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
var Stream = require('stream'); | ||
const Hoek = require('hoek'); | ||
const Stream = require('stream'); | ||
@@ -10,3 +11,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -18,7 +19,7 @@ | ||
var data = [].concat(payload || ''); | ||
var size = 0; | ||
for (var i = 0, il = data.length; i < il; ++i) { | ||
var chunk = data[i]; | ||
size += chunk.length; | ||
const data = [].concat(payload || ''); | ||
let size = 0; | ||
for (let i = 0; i < data.length; ++i) { | ||
const chunk = data[i]; | ||
size = size + chunk.length; | ||
data[i] = Buffer.isBuffer(chunk) ? chunk : new Buffer(chunk); | ||
@@ -37,5 +38,5 @@ } | ||
var chunk = this._data.slice(this._position, this._position + size); | ||
const chunk = this._data.slice(this._position, this._position + size); | ||
this.push(chunk, this._encoding); | ||
this._position += chunk.length; | ||
this._position = this._position + chunk.length; | ||
@@ -42,0 +43,0 @@ if (this._position >= this._data.length) { |
@@ -0,7 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Boom = require('boom'); | ||
var Hoek = require('hoek'); | ||
var Stream = require('stream'); | ||
const Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
const Stream = require('stream'); | ||
@@ -11,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -35,3 +36,3 @@ | ||
this.length += chunk.length; | ||
this.length = this.length + chunk.length; | ||
this.buffers.push(chunk); | ||
@@ -44,4 +45,4 @@ next(); | ||
var buffer = (this.buffers.length === 0 ? new Buffer(0) : (this.buffers.length === 1 ? this.buffers[0] : Buffer.concat(this.buffers, this.length))); | ||
const buffer = (this.buffers.length === 0 ? new Buffer(0) : (this.buffers.length === 1 ? this.buffers[0] : Buffer.concat(this.buffers, this.length))); | ||
return buffer; | ||
}; |
@@ -0,7 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
var Stream = require('stream'); | ||
var Payload = require('./payload'); | ||
const Hoek = require('hoek'); | ||
const Stream = require('stream'); | ||
const Payload = require('./payload'); | ||
@@ -11,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -14,0 +15,0 @@ |
{ | ||
"name": "wreck", | ||
"description": "HTTP Client Utilities", | ||
"version": "6.3.0", | ||
"version": "7.0.0", | ||
"repository": "git://github.com/hapijs/wreck", | ||
@@ -13,11 +13,11 @@ "main": "lib/index", | ||
"engines": { | ||
"node": ">=0.10.40" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "2.x.x", | ||
"boom": "2.x.x" | ||
"boom": "3.x.x", | ||
"hoek": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"lab": "5.x.x", | ||
"code": "1.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
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 too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
131041
1854
5
+ Addedboom@3.2.2(transitive)
+ Addedhoek@3.0.44.3.1(transitive)
- Removedboom@2.10.1(transitive)
- Removedhoek@2.16.3(transitive)
Updatedboom@3.x.x
Updatedhoek@3.x.x