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

Guard against xhr.getAllResponseHeaders() being null #289

Merged
merged 1 commit into from
Mar 30, 2016
Merged

Guard against xhr.getAllResponseHeaders() being null #289

merged 1 commit into from
Mar 30, 2016

Conversation

steveluscher
Copy link
Contributor

From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#getAllResponseHeaders():

Returns all the response headers, separated by CRLF, as a string, or null if no response has been received.

I discovered this on Android, once when xhr.getAllResponseHeaders() evaluated to null.

@@ -267,13 +267,16 @@

function headers(xhr) {
var head = new Headers()
var pairs = xhr.getAllResponseHeaders().trim().split('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n')

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this approach would be more elegant than wrapping everything in a typeof check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I was just trying to avoid creating and forEach-ing that array for nothing.

@dgraham
Copy link
Contributor

dgraham commented Mar 12, 2016

@steveluscher This looks great. Can you squash this into a single commit? If you accept the contributor license agreement by clicking the Details link next to the failed build status, I can merge this branch.

@steveluscher
Copy link
Contributor Author

cc/ @jamesgpearce

From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#getAllResponseHeaders():

> Returns all the response headers, separated by CRLF, as a string, or null if no response has been received.

I discovered this on Android, once when `xhr.getAllResponseHeaders()` evaluated to `null`.
@dgraham dgraham merged commit 08fc999 into JakeChampion:master Mar 30, 2016
@dgraham
Copy link
Contributor

dgraham commented Mar 30, 2016

Thanks, @steveluscher!

@steveluscher steveluscher deleted the patch-1 branch March 31, 2016 02:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants