Skip to content

Commit

Permalink
Made query strings work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Golo Roden committed May 26, 2015
1 parent 5934de0 commit 3a7bca5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/request.js
Expand Up @@ -30,10 +30,13 @@ var setupRequest = function (protocol) {
}

if (typeof options === 'object') {
options.path = options.path || '/';

options.protocol = protocol;
options.hostname = options.hostname || 'localhost';
options.port = options.port || 80;
options.pathname = options.path || '/';
options.pathname = options.path.split('?')[0];
options.search = options.path.split('?')[1] || '';

reqMethod = options.method || 'GET';
reqUrl = url.format(options);
Expand Down
26 changes: 26 additions & 0 deletions test/requestTests.js
Expand Up @@ -73,6 +73,32 @@ suite('request', function () {
req.end();
});

test('accepts query strings.', function (done) {
var req;

req = http.request({
method: 'GET',
hostname: 'www.thenativeweb.io',
port: 80,
path: '/?_=82517'
}, function (res) {
var content = '';

assert.that(res.statusCode).is.equalTo(200);

res.on('data', function (data) {
content += data.toString('utf8');
});

res.once('end', function () {
assert.that(content.indexOf('the native web')).is.not.equalTo(-1);
res.removeAllListeners();
done();
});
});
req.end();
});

test('returns a 404 if the requested path could not be found.', function (done) {
var req;

Expand Down

0 comments on commit 3a7bca5

Please sign in to comment.