REPOSITORY CODING · HARD
Repair entity-tag strength and condition precedence
Weak entity tags must not satisfy If-Match, and If-Modified-Since must not override a present nonmatching If-None-Match. Repair both validation paths.
HTTP cachingHTTP cache semantics laboratory
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
Go · 80 minute session
- This offline HTTP cache workbench accepts operation freshness, variant, conditional or revalidate. Header names are ASCII case-insensitive and unique after normalization; values are trimmed without combining different request fields. No outbound HTTP request occurs. Times are nonnegative epoch seconds with requestTime <= responseTime <= now <= 2000000000.
- Freshness parses quoted Cache-Control commas and delta-seconds strictly. Shared caches prefer s-maxage to max-age; private caches use max-age. Otherwise use max(0, Expires-Date), with responseTime as absent Date. Current age is max(max(0,responseTime-Date),Age+responseTime-requestTime)+(now-responseTime). Fresh means storable, no no-cache directive and age strictly less than lifetime. no-store disables storage; private disables shared storage. Duplicate directives are errors.
- Variant returns a deterministic JSON-string key of sorted unique lowercased Vary fields, each [name,present,value], preserving absence versus an empty header. Vary * is never reusable.
- Conditional evaluates If-Match with strong entity-tag comparison first; If-None-Match uses weak comparison and takes precedence over If-Modified-Since even when it does not match. Matching If-None-Match gives 304 for GET/HEAD and 412 otherwise. Date conditions apply only to GET/HEAD. Wildcards honor representation existence. Entity tags can contain commas.
- Revalidation merges a 304 into a stored 200, retaining the original status and body, replacing end-to-end metadata, requiring any supplied ETag to weakly match the stored validator. Remove fixed hop-by-hop fields, content-length and all Connection-nominated fields from both old and new headers. Return the merged representation or a stable error.