Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hapijs/wreck into 82
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
geek committed Mar 21, 2017
2 parents a350019 + 961d678 commit d4ff006
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,21 @@ and decorate a request before its sent.
#### `response`

The response event is always emitted for any request that *wreck* makes. The
handler should accept the following arguments `(error, request, response, start,
uri)` where:

- `error` - a Boom error
- `request` - the raw `ClientHttp` request object
- `response` - the raw `IncomingMessage` response object
- `start` - the time that the request was initiated
- `uri` - the result of `Url.parse(uri)`. This will provide information about
the resource requested. Also includes the headers and method.

This event is useful for logging all requests that go through *wreck*. The error
and response arguments can be undefined depending on if an error occurs. Please
handler should accept the following arguments `(err, details)` where:

- `err` - a Boom error
- `details` - object with the following properties
- `req` - the raw `ClientHttp` request object
- `res` - the raw `IncomingMessage` response object
- `start` - the time that the request was initiated
- `uri` - the result of `Url.parse(uri)`. This will provide information about
the resource requested. Also includes the headers and method.

This event is useful for logging all requests that go through *wreck*. The `err`
and `res` arguments can be undefined depending on if an error occurs. Please
be aware that if multiple modules are depending on the same cached *wreck*
module that this event can fire for each request made across all modules. The
start argument is the timestamp when the request was started. This can be
`start` property is the timestamp when the request was started. This can be
useful for determining how long it takes *wreck* to get a response back and
processed.

Expand All @@ -304,7 +304,7 @@ handle events in the following way:

```js
const symbol = Symbol.for('wreck');
process[symbol].on('response', (err) => {
process[symbol].on('response', (err, details) => {

if (err) {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internals.Client.prototype.request = function (method, url, options, callback, _
req.removeListener('error', onError);
req.on('error', Hoek.ignore);
clearTimeout(timeoutId);
this.emit('response', err, req, res, start, uri);
this.emit('response', err, { req, res, start, uri });

if (callback) {
return callback(err, res);
Expand Down
23 changes: 12 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2298,13 +2298,13 @@ describe('Events', () => {
res.end('ok');
});

process[internals.emitSymbol].once('response', (err, req, res, start, uri) => {
process[internals.emitSymbol].once('response', (err, details) => {

expect(err).to.not.exist();
expect(req).to.exist();
expect(res).to.exist();
expect(typeof start).to.equal('number');
expect(uri.href).to.equal('http://localhost:' + server.address().port + '/');
expect(details.req).to.exist();
expect(details.res).to.exist();
expect(typeof details.start).to.equal('number');
expect(details.uri.href).to.equal('http://localhost:' + server.address().port + '/');
done();
});

Expand All @@ -2323,11 +2323,12 @@ describe('Events', () => {

it('response event includes error when it occurs', { timeout: 10000 }, (done) => {

Wreck.once('response', (err, req, res) => {
Wreck.once('response', (err, details) => {

expect(err).to.exist();
expect(req).to.exist();
expect(res).to.not.exist();
expect(details).to.exist();
expect(details.req).to.exist();
expect(details.res).to.not.exist();
done();
});

Expand All @@ -2341,11 +2342,11 @@ describe('Events', () => {
it('multiple requests execute the same response handler', { timeout: 10000 }, (done) => {

let count = 0;
const handler = (err, req, res) => {
const handler = (err, details) => {

expect(err).to.exist();
expect(req).to.exist();
expect(res).to.not.exist();
expect(details.req).to.exist();
expect(details.res).to.not.exist();
count++;
};

Expand Down

0 comments on commit d4ff006

Please sign in to comment.