walkor / walkor/workerman

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

Open
#1,120 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
11.6k
Forks
2.2k
Avg merge
11h 30m
Merged PRs (30d)
3

Description

目前上传未知大小的流式数据,服务端会报 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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.