Cannot stream request using CURLOPT_READFUNCTION without chunked encoding
オープン
まだ誰も着手していません。
Extension: curl
Feature
Status: Verified
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
Description
Consider this curl code in C:
int counter = 0;
size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
{
if (counter++ == 1) {
return 0;
}
ptr[0] = 'W';
ptr[1] = 'H';
ptr[2] = 'A';
ptr[3] = 'T';
return 4;
}
int main() {
CURL* handle = curl_easy_init();
CURLcode res;
curl_easy_setopt(handle, CURLOPT_URL, "http://localhost:9090");
curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(handle, CURLOPT_POST, 1);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, 4);
res = curl_easy_perform(handle);
curl_easy_cleanup(handle);
return 0;
}
That results in the following HTTP request
POST / HTTP/1.1
Host: localhost:9090
Accept: */*
Content-Length: 4
Content-Type: application/x-www-form-urlencoded
WHAT
When removing the CURLOPT_POSTFIELDSIZE options, the following request is issued:
POST /iserv/helloworld HTTP/1.1
Host: localhost:982
Accept: */*
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
WHAT
That is analogous to its PHP implementation:
$counter = 0;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:9090');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_READFUNCTION, static function ($ch, $fd, $length) use (&$counter) {
if ($counter++ > 0) {
return "";
}
return "WHAT";
});
$output = curl_exec($ch);
curl_close($ch);
However, PHP does not expose the constant CURLOPT_POSTFIELDSIZE, i.e. I have no option to tell curl the length of the request. As a result, I cannot stream a request body using CURLOPT_READFUNCTION without chunked encoding.
PHP Version
8.0.12
Operating System
Ubuntu 21.10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
PHP の CURLOPT_READFUNCTION に対する curl オプション処理と、欠落している CURLOPT_POSTFIELDSIZE バインディングから始め、次にそれらのエントリーポイントを libcurl の対応するオプションと比較します。issue に示されたリクエストを再現し、ストリーミングされる body が chunked encoding を使わずに長さを指定できることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, php
- 領域
- networking
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100