From 7efca7dc7d87c23467f74badb8c527a492a71b0a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 11 Feb 2021 19:31:42 -0500 Subject: [PATCH] Minify: Don't ignore request headers in `requestURI()` --- src/node/utils/Minify.js | 72 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index d9f5d508c..8689ce8f6 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -48,45 +48,41 @@ const LIBRARY_WHITELIST = [ // What follows is a terrible hack to avoid loop-back within the server. // TODO: Serve files from another service, or directly from the file system. -const requestURI = async (url, method, headers) => { - var headers = {}; - - return await new Promise((resolve, reject) => { - const parsedURL = urlutil.parse(url); - let status = 500; - const content = []; - const mockRequest = { - url, - method, - params: {filename: parsedURL.path.replace(/^\/static\//, '')}, - headers, - }; - const mockResponse = { - writeHead: (_status, _headers) => { - status = _status; - for (const header in _headers) { - if (Object.prototype.hasOwnProperty.call(_headers, header)) { - headers[header] = _headers[header]; - } +const requestURI = async (url, method, headers) => await new Promise((resolve, reject) => { + const parsedURL = urlutil.parse(url); + let status = 500; + const content = []; + const mockRequest = { + url, + method, + params: {filename: parsedURL.path.replace(/^\/static\//, '')}, + headers, + }; + const mockResponse = { + writeHead: (_status, _headers) => { + status = _status; + for (const header in _headers) { + if (Object.prototype.hasOwnProperty.call(_headers, header)) { + headers[header] = _headers[header]; } - }, - setHeader: (header, value) => { - headers[header.toLowerCase()] = value.toString(); - }, - header: (header, value) => { - headers[header.toLowerCase()] = value.toString(); - }, - write: (_content) => { - _content && content.push(_content); - }, - end: (_content) => { - _content && content.push(_content); - resolve([status, headers, content.join('')]); - }, - }; - minify(mockRequest, mockResponse).catch(reject); - }); -}; + } + }, + setHeader: (header, value) => { + headers[header.toLowerCase()] = value.toString(); + }, + header: (header, value) => { + headers[header.toLowerCase()] = value.toString(); + }, + write: (_content) => { + _content && content.push(_content); + }, + end: (_content) => { + _content && content.push(_content); + resolve([status, headers, content.join('')]); + }, + }; + minify(mockRequest, mockResponse).catch(reject); +}); const requestURIs = (locations, method, headers, callback) => { Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => {