Minify: Don't ignore request headers in `requestURI()`
parent
7a003cb9e2
commit
7efca7dc7d
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue