Skip to content

fix(http): handle oversized response header in FileCache send path (minimal alt to #823) - #866

Merged
ithewei merged 1 commit into
masterfrom
fix/filecache-header-overflow
Aug 6, 2026
Merged

fix(http): handle oversized response header in FileCache send path (minimal alt to #823)#866
ithewei merged 1 commit into
masterfrom
fix/filecache-header-overflow

Conversation

@ithewei

@ithewei ithewei commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Minimal fix for the FileCache oversized-header problem that #823 targets, without #823's larger rework (LRU/concurrency/config changes).

Problem

FileCache reserves a fixed block before the file content so header+body can be sent as one buffer. prepend_header() returned void and silently did nothing when the header exceeded the reserve (1K) — the file was then served with a missing/garbage header, and the caller couldn't tell.

Fix

  • Bump the reserve 1K → 4K so the fast single-buffer path is taken for normal responses (incl. long cookies / CORS / CSP headers).
  • prepend_header() now returns bool. When the header still doesn't fit, HttpHandler falls back to sending the header first, then the file content (via the existing SEND_BODY state; pResp->content already points at fc->filebuf) — correct instead of silently broken.

Verified

  • normal static file serve: unchanged (fast path)
  • response with a >4K header: both the full header and the intact file body are delivered (two-part send)
  • a 5000-byte file: served intact

Relation to #823

This is a smaller, targeted alternative. It fixes the actual correctness bug (silent header drop) with ~20 lines and no changes to LRU / cache concurrency / configurability. If instance-level configurable reserve/size is wanted later, that can be a separate, focused change.

FileCache reserves a fixed block before the file content so header+body
can be sent as one buffer. prepend_header() previously returned void and
silently did nothing when the header exceeded the reserve (1K): the file
was then served with a missing/garbage header and the caller had no way to
know.

- Bump the reserve from 1K to 4K (covers normal responses incl. long
  cookies / CORS / CSP headers), so the fast single-buffer path is taken
  in practice.
- prepend_header() now returns bool. When the header still doesn't fit,
  HttpHandler falls back to sending the header first, then the file
  content (pResp->content already points at fc->filebuf) via the existing
  SEND_BODY state -- correct instead of silently broken.

Verified: normal static file serve unchanged; a response with a >4K header
still delivers both the full header and the intact file body.

Minimal alternative to #823 (avoids its LRU/concurrency/config rework).
Copilot AI lite review requested due to automatic review settings August 6, 2026 04:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ithewei
ithewei merged commit 1965221 into master Aug 6, 2026
12 checks passed
@ithewei
ithewei deleted the fix/filecache-header-overflow branch August 6, 2026 04:26
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.

2 participants