From 8ee80cb5f1585e62cc063ac4d0a172455357ac48 Mon Sep 17 00:00:00 2001 From: azivner Date: Fri, 30 Nov 2018 15:49:35 +0100 Subject: [PATCH] using dashes instead of underscores in header names to avoid the fact that nginx by default drops all headers with underscore in the header name --- src/public/javascripts/services/server.js | 5 +++-- src/routes/routes.js | 2 +- src/services/protected_session.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/public/javascripts/services/server.js b/src/public/javascripts/services/server.js index 86beca5aa..9fb4279ca 100644 --- a/src/public/javascripts/services/server.js +++ b/src/public/javascripts/services/server.js @@ -12,9 +12,10 @@ function getHeaders() { // headers need to be lowercase because node.js automatically converts them to lower case // so hypothetical protectedSessionId becomes protectedsessionid on the backend + // also avoiding using underscores instead of dashes since nginx filters them out by default return { - protected_session_id: protectedSessionId, - source_id: glob.sourceId + 'trilium-protected-session-id': protectedSessionId, + 'trilium-source-id': glob.sourceId }; } diff --git a/src/routes/routes.js b/src/routes/routes.js index fce2c078e..01d4dbcd5 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -66,7 +66,7 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio router[method](path, ...middleware, async (req, res, next) => { try { const result = await cls.init(async () => { - cls.namespace.set('sourceId', req.headers.source_id); + cls.namespace.set('sourceId', req.headers['trilium-source-id']); protectedSessionService.setProtectedSessionId(req); if (transactional) { diff --git a/src/services/protected_session.js b/src/services/protected_session.js index c698553b8..3c18a3956 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -15,7 +15,7 @@ function setDataKey(decryptedDataKey) { } function setProtectedSessionId(req) { - cls.namespace.set('protectedSessionId', req.headers.protected_session_id); + cls.namespace.set('protectedSessionId', req.headers['trilium-protected-session-id']); } function getProtectedSessionId() {