Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive requester #1430

Merged
merged 2 commits into from Feb 17, 2015
Merged

Conversation

tikotzky
Copy link
Contributor

Right now if you set a requester function in request.defaults it will override all further defined requester functions when using request.METHOD to make a request. For example

var request1 = request.defaults({}, function(uri, options, callback){
    console.log('I AM THE FIRST REQUESTER FUNCTION');
    request(uri, options, callback);
})

var request2 = request1.defaults({}, function(uri, options, callback){
    console.log('I AM THE SECOND REQUESTER FUNCTION');
    console.log('I WILL NEVER GET CALLED BY request2.METHOD');
    request1(uri, options, callback);
})

// currently using request.METHOD will only hit the first requester
request2.get(url)
// I AM THE FIRST REQUESTER FUNCTION

// using request directly will hit the both requesters
request({
  uri: url,
  method: 'GET'
})
// I AM THE SECOND REQUESTER FUNCTION
// I WILL NEVER GET CALLED BY request2.METHOD
// I AM THE FIRST REQUESTER FUNCTION

This PR fixes request.defaults so that recursive requester functions will get called by both request() and request.METHOD()

@nylen
Copy link
Member

nylen commented Feb 16, 2015

This is nice work, thank you for the PRs and for including tests 💚 I'll nominate it for $30 bounty if you're interested.

I'd rather see us use request instead of self / this, do you think that would cause any problems?


defaultsOne.get(s.url + '/get_recursive1', function (e, r, b) {
t.equal(e, null)
t.equal(b, 'TESTING!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.deepEqual(r.request.headers, {foo: 'bar1'})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tikotzky
Copy link
Contributor Author

@nylen thanks for the offer of bounty nomination, but I'll pass on that for now.

As for changing to use request instead of this, are you referring to inside the request.METHOD function?

Changing that to use request instead of this would make it not use the requester function passed into request.defaults.

@nylen
Copy link
Member

nylen commented Feb 16, 2015

@tikotzky good point, 👍 from me then. I'll merge this tomorrow if no one objects or beats me to it.

@simov @tikotzky our test suite has come a long way 😬 and further patches are always welcome.

@tikotzky
Copy link
Contributor Author

@nylen can this get merged now?

nylen added a commit that referenced this pull request Feb 17, 2015
@nylen nylen merged commit a822e64 into request:master Feb 17, 2015
@tikotzky tikotzky deleted the fix-recursive-requester branch February 17, 2015 20:13
simov added a commit to simov/request that referenced this pull request May 17, 2015
simov added a commit that referenced this pull request May 20, 2015
Refactor test-default tests (according to comments in #1430)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants