提交 9a6d748b 编写于 作者: P Philipp Kursawe 提交者: Jake Champion

fix: ignore not throw on invalid response headers

Fixes #930
上级 a43b6283
......@@ -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
......
......@@ -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()
}
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册