Skip to content

Commit 9a6d748

Browse files
pkeJakeChampion
authored andcommittedApr 1, 2023
fix: ignore not throw on invalid response headers
Fixes #930
1 parent a43b628 commit 9a6d748

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎fetch.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ function parseHeaders(rawHeaders) {
437437
var key = parts.shift().trim()
438438
if (key) {
439439
var value = parts.join(':').trim()
440-
headers.append(key, value)
440+
try {
441+
headers.append(key, value)
442+
} catch (error) {
443+
console.warn('Response ' + error.message)
444+
}
441445
}
442446
})
443447
return headers

‎test/server.js

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ const routes = {
120120
'Content-Type': 'text/html; charset=utf-8'
121121
})
122122
res.end()
123+
},
124+
'/invalid-headers': function(res) {
125+
res.writeHead(200, {
126+
'Content-Type': 'text/plain',
127+
'Invalid Header': 'valid value',
128+
'Westworld-S01': "<3"
129+
})
130+
res.end()
123131
}
124132
}
125133

‎test/test.js

+6
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,12 @@ exercise.forEach(function(exerciseMode) {
12811281
assert.equal(response.headers.get('Content-Type'), 'text/html; charset=utf-8')
12821282
})
12831283
})
1284+
test('parses invalid headers', function() {
1285+
return fetch('/invalid-headers').then(function(response) {
1286+
assert.equal(response.headers.get('Content-Type'), 'text/plain')
1287+
assert.equal(response.headers.get('Westworld-S01'), '<3')
1288+
})
1289+
})
12841290
})
12851291

12861292
// https://fetch.spec.whatwg.org/#methods

0 commit comments

Comments
 (0)
Please sign in to comment.