From: Justin Wind Date: Tue, 14 Nov 2023 18:48:12 +0000 (-0800) Subject: log a little less about static meta headers X-Git-Tag: v2.0.1~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=88c98d0981e4822d4f054ad822a6fa69614deecc;p=squeep-api-dingus log a little less about static meta headers --- diff --git a/lib/dingus.js b/lib/dingus.js index d4af0e1..0a5f9d8 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -520,8 +520,8 @@ class Dingus { */ async _serveFileMetaHeaders(res, directory, fileName) { const _scope = _fileScope('_serveFileMetaHeaders'); - this.logger.debug(_scope, 'called', { directory, fileName }); + let added = false; const metaPrefix = '.'; const metaSuffix = '.meta'; const metaFileName = `${metaPrefix}${fileName}${metaSuffix}`; @@ -529,7 +529,7 @@ class Dingus { const [stat, data] = await this._readFileInfo(metaFilePath); if (!stat) { - return; + return added; } const lineBreakRE = /\r\n|\n|\r/; @@ -542,8 +542,10 @@ class Dingus { const result = headerParseRE.exec(line); const { groups: header } = result; res.setHeader(header.name, header.value); + added = true; } }); + return added; } @@ -636,7 +638,7 @@ class Dingus { res.setHeader(Enum.Header.CacheControl, 'public'); if (this.staticMetadata) { - await this._serveFileMetaHeaders(res, directory, fileName); + ctx.metaHeaders = await this._serveFileMetaHeaders(res, directory, fileName); } this.logger.debug(_scope, 'serving file', { filePath, contentType }); diff --git a/test/lib/dingus.js b/test/lib/dingus.js index 5690dcf..8913436 100644 --- a/test/lib/dingus.js +++ b/test/lib/dingus.js @@ -707,8 +707,9 @@ describe('Dingus', function () { }); it('covers no meta file', async function() { dingus._readFileInfo.resolves([null, null]); - await dingus._serveFileMetaHeaders(res, directory, fileName); + const result = await dingus._serveFileMetaHeaders(res, directory, fileName); assert(!res.setHeader.called); + assert.strictEqual(result, false); }); it('adds extra headers', async function () { dingus._readFileInfo.resolves([{}, Buffer.from(`Link: ; rel="relation" @@ -717,8 +718,9 @@ X-Folded-Header: data the fold Content-Type: image/sgi `)]); - await dingus._serveFileMetaHeaders(res, directory, fileName); + const result = await dingus._serveFileMetaHeaders(res, directory, fileName); assert(res.setHeader.called); + assert.strictEqual(result, true); }); }); // _serveFileMetaHeaders