#1120·workerman

[Feature request?] Support Transfer-Encoding chunked with no Content-Length

Author: krissssCreated Aug 25, 2025Updated Aug 25, 2025

目前上传未知大小的流式数据,服务端会报 400 错误(HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n)。 发现原因是代码中做了 header 中必须有 Content-Length 的限制(Workerman\Protocols\Http::input 内)。 但是当上传未知大小的数据时,仅使用 Transfer-Encoding: chunked 是符合标准的。 希望支持下。

测试代码: 客户端:

php
$fp = fopen('php://temp', 'r+');
fwrite($fp, 'hello');
$response = \Symfony\Component\HttpClient\HttpClient::create()
    ->request('POST', 'http://127.0.0.1:8787/upload', [
        'body' => $fp
    ]);
dd($response->getStatusCode());

服务端:webman header 头信息打印(打印位置:Workerman\Protocols\Http::input):

txt
POST /upload HTTP/1.1\r\n
Host: 127.0.0.1:8787\r\n
Accept: */*\r\n
User-Agent: Symfony HttpClient (Curl)\r\n
Accept-Encoding: gzip\r\n
Transfer-Encoding: chunked\r\n
Content-Type: application/x-www-form-urlencoded