Construct Headers object in a spec-compliant fashion

This commit is contained in:
Timothy Gu 2016-10-10 14:12:57 -07:00
parent 82c1e78184
commit ba226399d4
1 changed files with 10 additions and 1 deletions

View File

@ -152,7 +152,16 @@ function fetch(url, opts) {
}
// normalize location header for manual redirect mode
const headers = new Headers(res.headers);
const headers = new Headers();
for (const name of Object.keys(res.headers)) {
if (Array.isArray(res.headers[name])) {
for (const val of res.headers[name]) {
headers.append(name, val);
}
} else {
headers.append(name, res.headers[name]);
}
}
if (options.redirect === 'manual' && headers.has('location')) {
headers.set('location', resolve_url(options.url, headers.get('location')));
}