Skip to content

Commit

Permalink
Fixed query-string support, retain original qs
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg authored and tj committed Jan 24, 2012
1 parent 32c6ac1 commit b3abd64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,16 @@ Request.prototype.request = function(){
options.path = url.pathname;
options.host = url.hostname;

if (null == url.query) url.query = '';

// querystring
if ('GET' == this.method && null != data) {
options.path += '?' + qs.stringify(data);
data = null;
if ('GET' == this.method && data) {
data = qs.stringify(data);
url.query += (url.query.length ? '&' : '') + data;
}

if (url.query.length) options.path += '?' + url.query;

// initiate request
var mod = exports.protocols[url.protocol];

Expand Down
23 changes: 21 additions & 2 deletions test/node/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ app.listen(3006);

describe('req.send(Object)', function(){
describe('on a GET request', function(){
it('should send x-www-form-urlencoded data', function(done){
it('should construct the query-string', function(done){
request
.get('http://localhost:3006/')
.send({ name: 'tobi' })
Expand All @@ -25,5 +25,24 @@ describe('req.send(Object)', function(){
done();
});
})

it('should append to the original query-string', function(done){
request
.get('http://localhost:3006/?name=tobi')
.send({ order: 'asc' })
.end(function(res) {
res.body.should.eql({ name: 'tobi', order: 'asc' });
done();
});
});

it('should retain the original query-string', function(done){
request
.get('http://localhost:3006/?name=tobi')
.end(function(res) {
res.body.should.eql({ name: 'tobi' });
done();
});
});
})
})
})

0 comments on commit b3abd64

Please sign in to comment.