Skip to content

Commit

Permalink
Add reference to request object as property on response
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Lakenen committed Sep 24, 2014
1 parent 17b2990 commit 6b375e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Request = module.exports = function (xhr, params) {
}

var res = new Response;
res.req = self;
res.on('close', function () {
self.emit('close');
});
Expand Down
14 changes: 14 additions & 0 deletions test/request_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,17 @@ test('Test POST XHR2 types', function(t) {
};
request.end(new global.FormData());
});

test('Test response has reference to request object', function(t) {
t.plan(1);
var url = '/api/foo';

var request = http.request({ url: url });
request.on('response', function (res) {
t.equal(res.req, request, 'response should have reference to request object');
});
request.xhr.readyState = 4;
request.xhr.responseType = 'meat';
request.xhr.responseText = '';
request.xhr.onreadystatechange();
});

0 comments on commit 6b375e4

Please sign in to comment.