feat: ETag/304 caching on GET /api/tenants (#946) - #1052
Merged
greatest0fallt1me merged 1 commit intoJul 29, 2026
Conversation
- Pre-set strong ETag on GET /api/tenants from tenant data only,
so the tag is stable across requests that return the same list
regardless of volatile envelope fields (timestamp, requestId)
- Extend etagMiddleware to honour a pre-set ETag while still
evaluating If-None-Match via strong comparison (RFC 7232 §3.2),
preventing Express's built-in weak-comparison fresh module from
firing incorrectly on W/"..." tags
- Add focused ETag/304 tests to src/routes/tenants.test.ts:
- 200 with strong ETag header on first fetch
- 304 Not Modified when If-None-Match matches
- 200 when If-None-Match does not match
- 200 (not 304) for weak ETag — strong comparison only
- 401 for unauthenticated GET
- 500 propagation for repository errors
- Document GET /api/tenants caching behaviour in docs/tenants-api.md
Closes CalloraOrg#946
|
@Vicistar-V Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Great work, this looks good. Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements strong ETag / 304 Not Modified caching on
GET /api/tenantsas specified in issue #946.Changes
src/middleware/etag.tsExtended
etagMiddlewareto honour a pre-setETagresponse header while still evaluatingIf-None-Matchthrough our own strong-comparison logic (RFC 7232 §3.2). Previously, a pre-set ETag caused the middleware to skip all freshness evaluation entirely, letting Express's built-in weak-comparisonfreshmodule incorrectly return 304 forW/"..."tags.src/routes/tenants.tsThe
GET /handler now pre-sets the strong ETag from the tenant list data alone before wrapping it in the response envelope:ts
res.setHeader('ETag', generateETag(JSON.stringify(tenants)));
This makes the tag stable across consecutive fetches returning the same tenant state, regardless of volatile envelope fields (
timestamp,requestId) that change per request.src/routes/tenants.test.tsAdded focused ETag/304 integration tests:
ETagheader on first fetchIf-None-Matchmatches exactlyIf-None-Matchdoesn't matchdocs/tenants-api.mdAdded
GET /api/tenantssection documenting ETag format,If-None-Matchsemantics, comparison rules, and a curl example.Testing
npx jest --forceExit --testPathPattern="etag|tenants" --no-coverage
80/80 tests pass across all 4 suites.
Closes #946