break;
}
const suffix = Enum.EncodingTypeSuffix[encoding];
- if (suffix) {
- const encodedFilePath = `${filePath}${suffix}`;
- const [ encodedStat, encodedData ] = await this._readFileInfo(encodedFilePath);
- if (encodedStat) {
- ([ stat, data ] = [ encodedStat, encodedData ]);
- ctx.selectedEncoding = encoding;
- Dingus.addEncodingHeader(res, encoding);
- res.setHeader(Enum.Header.Vary, Enum.Header.AcceptEncoding);
- this.logger.debug(_scope, 'serving encoded version', { ctx, encodedFilePath });
- }
- break;
+ if (!suffix) {
+ this.logger.error(_scope, 'supported encoding missing mapped suffix', { ctx, encoding });
+ continue;
+ }
+ const encodedFilePath = `${filePath}${suffix}`;
+ const [ encodedStat, encodedData ] = await this._readFileInfo(encodedFilePath);
+ if (encodedStat) {
+ ([ stat, data ] = [ encodedStat, encodedData ]);
+ ctx.selectedEncoding = encoding;
+ Dingus.addEncodingHeader(res, encoding);
+ res.setHeader(Enum.Header.Vary, Enum.Header.AcceptEncoding);
+ this.logger.debug(_scope, 'serving encoded version', { ctx, encodedFilePath });
}
+ break;
}
const lastModifiedDate = new Date(stat.mtimeMs);
await dingus.serveFile(req, res, ctx, directory, fileName);
assert(res.end.called);
});
+ it('handles misconfigured encoding', async function () {
+ Enum.EncodingType.Flarp = 'flarp';
+ req._headers[Enum.Header.AcceptEncoding] = 'flarp, gzip';
+ await dingus.serveFile(req, res, ctx, directory, fileName);
+ delete Enum.EncodingType.Flarp;
+ assert(res.end.called);
+ });
}); // serveFile
describe('renderError', function () {