*/
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}`;
const [stat, data] = await this._readFileInfo(metaFilePath);
if (!stat) {
- return;
+ return added;
}
const lineBreakRE = /\r\n|\n|\r/;
const result = headerParseRE.exec(line);
const { groups: header } = result;
res.setHeader(header.name, header.value);
+ added = true;
}
});
+ return added;
}
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 });
});
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: <https://example.com/>; rel="relation"
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