Cannot stream request using CURLOPT_READFUNCTION without chunked encoding
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.1k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
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
Hướng dẫn đóng góp
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.
Hướng nghiên cứu
Bắt đầu với phần xử lý tùy chọn curl của PHP cho CURLOPT_READFUNCTION và binding còn thiếu của CURLOPT_POSTFIELDSIZE, sau đó so sánh các entry point đó với các tùy chọn tương ứng của libcurl. Tái hiện request được nêu trong issue và xác minh rằng một body được truyền theo luồng có thể cung cấp độ dài của nó mà không sử dụng chunked encoding.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, php
- Lĩnh vực
- networking
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100