Repository navigation
fix(api): accept a document ETag with a compression suffix in If-Match - #759
Conversation
A proxy that compresses the response appends the content coding to a strong ETag. The bundled Caddy gateway (encode gzip) turns "<hash>-<meta>" into "<hash>-<meta>-gzip", and a client that sent that tag back in If-Match got 400 BAD_REQUEST. parseEntityTag now accepts one gzip, br, zstd or deflate suffix (any case) after the meta tag and drops it, so If-Match reads the same content hash and If-None-Match compares the same whole tag. A suffix without a meta tag, an empty, unknown or repeated suffix stay invalid.
There was a problem hiding this comment.
ℹ️ No critical issues. One suggestion on the new gateway spec.
Reviewed changes
parseEntityTagaccepts one coding suffix —if_match_hash.gonow splits the segment after the meta tag and acceptsgzip,br,zstd,deflatein any case, dropping the suffix from both the returned content hash and the whole tag. Unknown, empty and repeated suffixes, and a suffix with no meta tag, stay invalid.- Both preconditions share the change —
ifMatchHash(doc PATCH and doc PUT by-path) reads the same content hash, andetagMatches(both document GETs) compares the unsuffixed tag. Caddy appends the coding only to strong ETags and strips it fromIf-None-Match, so the suffix only reaches the API onIf-Match; tolerating it on the read side too is consistent with the PR's stated contract. - Unit coverage —
if_match_hash_test.goadds accept/reject tables forIf-MatchandIf-None-Match, including upper-case, weak, bare, stale and malformed shapes. - API-level e2e —
doc_content_hash_test.gocovers the suffixed current tag (200), a stale suffixed tag (412VERSION_CONFLICT) and a suffixedIf-None-Match(304). - Gateway-level spec —
etag-through-gateway.feature/.spec.tsread a compressed document through Caddy and round-trip its ETag intoIf-Match, following themanaged-copies.spec.tsprefix and cleanup conventions.
Verified locally: the handler unit tests pass, go vet ./test/e2e/ compiles the new e2e test, gofmt -l is clean. I also checked Caddy's encode handler source: it appends -<encodingName> to strong ETags and strips it from If-None-Match only, which matches the premise. No security change — If-Match already accepted a bare content hash, so ignoring the coding leaves the precondition no weaker.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the one commit since the prior pullfrog review (df22eb0 → 523fc79), which replaces the gateway spec's vacuous ETag check with a real assertion.
- Gateway spec now proves the coding suffix —
apps/e2e/tests/docs/etag-through-gateway.spec.tsrequires the document read'sETagto match"<64-hex hash>-<16-hex meta>-gzip"instead of merely being truthy, so the spec fails on a stack where the gateway does not append the content coding — the gap the prior review flagged.
I checked the two external contracts the assertion rests on. Playwright 1.64.1's APIRequestContext.fetch seeds accept-encoding: gzip,deflate,br, overwrites it with the spec's gzip, and exposes response.rawHeaders untouched (only the body is decompressed), so read.headers().etag is the raw suffixed tag. Caddy's encode handler rewrites a strong ETag to <tag>-<encoding> only when it actually encodes, and all three bundled Caddyfiles enable gzip alone, so -gzip is the only suffix this stack can produce. docETag is a 64-hex content hash plus a 16-hex meta tag, matching the pattern.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
Fixes a
400on document writes that send back the ETag they received, when the request goes through the bundled gateway. Found while testing the next parts of #747 against the full stack; it is onmastersince #751.What went wrong
encode gzipin the Caddyfiles). Caddy appends the content coding to a strong ETag, so a document's"<hash>-<meta>"reaches the client as"<hash>-<meta>-gzip".If-Match.-, so it answered400 BAD_REQUEST("If-Match must be a document content hash or ETag…").If-None-Matchwas not affected through the gateway, because Caddy removes the suffix from that header itself. The API tests did not catch this because they talk to the API directly.The fix
parseEntityTagaccepts one content-coding suffix after the meta tag (gzip,br,zstdordeflate, any case) and drops it.If-Matchreads the same content hash as before, andIf-None-Matchcompares the same whole tag, with or without the suffix.Still rejected: a suffix without a meta tag (
<hash>-gzip), an unknown suffix, an empty suffix and two suffixes.If-Matchanswers400for those as before.No change to the ETag the API sends, to the gateway config or to any client.
Type of Change
Testing
services/api, CI's commands in a Linux container: unit tests with-raceand./test/e2e/...pass.if_match_hash_test.go: table cases for each accepted coding, upper case, weak and bare forms, and each rejected shape.test/e2e/doc_content_hash_test.go: a write with the suffixed tag succeeds, a stale suffixed tag gets412 VERSION_CONFLICT, andIf-None-Matchwith the suffixed tag gets304.apps/e2e: newtests/docs/etag-through-gateway.spec.tsreads a document through the gateway and sends the returned ETag back inIf-Match. It passes on a stack built from this branch. A direct request with the-gziptag gave400onmasterand gives200here.tests/docsandtests/realtime, chromium) on that stack: 215 passed, 6 skipped, 1 failed. The failure isdocs.spec.ts:640(edit own comment, usesControl+aon macOS), which fails the same way onmaster.Checklist