routing.headers cannot set Cache-Control on static assets
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 56/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend
Hướng nghiên cứu
Start by reading headerMiddleware in dist/runtime/routing.mjs, then inspect stampClientAssetCachePolicy and the routing runtime tests. Reproduce the CSS and JS behavior with vp build and vp preview, and check how the fix affects 404 responses. Done means the acceptance checklist passes in preview and Cloudflare deploy, with tests and docs covering the 404 policy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
routing.headers cannot set Cache-Control on static assets
What happens
With Void 1.1.12 (the runtime code is the same in 1.2.1), this rule has no effect on static assets:
routing: {
headers: {
'/assets/*': ['Cache-Control: public, max-age=31536000, immutable'],
},
},
A CSS file, a font or an image under /assets/ still answers cache-control: public, max-age=0, must-revalidate. Other headers in the same rule, such as X-Robots-Tag, do arrive.
The rule also makes JavaScript worse. stampClientAssetCachePolicy removes immutableFiles for every chunk an authored Cache-Control pattern matches. So JS chunks lose the built-in immutable policy, and the authored policy never applies either.
The docs say the opposite should happen. guide/edge/headers.md says "User-defined Cache-Control overrides the built-in default", and guide/edge/static-assets.md suggests routing.headers for CSS and other assets.
Cause
headerMiddleware in dist/runtime/routing.mjs runs after next() and assigns a new response:
const headers = new Headers(c.res.headers);
for (const [name, value] of matched) headers.set(name, value);
c.res = new Response(c.res.body, { headers, status: c.res.status, statusText: c.res.statusText });
Hono's set res copies every header of the previous #res onto the new response, except content-type and set-cookie. The previous response is the asset binding's response, which carries cache-control: public, max-age=0, must-revalidate. That value overwrites the authored one. Headers the old response lacks, such as X-Robots-Tag, survive, which hides the bug.
Reproduce
- In a static Void app with
output: 'static', add the rule above. - Run
vp build, thenvp preview. - Run
curl -s -D - -o /dev/null http://127.0.0.1:<port>/assets/<any>.css. The response showscache-control: public, max-age=0, must-revalidate. - Request a JS chunk the same way. It now also shows
max-age=0, must-revalidate, where it showedimmutablebefore the rule was added.
Fix we apply locally
Clear the context's response before you assign the new one, so Hono has nothing to merge:
const response = new Response(c.res.body, { headers, status: c.res.status, statusText: c.res.statusText });
c.res = void 0;
c.res = response;
Aureum carries this as patches/void.patch.
Also worth deciding
Header rules apply to every status. With the fix in place, /assets/missing.css answers 404 with immutable, so a browser can cache the 404 for a year. A deploy that briefly serves new HTML from one version and assets from another could leave a visitor with a stylesheet that stays broken. Consider applying authored Cache-Control to successful responses only, or document that it applies to every status.
Acceptance checklist
- A
routing.headersrule that setsCache-Controlfor/assets/*reaches CSS, font and image responses invp previewand in a Cloudflare deploy. - JS chunks under the same pattern answer with the authored
Cache-Control. - Pages and other paths the rule does not match keep their default
Cache-Control. - A test in the routing runtime covers an authored header that the asset response already carries.
- The docs state whether authored
Cache-Controlapplies to 404 responses.
- Ngôn ngữ chính
- TypeScript
- Star
- 580
- Fork
- 56
- Merge trung bình
- 8 giờ 36 phút
- Pull request đã merge (30 ngày)
- 110
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của voidzero-dev/void
-
Static Cloudflare deploy ignores `cloudflare.assets.html_handling`Có thể đã có người làm @0froq đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
voidzero-dev/void#580 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`void/log` serializes `Error` fields as `{}`, losing message and stackCó thể đã có người làm @RaphaelFakhri đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
voidzero-dev/void#577 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
vp build / void deploy exit 0 when a page fails to prerender, and the page is silently missingĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
voidzero-dev/void#576 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dev: `better-auth/client/plugins` fails to resolve when auth is enabled (the `better-auth/client` alias matches it as a prefix)Có thể đã có người làm @MaxtuneLee đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
voidzero-dev/void#565 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
prepareDeployArtifact omits worker.vars that the CLI managed deploy includesCó thể đã có người làm @dvkam đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
voidzero-dev/void#529 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/void
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
awslabs/visual-asset-management-system#804 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
restatedev/sdk-typescript#813 ·
-
bug desktop P1 session XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Merit-Systems/x402scan#1312 ·
-
type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/apiops-cli#331 ·
Maintainer thường phản hồi trong vòng 3 ngày