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 Jul 30, 2014
1 parent c0869e5 commit d9801f5
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 @@ -49,6 +49,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 @@ -72,3 +72,17 @@ test('Test withCredentials param', function(t) {

t.end();
});

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 d9801f5

Please sign in to comment.