diff --git a/lib/documentLoaders/node.js b/lib/documentLoaders/node.js index 9de3b7ba..61ad6b30 100644 --- a/lib/documentLoaders/node.js +++ b/lib/documentLoaders/node.js @@ -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) { @@ -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 @@ -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) {