Minify: Don't ignore request headers in requestURI()

This commit is contained in:
Richard Hansen 2021-02-11 19:31:42 -05:00 committed by John McLear
parent 7a003cb9e2
commit 7efca7dc7d

View file

@ -48,45 +48,41 @@ const LIBRARY_WHITELIST = [
// What follows is a terrible hack to avoid loop-back within the server. // 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. // TODO: Serve files from another service, or directly from the file system.
const requestURI = async (url, method, headers) => { const requestURI = async (url, method, headers) => await new Promise((resolve, reject) => {
var headers = {}; const parsedURL = urlutil.parse(url);
let status = 500;
return await new Promise((resolve, reject) => { const content = [];
const parsedURL = urlutil.parse(url); const mockRequest = {
let status = 500; url,
const content = []; method,
const mockRequest = { params: {filename: parsedURL.path.replace(/^\/static\//, '')},
url, headers,
method, };
params: {filename: parsedURL.path.replace(/^\/static\//, '')}, const mockResponse = {
headers, writeHead: (_status, _headers) => {
}; status = _status;
const mockResponse = { for (const header in _headers) {
writeHead: (_status, _headers) => { if (Object.prototype.hasOwnProperty.call(_headers, header)) {
status = _status; headers[header] = _headers[header];
for (const header in _headers) {
if (Object.prototype.hasOwnProperty.call(_headers, header)) {
headers[header] = _headers[header];
}
} }
}, }
setHeader: (header, value) => { },
headers[header.toLowerCase()] = value.toString(); setHeader: (header, value) => {
}, headers[header.toLowerCase()] = value.toString();
header: (header, value) => { },
headers[header.toLowerCase()] = value.toString(); header: (header, value) => {
}, headers[header.toLowerCase()] = value.toString();
write: (_content) => { },
_content && content.push(_content); write: (_content) => {
}, _content && content.push(_content);
end: (_content) => { },
_content && content.push(_content); end: (_content) => {
resolve([status, headers, content.join('')]); _content && content.push(_content);
}, resolve([status, headers, content.join('')]);
}; },
minify(mockRequest, mockResponse).catch(reject); };
}); minify(mockRequest, mockResponse).catch(reject);
}; });
const requestURIs = (locations, method, headers, callback) => { const requestURIs = (locations, method, headers, callback) => {
Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => { Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => {