Skip to content

Commit

Permalink
Guard against xhr.getAllResponseHeaders() being null
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
steveluscher authored and mislav committed May 5, 2016
1 parent 3fc66ed commit 8deb829
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@

function headers(xhr) {
var head = new Headers()
var pairs = xhr.getAllResponseHeaders().trim().split('\n')
var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n')
pairs.forEach(function(header) {
var split = header.trim().split(':')
var key = split.shift().trim()
Expand Down

0 comments on commit 8deb829

Please sign in to comment.