fix(http): a handler-set ETag array is still the handler's (CARD-15)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 33s

With `etag: true`, `tagged()` only recognised a handler ETag given as a
string. Given as an array, it compared If-None-Match against the body's
computed tag while sending the handler's array, so a client revalidating
with the tag it was sent got a 200 instead of a 304, and two ETag values
went on the wire.

ETag is single-valued, so the last value of an array wins, as a repeated
`setHeader` would. It is sent alone and drives the comparison.

Found in the pre-freeze integrated review.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-24 13:55:06 -05:00
1 parent cdef95ffcb
commit 3efe049bb5
2 files changed
+18 -2

No files matched your search

+4 -2
View File
@@ -191,8 +191,10 @@ function tagged(
): Buffered {
const key = findHeader(result.headers, 'etag');
const existing = key === undefined ? undefined : result.headers[key];
const etag = typeof existing === 'string' ? existing : bodyEtag(result.body);
const headers = key === undefined ? { ...result.headers, etag } : result.headers;
// ETag is single-valued: from an array, the last value wins, as a repeated `setHeader` would.
const own = Array.isArray(existing) ? existing[existing.length - 1] : existing;
const etag = own ?? bodyEtag(result.body);
const headers = { ...result.headers, [key ?? 'etag']: etag };
if (isNotModified(req.headers, etag)) return bodyless({ kind: 'buffered', status: 304, headers, body: '' });