Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.protocol || '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 @@ -112,3 +112,17 @@ test('Test POST XHR2 types', function(t) {
};
request.end(new global.FormData());
});

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();
});