Skip to content

Commit

Permalink
fix: etag support RFC 9110 standard (#9077)
Browse files Browse the repository at this point in the history
ETag must be in double quotes based on standard. Fixing it.

```
If-None-Match: "<etag_value>"
  • Loading branch information
sjaanus authored Jan 10, 2025
1 parent 67068af commit fda2252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test('should get 304 if asked for latest revision', async () => {
const currentRevisionId = body.revisionId;

await app.request
.set('If-None-Match', currentRevisionId)
.set('If-None-Match', `"${currentRevisionId}"`)
.get('/api/client/delta')
.expect(304);
});
Expand All @@ -123,7 +123,7 @@ test('should return correct delta after feature created', async () => {

const { body: deltaBody } = await app.request
.get('/api/client/delta')
.set('If-None-Match', currentRevisionId)
.set('If-None-Match', `"${currentRevisionId}"`)
.expect(200);

expect(deltaBody).toMatchObject({
Expand Down Expand Up @@ -162,7 +162,7 @@ test('archived features should not be returned as updated', async () => {

const { body: deltaBody } = await app.request
.get('/api/client/delta')
.set('If-None-Match', currentRevisionId)
.set('If-None-Match', `"${currentRevisionId}"`)
.expect(200);

expect(deltaBody).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export default class ClientFeatureToggleDeltaController extends Controller {
const query = await this.resolveQuery(req);
const etag = req.headers['if-none-match'];

const currentSdkRevisionId = etag ? Number.parseInt(etag) : undefined;
const sanitizedEtag = etag ? etag.replace(/^"(.*)"$/, '$1') : undefined;

const currentSdkRevisionId = sanitizedEtag
? Number.parseInt(sanitizedEtag)
: undefined;

const changedFeatures =
await this.clientFeatureToggleService.getClientDelta(
Expand All @@ -107,7 +111,7 @@ export default class ClientFeatureToggleDeltaController extends Controller {
return;
}

res.setHeader('ETag', changedFeatures.revisionId.toString());
res.setHeader('ETag', `"${changedFeatures.revisionId}"`);
this.openApiService.respondWithValidation(
200,
res,
Expand Down

0 comments on commit fda2252

Please sign in to comment.