From 95373d2b7ea9c90f1966f573a1c4f7c62d43ab19 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 2 Dec 2014 14:30:13 +0000 Subject: [PATCH] send a strong etag for the output.pdf file, needed for byte ranges in pdf.js --- services/clsi/app.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/clsi/app.coffee b/services/clsi/app.coffee index 5f55fdfba7..0d9904dc3e 100644 --- a/services/clsi/app.coffee +++ b/services/clsi/app.coffee @@ -38,10 +38,17 @@ app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf staticServer = express.static Settings.path.compilesDir, setHeaders: (res, path, stat) -> if Path.basename(path) == "output.pdf" res.set("Content-Type", "application/pdf") + # Calculate an etag in the same way as nginx + # https://github.com/tj/send/issues/65 + etag = (path, stat) -> + '"' + Math.ceil(+stat.mtime / 1000).toString(16) + + '-' + Number(stat.size).toString(16) + '"' + res.set("Etag", etag(path, stat)) else # Force plain treatment of other file types to prevent hosting of HTTP/JS files # that could be used in same-origin/XSS attacks. res.set("Content-Type", "text/plain") + app.get "/project/:project_id/output/*", (req, res, next) -> req.url = "/#{req.params.project_id}/#{req.params[0]}" staticServer(req, res, next)