Skip to content

refactor(httputil): consolidate conditional-request serving#340

Merged
alecthomas merged 1 commit into
mainfrom
refactor/consolidate-conditional-serving
Jun 22, 2026
Merged

refactor(httputil): consolidate conditional-request serving#340
alecthomas merged 1 commit into
mainfrom
refactor/consolidate-conditional-serving

Conversation

@alecthomas

Copy link
Copy Markdown
Collaborator

ETag/If-Match/If-None-Match handling was duplicated across the apiv1 and git handlers and missing entirely from the generic caching handler builder.

Add ServeCacheHit, ServeCacheStat and CheckConditionals to httputil and route apiv1, the handler builder, and git snapshots through them. This fixes a latent bug where builder-based strategies (github-releases, host, hermit, proxy, artifactory) ignored conditional requests on cache hits, and removes git's upward dependency on the strategy package for CheckConditionals.

ETag/If-Match/If-None-Match handling was duplicated across the apiv1 and git handlers and missing entirely from the generic caching handler builder.

Add ServeCacheHit, ServeCacheStat and CheckConditionals to httputil and route apiv1, the handler builder, and git snapshots through them. This fixes a latent bug where builder-based strategies (github-releases, host, hermit, proxy, artifactory) ignored conditional requests on cache hits, and removes git's upward dependency on the strategy package for CheckConditionals.
@alecthomas alecthomas requested a review from a team as a code owner June 22, 2026 04:51
@alecthomas alecthomas requested review from inez and removed request for a team June 22, 2026 04:51
@alecthomas alecthomas enabled auto-merge (squash) June 22, 2026 04:51
@alecthomas alecthomas merged commit 8aa8bf6 into main Jun 22, 2026
8 checks passed
@alecthomas alecthomas deleted the refactor/consolidate-conditional-serving branch June 22, 2026 04:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c91ed13ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +55 to +57
maps.Copy(w.Header(), headers)
if status := CheckConditionals(r, headers.Get(ETagHeader)); status != 0 {
w.WriteHeader(status)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear cached Content-Length on 412 conditional hits

When a cached object has Content-Length and an If-Match request fails, this branch writes a 412 after copying the object's headers but sends no body. Unlike 304, Go does not suppress Content-Length for 412 responses, so clients can hang or fail with an unexpected EOF waiting for the advertised cached-object bytes. Strip or replace entity headers before writing the 412 response.

Useful? React with 👍 / 👎.

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.

1 participant