Skip to content

Commit

Permalink
http response begin
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Mar 20, 2013
1 parent 27ecc72 commit 5e820f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -5,7 +5,7 @@ var Stream = require('./stream');
var events = [
'http-client-request-begin'
, 'http-client-request-end'
// , 'http-client-response-begin'
, 'http-client-response-begin'
// , 'http-client-response-end'
// , 'http-server-request-begin'
// , 'http-server-request-end'
Expand Down
17 changes: 17 additions & 0 deletions listeners/http-client-response-begin.js
@@ -0,0 +1,17 @@
/// http-client-response-begin

module.exports =
function listener(res, time, timeDiff) {
var req = res.client._httpMessage;

return {
event: 'http-client-response-begin',
time: time,
timeDiff: timeDiff,
headers: res.headers,
statusCode: res.statusCode,
method: req.method,
path: req.path,
host: req._headers.host
};
};
25 changes: 25 additions & 0 deletions tests/http_client.js
Expand Up @@ -44,6 +44,31 @@ test('emits http-client-request-end', function(t) {
}
});

d.run(function() {
http.get('http://search.twitter.com/search.json?q=nodejs', function(res) {
res.resume();
});
});
});

test('emits http-client-response-begin', function(t) {
t.plan(6);

var s = S();
var d = domain.create();

s.on('readable', function() {
var event = s.read();
if (event && event.event == 'http-client-response-begin') {
t.type(event.time, 'number');
t.ok(event.timeDiff >= 0);
t.equal(event.method, 'GET');
t.equal(event.path, '/search.json?q=nodejs');
t.equal(event.host, 'search.twitter.com');
t.type(event.headers, 'object');
}
});

d.run(function() {
http.get('http://search.twitter.com/search.json?q=nodejs', function(res) {
res.resume();
Expand Down

0 comments on commit 5e820f2

Please sign in to comment.