Skip to content

feat: ETag/304 listings#573

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
AugistineCreates:task/listings-etag
Jun 29, 2026
Merged

feat: ETag/304 listings#573
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
AugistineCreates:task/listings-etag

Conversation

@AugistineCreates

Copy link
Copy Markdown
Contributor

this pr closes #515

Description

This PR implements ETag/304 conditional GET caching on the /api/apis listings endpoint. When a client fetches the listings, the backend generates a weak ETag header based on the response body. On subsequent requests, if the client sends the ETag in the If-None-Match header and the content hasn't changed, the server responds with a 304 Not Modified status code and an empty body, saving bandwidth and improving performance on hot listings.

Key Changes

  • [NEW] etag.ts: A reusable Express middleware that calculates a weak ETag (SHA-1 base64 hash) for GET and HEAD responses and compares it against the incoming If-None-Match header.
  • [MODIFY] apis.ts: Integrated etagMiddleware into the GET / route of the APIs listings router.
  • [NEW] etag.test.ts: Unit tests for the ETag middleware covering ETag generation, matching If-None-Match (with and without the weak W/ prefix), non-matching headers, and non-GET requests.
  • [MODIFY] apis.registration.test.ts: Integration tests verifying that the /api/apis endpoint returns the ETag header and correctly responds with 304 Not Modified when requested conditionally.

Verification

The ETag middleware and the listings integration were verified using native Node.js TypeScript execution (node --experimental-strip-types), confirming that all test cases pass successfully:

  1. Weak ETag generation: Verified weak ETag format (W/"...").
  2. Successful ETag Header: Verified that first GET request returns 200 with the ETag header set.
  3. Conditional GET (304): Verified that sending matching If-None-Match returns 304 with an empty body.
  4. Weak ETag Comparison: Verified that the middleware correctly matches ETags even when the client strips the W/ prefix.
  5. No-op on write methods: Verified that POST requests do not set an ETag header.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@AugistineCreates 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 01c75fe into CalloraOrg:main Jun 29, 2026
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/apis listings

2 participants