Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const etags = new Map();
const calculateSha = (handlers, absolutePath) =>
new Promise((resolve, reject) => {
const hash = createHash('sha1');
hash.update(path.extname(absolutePath));
hash.update('-');
const rs = handlers.createReadStream(absolutePath);
rs.on('error', reject);
rs.on('data', buf => hash.update(buf));
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## This is a markdown file
14 changes: 11 additions & 3 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,22 @@ test('allow symlinks by setting the option', async t => {
});

test('etag header is set', async t => {
const directory = 'single-directory';
const url = await getUrl({
renderSingle: true,
etag: true
});
const response = await fetch(`${url}/${directory}`);

let response = await fetch(`${url}/docs.md`);
t.is(response.status, 200);
t.is(
response.headers.get('etag'),
'"60be4422531fce1513df34cbcc90bed5915a53ef"'
);

response = await fetch(`${url}/docs.txt`);
t.is(response.status, 200);
t.is(
response.headers.get('etag'),
'"4e5f19df3bfe8db7d588edfc3960991aa0715ccf"'
'"ba114dbc69e41e180362234807f093c3c4628f90"'
);
});