Skip to content

Commit

Permalink
fix: ignore not throw on invalid response headers
Browse files Browse the repository at this point in the history
Fixes #930
  • Loading branch information
pke authored and JakeChampion committed Apr 1, 2023
1 parent a43b628 commit e74fa5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ function parseHeaders(rawHeaders) {
var key = parts.shift().trim()
if (key) {
var value = parts.join(':').trim()
headers.append(key, value)
try {
headers.append(key, value)
} catch (error) {
console.warn('Response ' + error.message)
}
}
})
return headers
Expand Down
8 changes: 8 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ const routes = {
'Content-Type': 'text/html; charset=utf-8'
})
res.end()
},
'/invalid-headers': function(res) {
res.writeHead(200, {
'Content-Type': 'text/plain',
'Invalid Header': 'valid value',
'Westworld-S01': "<3"
})
res.end()
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,12 @@ exercise.forEach(function(exerciseMode) {
assert.equal(response.headers.get('Content-Type'), 'text/html; charset=utf-8')
})
})
test('parses invalid headers', function() {
return fetch('/invalid-headers').then(function(response) {
assert.equal(response.headers.get('Content-Type'), 'text/plain')
assert.equal(response.headers.get('Westworld-S01'), '<3')
})
})
})

// https://fetch.spec.whatwg.org/#methods
Expand Down

0 comments on commit e74fa5b

Please sign in to comment.