Skip to content

feat: ETag/304 caching on GET /api/tenants (#946) - #1052

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Vicistar-V:feat/etag-tenants-946
Jul 29, 2026
Merged

feat: ETag/304 caching on GET /api/tenants (#946)#1052
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Vicistar-V:feat/etag-tenants-946

Conversation

@Vicistar-V

Copy link
Copy Markdown

Summary

Implements strong ETag / 304 Not Modified caching on GET /api/tenants as specified in issue #946.

Changes

src/middleware/etag.ts

Extended etagMiddleware to honour a pre-set ETag response header while still evaluating If-None-Match through 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-comparison fresh module incorrectly return 304 for W/"..." tags.

src/routes/tenants.ts

The 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.ts

Added focused ETag/304 integration tests:

  • 200 with a strong ETag header on first fetch
  • 304 when If-None-Match matches exactly
  • 200 when If-None-Match doesn't match
  • 200 (not 304) for a weak tag — strong comparison only
  • 401 for unauthenticated GET
  • 500 propagation for repository errors

docs/tenants-api.md

Added GET /api/tenants section documenting ETag format, If-None-Match semantics, 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

- 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
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit b2641cb into CalloraOrg:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Great work, this looks good. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ETag / 304 caching on /api/tenants [b#081]

2 participants