Skip to content

Commit

Permalink
Update the internal path variable when querystring is changed
Browse files Browse the repository at this point in the history
If the querystring is changed *after* creating a request object, update
the internal path to ensure that the proper request is sent over the
wire.
  • Loading branch information
jblebrun committed Apr 18, 2013
1 parent 638c568 commit 227d998
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ Request.prototype.qs = function (q, clobber) {

this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base))
this.url = this.uri
this.path = this.uri.path

return this
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test-qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ var req5 = request.get({ uri: 'http://www.google.com', qs: {}})
setTimeout(function(){
assert.equal('/', req5.path)
}, 1)


// Test modifying the qs after creating the request
var req6 = request.get({ uri: 'http://www.google.com', qs: {}});
req6.qs({ q: "test" });
process.nextTick(function() {
assert.equal('/?q=test', req6.path);
});

0 comments on commit 227d998

Please sign in to comment.