Comparing version 6.0.0 to 6.1.0
@@ -19,3 +19,4 @@ | ||
var internals = { | ||
jsonRegex: /^application\/[a-z.+-]*json$/ | ||
jsonRegex: /^application\/[a-z.+-]*json$/, | ||
shallowOptions: ['agent', 'payload', 'downstreamRes', 'redirected'] | ||
}; | ||
@@ -44,3 +45,3 @@ | ||
options = Hoek.applyToDefaultsWithShallow(options, this._defaults, ['agent', 'payload', 'downstreamRes']); | ||
options = Hoek.applyToDefaultsWithShallow(options, this._defaults, internals.shallowOptions); | ||
return new internals.Client(options); | ||
@@ -71,3 +72,3 @@ }; | ||
options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, ['agent', 'payload', 'downstreamRes']); | ||
options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, internals.shallowOptions); | ||
@@ -81,2 +82,5 @@ Hoek.assert(options.payload === null || options.payload === undefined || typeof options.payload === 'string' || | ||
Hoek.assert(options.redirected === undefined || options.redirected === null || typeof options.redirected === 'function', | ||
'options.redirected must be a function'); | ||
if (options.baseUrl) { | ||
@@ -159,4 +163,6 @@ url = internals.resolveUrl(options.baseUrl, url); | ||
var statusCode = res.statusCode; | ||
if (redirects === false || | ||
[301, 302, 307, 308].indexOf(res.statusCode) === -1) { | ||
[301, 302, 307, 308].indexOf(statusCode) === -1) { | ||
@@ -168,3 +174,3 @@ return finish(null, res); | ||
var redirectMethod = (res.statusCode === 301 || res.statusCode === 302 ? 'GET' : uri.method); | ||
var redirectMethod = (statusCode === 301 || statusCode === 302 ? 'GET' : uri.method); | ||
var location = res.headers.location; | ||
@@ -186,3 +192,3 @@ | ||
var redirectOptions = Hoek.cloneWithShallow(options, ['agent', 'payload', 'downstreamRes']); | ||
var redirectOptions = Hoek.cloneWithShallow(options, internals.shallowOptions); | ||
@@ -192,3 +198,7 @@ redirectOptions.payload = shadow || options.payload; // shadow must be ready at this point if set | ||
return self.request(redirectMethod, location, redirectOptions, finish, _trace); | ||
var redirectReq = self.request(redirectMethod, location, redirectOptions, finish, _trace); | ||
if (options.redirected) { | ||
options.redirected(statusCode, location, redirectReq); | ||
} | ||
}; | ||
@@ -262,3 +272,3 @@ | ||
options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, ['agent', 'payload', 'downstreamRes']); | ||
options = Hoek.applyToDefaultsWithShallow(options || {}, this._defaults, internals.shallowOptions); | ||
@@ -265,0 +275,0 @@ // Set stream timeout |
{ | ||
"name": "wreck", | ||
"description": "HTTP Client Utilities", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"repository": "git://github.com/hapijs/wreck", | ||
@@ -6,0 +6,0 @@ "main": "lib/index", |
@@ -45,2 +45,3 @@ ![wreck Logo](https://raw.github.com/hapijs/wreck/master/images/wreck.png) | ||
redirects: 3, | ||
redirected: function (statusCode, location, req) {}, | ||
timeout: 1000, // 1 second, default: unlimited | ||
@@ -86,2 +87,6 @@ maxBytes: 1048576, // 1 MB, default: unlimited | ||
- `redirects` - The maximum number of redirects to follow. | ||
- `redirected` - A callback function that is called when a redirect was triggered, using the signature `function (statusCode, location, req)` where: | ||
- `statusCode` - HTTP status code of the response that triggered the redirect. | ||
- `location` - The redirected location string. | ||
- `req` - The new [ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest) object which replaces the one initially returned. | ||
- `agent` - Node Core [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent). | ||
@@ -88,0 +93,0 @@ Defaults to either `wreck.agents.http` or `wreck.agents.https`. Setting to `false` disables agent pooling. |
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
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
128562
1796
240
10