Skip to content

Commit

Permalink
Set correct path and method properties on the request object
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Lakenen committed Jul 30, 2014
1 parent c0869e5 commit 815d391
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var Request = module.exports = function (xhr, params) {
self.writable = true;
self.xhr = xhr;
self.body = [];
self.method = params.method || 'GET';
self.path = params.path || '/'

self.uri = (params.scheme || 'http') + '://'
+ params.host
Expand All @@ -26,7 +28,7 @@ var Request = module.exports = function (xhr, params) {
catch (e) {}

xhr.open(
params.method || 'GET',
self.method,
self.uri,
true
);
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 request has correct method and path properties', function(t) {
var path = '/api/foo?hello=world';

var request = http.request(path);
t.equal(request.path, path, 'path should be correct');
t.equal(request.method, 'GET', 'method should be correct');

request = http.request({ path: path, method: 'POST' });
t.equal(request.path, path, 'path should be correct');
t.equal(request.method, 'POST', 'method should be correct');

t.end();
});

0 comments on commit 815d391

Please sign in to comment.