Skip to content

Commit 815d391

Browse files
author
Cameron Lakenen
committed
Set correct path and method properties on the request object
1 parent c0869e5 commit 815d391

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/request.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var Request = module.exports = function (xhr, params) {
88
self.writable = true;
99
self.xhr = xhr;
1010
self.body = [];
11+
self.method = params.method || 'GET';
12+
self.path = params.path || '/'
1113

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

2830
xhr.open(
29-
params.method || 'GET',
31+
self.method,
3032
self.uri,
3133
true
3234
);

test/request_url.js

+14
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ test('Test withCredentials param', function(t) {
7272

7373
t.end();
7474
});
75+
76+
test('Test request has correct method and path properties', function(t) {
77+
var path = '/api/foo?hello=world';
78+
79+
var request = http.request(path);
80+
t.equal(request.path, path, 'path should be correct');
81+
t.equal(request.method, 'GET', 'method should be correct');
82+
83+
request = http.request({ path: path, method: 'POST' });
84+
t.equal(request.path, path, 'path should be correct');
85+
t.equal(request.method, 'POST', 'method should be correct');
86+
87+
t.end();
88+
});

0 commit comments

Comments
 (0)