Skip to content

Commit

Permalink
Fix immutable response header bug.
Browse files Browse the repository at this point in the history
Node 18 responses have an immutable location header. Refactor logic to
avoid issue.
  • Loading branch information
davidlehn committed Jun 6, 2022
1 parent 6d20396 commit 9f61795
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/documentLoaders/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = ({
url, headers, strictSSL, httpAgent, httpsAgent
});
doc = {contextUrl: null, documentUrl: url, document: body || null};

// handle error
const statusText = http.STATUS_CODES[res.status];
if(res.status >= 400) {
Expand All @@ -92,7 +93,9 @@ module.exports = ({
});
}
const link = res.headers.get('link');
let location = res.headers.get('location');
const contentType = res.headers.get('content-type');

// handle Link Header
if(link && contentType !== 'application/ld+json') {
// only 1 related link header permitted
Expand All @@ -115,10 +118,10 @@ module.exports = ({
alternate.type == 'application/ld+json' &&
!(contentType || '')
.match(/^application\/(\w*\+)?json$/)) {
res.headers.set('location', prependBase(url, alternate.target));
location = prependBase(url, alternate.target);
}
}
const location = res.headers.get('location');

// handle redirect
if((alternate ||
res.status >= 300 && res.status < 400) && location) {
Expand Down

0 comments on commit 9f61795

Please sign in to comment.