fix(http): a handler-set ETag array is still the handler's (CARD-15)
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:
2 files changed
+18
-2
No files matched your search
+4
-2
@@ -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: '' });
|
||||
|
||||
|
||||
Reference in new issue
Block a user