Skip to content

Commit 9f61795

Browse files
committed
Fix immutable response header bug.
Node 18 responses have an immutable location header. Refactor logic to avoid issue.
1 parent 6d20396 commit 9f61795

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/documentLoaders/node.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module.exports = ({
8080
url, headers, strictSSL, httpAgent, httpsAgent
8181
});
8282
doc = {contextUrl: null, documentUrl: url, document: body || null};
83+
8384
// handle error
8485
const statusText = http.STATUS_CODES[res.status];
8586
if(res.status >= 400) {
@@ -92,7 +93,9 @@ module.exports = ({
9293
});
9394
}
9495
const link = res.headers.get('link');
96+
let location = res.headers.get('location');
9597
const contentType = res.headers.get('content-type');
98+
9699
// handle Link Header
97100
if(link && contentType !== 'application/ld+json') {
98101
// only 1 related link header permitted
@@ -115,10 +118,10 @@ module.exports = ({
115118
alternate.type == 'application/ld+json' &&
116119
!(contentType || '')
117120
.match(/^application\/(\w*\+)?json$/)) {
118-
res.headers.set('location', prependBase(url, alternate.target));
121+
location = prependBase(url, alternate.target);
119122
}
120123
}
121-
const location = res.headers.get('location');
124+
122125
// handle redirect
123126
if((alternate ||
124127
res.status >= 300 && res.status < 400) && location) {

0 commit comments

Comments
 (0)