Skip to content

Commit

Permalink
In files.js, explicitly check for interlisp source files when setting…
Browse files Browse the repository at this point in the history
… content type header
  • Loading branch information
fghalasz committed Jul 19, 2024
1 parent d9716a1 commit 2771a41
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions web-portal/server/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ function setContentType(res, path, stat) {
const ext = mPath.extname(path);
if(ext.length == 0) {
const buffer = mFs.readFileSync(path);
if(isBinary(null, buffer)) {
console.log("BINARY: " + path);
const name = mPath.basename(path);
if(isInterlispSource(buffer, name) {
res.set('Content-Type', 'application/octet-stream');
} else if (isText(null, buffer)) {
console.log("TEXT: " + path);
res.set('Content-Type', 'text/plain; charset=UTF-8');
res.set('X-Content-Type-Options', 'nosniff');
} else {
console.log("NEITHER: " + path);
} else {
res.set('Content-Type', 'application/octet-stream');
}
} else {
switch(ext) {
Expand All @@ -57,6 +56,16 @@ function setContentType(res, path, stat) {
}
}

// Does buffer contain an Interlisp source file?
function isInterlispSource(buffer, name) {
return (
buffer.includes("(DEFINE-FILE-INFO")
&& buffer.includes(name + "COMS")
);

}


filesApp.use((req, res, next) => {
if(req.protocol === 'https' || !config.supportHttps) next();
else res.redirect(`https://${req.hostname}:${config.httpsRedirectPort}${req.url}`);
Expand Down

0 comments on commit 2771a41

Please sign in to comment.