Skip to content

Commit

Permalink
task: enclose ETag in double quotes. (#3385)
Browse files Browse the repository at this point in the history
According to the
[RFC](https://www.rfc-editor.org/rfc/rfc7232#section-2.3) Etags should
be enclosed in double quotes. This PR makes sure we do actually wrap it
in double quotes
  • Loading branch information
Christopher Kolstad committed Mar 24, 2023
1 parent 59ff86c commit 49fbf4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/lib/routes/client-api/feature.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import memoizee from 'memoizee';
import { Response } from 'express';
// eslint-disable-next-line import/no-extraneous-dependencies
import hasSum from 'hash-sum';
import hashSum from 'hash-sum';
// eslint-disable-next-line import/no-extraneous-dependencies
import { diff } from 'deep-object-diff';
import Controller from '../controller';
Expand Down Expand Up @@ -318,8 +318,8 @@ export default class FeatureController extends Controller {
const revisionId = await this.eventService.getMaxRevisionId();

// TODO: We will need to standardize this to be able to implement this a cross languages (Edge in Rust?).
const queryHash = hasSum(query);
const etag = `${queryHash}:${revisionId}`;
const queryHash = hashSum(query);
const etag = `"${queryHash}:${revisionId}"`;
return { revisionId, etag, queryHash };
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/e2e/api/client/feature.optimal304.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ test('returns calculated hash', async () => {
.get('/api/client/features')
.expect('Content-Type', /json/)
.expect(200);
expect(res.headers.etag).toBe('ae443048:19');
expect(res.body.meta.etag).toBe('ae443048:19');
expect(res.headers.etag).toBe('"ae443048:19"');
expect(res.body.meta.etag).toBe('"ae443048:19"');
});

test('returns 304 for pre-calculated hash', async () => {
return app.request
.get('/api/client/features')
.set('if-none-match', 'ae443048:19')
.set('if-none-match', '"ae443048:19"')
.expect(304);
});

Expand All @@ -149,6 +149,6 @@ test('returns 200 when content updates and hash does not match anymore', async (
.set('if-none-match', 'ae443048:19')
.expect(200);

expect(res.headers.etag).toBe('ae443048:20');
expect(res.body.meta.etag).toBe('ae443048:20');
expect(res.headers.etag).toBe('"ae443048:20"');
expect(res.body.meta.etag).toBe('"ae443048:20"');
});

0 comments on commit 49fbf4a

Please sign in to comment.