/assets/uploads/<name> 的 200 与 206 响应中,Content-Length 和 Accept-Ranges 各出现两次。
/assets/uploads/<name>
Content-Length
Accept-Ranges
curl -s -D - -o /dev/null http://127.0.0.1:8787/assets/uploads/<name>.svg
响应头(节选,未删改):
HTTP/1.1 200 OK Content-Type: image/svg+xml X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none'; sandbox Cache-Control: public, max-age=31536000, immutable Access-Control-Allow-Origin: * Accept-Ranges: bytes Accept-Ranges: bytes Content-Length: 111 Content-Length: 111 Connection: keep-alive Last-Modified: Mon, 23 Nov 2026 09:21:50 GMT
Range 请求同样重复:
curl -s -D - -o /dev/null -H 'Range: bytes=0-3' http://127.0.0.1:8787/assets/uploads/<name>.svg # Accept-Ranges ×2、Content-Length ×2、Content-Range ×1
每个响应只发送一个 Content-Length 和一个 Accept-Ranges。
app/Controller/MediaController.php:22-43 手动设置了这两个头:
app/Controller/MediaController.php:22-43
$headers = [ ... 'Access-Control-Allow-Origin' => '*', 'Accept-Ranges' => 'bytes', ]; ... return (new Response(200, $headers + ['Content-Length' => (string) $length]))->withFile($path);
而 Workerman 在编码文件响应时会再次写入(vendor/workerman/workerman/src/Protocols/Http.php:405-417):
vendor/workerman/workerman/src/Protocols/Http.php:405-417
$response->withHeaders([ 'Content-Length' => $bodyLen, 'Accept-Ranges' => 'bytes', ]);
withHeaders() 是追加语义,于是同名头重复。Content-Range 之所以只有一个,是因为框架随后用 header() 覆盖了。
withHeaders()
Content-Range
header()
从 MediaController::file() 里删掉 Content-Length、Accept-Ranges(以及 Content-Range),交给 withFile($path, $offset, $count) 自行生成;Content-Type、CSP、CORS、Cache-Control 保留。
MediaController::file()
withFile($path, $offset, $count)
Content-Type
main
No dependencies set.
The note is not visible to the blocked user.
现象
/assets/uploads/<name>的 200 与 206 响应中,Content-Length和Accept-Ranges各出现两次。复现步骤
响应头(节选,未删改):
Range 请求同样重复:
期望
每个响应只发送一个
Content-Length和一个Accept-Ranges。影响
Content-Length;HTTP/2(RFC 9113 §8.1)对重复Content-Length更严格,可能被判为 malformed。原因定位
app/Controller/MediaController.php:22-43手动设置了这两个头:而 Workerman 在编码文件响应时会再次写入(
vendor/workerman/workerman/src/Protocols/Http.php:405-417):withHeaders()是追加语义,于是同名头重复。Content-Range之所以只有一个,是因为框架随后用header()覆盖了。修复建议
从
MediaController::file()里删掉Content-Length、Accept-Ranges(以及Content-Range),交给withFile($path, $offset, $count)自行生成;Content-Type、CSP、CORS、Cache-Control 保留。环境
main@ 01ede89(v1.1.0)