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

Make sure we return on errored browser requests. #1349

Merged
merged 1 commit into from Jan 13, 2015

Conversation

eiriksm
Copy link
Member

@eiriksm eiriksm commented Jan 12, 2015

Turns out that if browser requests are erroring out on an early stage (this could be error on DNS, cross-domain security cancellation or user has no internet connection), request will fail when trying the method caseless.has, because this will invoke Object.keys on undefined. So just wrapping the check here in a check for headers fixes the issue.

I also added a browesr test for this. The test proves the problem: it will fail if request.js is not updated (for example with this code).

I realize I could have also sent a PR to caseless to avoid calling Object keys on an undefined object, but seems to me that we should not even invoke caseless when we have no headers to work with.

Please let me know if you feel this should be solved in another way

Have a great week!

@simov
Copy link
Member

simov commented Jan 12, 2015

Your fix is correct but I really think this should be fixed in caseless like:

this.dict = dict || {}

on line 2

@eiriksm
Copy link
Member Author

eiriksm commented Jan 12, 2015

OK, so fix both places, or just caseless?

I want to keep the test at least, but this will pass only when we update caseless in that case.

@simov
Copy link
Member

simov commented Jan 12, 2015

IMO the fix should be applied only in caseless, then we keep the test in request of course.

Ping @nylen as he's the one that have publish right for these modules. Once this got published in caseless this PR can be fixed and merged.

My point about fixing this in caseless is that it's a bug in it in the first place.

@eiriksm
Copy link
Member Author

eiriksm commented Jan 12, 2015

Agreed. PR sent in request/caseless#17

@nylen
Copy link
Member

nylen commented Jan 12, 2015

👍 awesome! I actually ran into this issue the other day and didn't know what to make of it.

caseless 0.9.0 is out with that change.

I'd apply the fix here too (it's natural to say "do we have headers? if not, then don't do any of this stuff with headers"). But, as long as we fixed the issue and we have a test, that's the important part.

@nylen
Copy link
Member

nylen commented Jan 12, 2015

btw @eiriksm I've added you as a contributor. thanks for your work on browserified request, it is very much appreciated!

@eiriksm
Copy link
Member Author

eiriksm commented Jan 12, 2015

Added a commit with upgraded caseless to this PR. I don't really see the harm in having if (response.headers) in there still. In theory, it is a performance improvement ;)

And thanks for adding me as a contributor. Wow, I am honored :)

@nylen
Copy link
Member

nylen commented Jan 12, 2015

+1 from me, we fixed it twice.

I'll merge this tomorrow if no one objects or beats me to it.

@simov
Copy link
Member

simov commented Jan 12, 2015

What would happen here and here if response.caseless is not being initialized on top?

It might be a very rare edge case but still you'll get cannot access whatever of undefined I'm for keeping the code without the if branch. Then if there isn't any headers the only check will be if (response.caseless.has('set-cookie')

@eiriksm
Copy link
Member Author

eiriksm commented Jan 12, 2015

I don't see how that would ever be possible. But be that as it may, you are of course right. The variable should not be uninitialized when it is being used later.

I just pushed an updated branch with the if removed.

Thanks for pointing that out, I should have checked for its usage before posting the suggestion.

@simov
Copy link
Member

simov commented Jan 12, 2015

Looking good to me 👍

nylen added a commit that referenced this pull request Jan 13, 2015
Make sure we return on errored browser requests.
@nylen nylen merged commit 9564f99 into request:master Jan 13, 2015
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