Bug #79013 [Com]: Content-Length missing when posting a curlFile with curl
| From: | andrewscaya at yahoo dot ca | Date: | Thu, 13 Feb 2020 18:53:38 +0000 |
| Subject: | Bug #79013 [Com]: Content-Length missing when posting a curlFile with curl | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225568@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79013&edit=1
ID: 79013
Comment by: andrewscaya at yahoo dot ca
Reported by: christian at klemmer dot io
Summary: Content-Length missing when posting a curlFile with
curl
Status: Not a bug
Type: Bug
Package: cURL related
Operating System: debian 10.2
PHP Version: 7.4.1
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I can confirm that when PHP 7.4 reverts to using chunked file uploads, PHP scripts that were working
fine on PHP 7.2 or 7.3, no longer post anything to the server.
EXAMPLE SCRIPT
--------------
/* http://example.com:
<?php var_dump($_FILES); ?>
*/
// Create a cURL handle
$ch = curl_init('http://example.com/index.php');
$cfile = curl_file_create('example.txt','text/plain','test_name');
// Assign POST data
$postdata = ['file' => $cfile];
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
// Execute the handle
echo curl_exec($ch);
ACTUAL RESULTS
--------------
Using cURL 7.68.0 and PHP 7.3
-----------------------------
$_FILES:
/srv/www/index.php:5:
array (size=1)
'file' =>
array (size=5)
'name' => 'test_name' (length=9)
'type' => 'text/plain' (length=10)
'tmp_name' => '/tmp/php69gfI5' (length=14)
'error' => 0
'size' => 25
POST /index.php HTTP/1.1
Content-Type: multipart/form-data; boundary=------------------------63a96cbe43cf28f8
Content-Length: 212
Accept: */*
Host: example.com
Using cURL 7.68.0 and PHP 7.4
-----------------------------
$_FILES:
/srv/www/index.php:5:
array (size=0)
empty
POST /index.php HTTP/1.1
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------46680d0956db253f
Transfer-Encoding: chunked
Accept: */*
Host: example.com
EXPECTED RESULTS
----------------
Should be the same.
Previous Comments:
------------------------------------------------------------------------
[2020-01-24 13:11:41] cmb@php.net
For me, using current PHP-7.4 the test script outputs:
Linux, curl 7.64.0:
POST / HTTP/2
Host: example.com
Accept: */*
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=------------------------df0efab1e65ad7e7
Linux, curl 7.68.0:
POST / HTTP/2
Host: example.com
accept: */*
content-type: multipart/form-data; boundary=------------------------f55b79edfe19cb82
Windows, curl 7.67.0
POST / HTTP/2
Host: example.com
accept: */*
content-type: multipart/form-data; boundary=------------------------1e758282c5b98dfb
So obviously a bug in libcurl which has been fixed in the meantime.
------------------------------------------------------------------------
[2020-01-23 18:05:45] sdmarshall73 at gmail dot com
My apologies for the previous post ( and this one ). You did mention the files were being removed on
the remote side. Seems like the same issue I'm experiencing. I've voted on the bug and
I'll just follow this post. Please remove these comments if possible.
------------------------------------------------------------------------
[2020-01-23 17:10:05] sdmarshall73 at gmail dot com
Have you actually tested to see if the files are being received on the remote server? I have an
application that uploads files and the files aren't being received on the remote server when
using PHP7.4. I wanted to see if this bug is related before filing my own bug report.
------------------------------------------------------------------------
[2019-12-23 08:54:46] cmb@php.net
Thanks for reporting and digging into the details!
In my opinion, no longer sending a Content-Length header but
instead falling back to chunked transfer encoding is a bug at
least for PHP 7.3, where request #77711 has recently been
back-ported to[1]. For PHP 7.4, this change might be acceptable,
but would at least have to be documented.
However, while having a closer look at this issue, I've noticed
that the current implementation can't really work wrt.
curl_copy_handle()[2], what has to be addressed first, since fixing
that will result in a quite different implementation, which
renders the obvious trivial fix for this issue moot.
> So it seems to be a combination of several CURL versions with
> PHP 7.4
To clarify, this issue affects only libcurl >= 7.56.0, since older
versions still use the "classic" file upload.
[1] <http://git.php.net/?p=php-src.git;a=commit;h=17a9f1401aeb35fe1e3657b38102a410d151d42f>
[2] <https://bugs.php.net/bug.php?id=79019>
------------------------------------------------------------------------
[2019-12-22 22:41:03] christian at klemmer dot io
And as addition tests with PHP 7.3.13 with different curl versions.
All result in the expected behaviour.
Ubuntu 19.10 - PHP 7.3.13 - CURL 7.65.3 (7.65.3-1ubuntu3):
-----------------------
POST / HTTP/2
Host: example.com
Accept: */*
Content-Length: 210
Content-Type: multipart/form-data; boundary=------------------------4d274c175c3e77e5
Debian 9.11 - PHP 7.3.13 - CURL 7.52.1 (7.52.1-5+deb9u9):
-----------------------
POST / HTTP/1.1
Host: example.com
Accept: */*
Content-Length: 210
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------5652b6f1c9e7a818
Debian 10.2 - PHP 7.3.13 - CURL 7.64.0 (7.64.0-4):
-----------------------
POST / HTTP/2
Host: example.com
Accept: */*
Content-Length: 210
Content-Type: multipart/form-data; boundary=------------------------0b86b20895500f64
So it seems to be a combination of several CURL versions with PHP 7.4
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79013
--
Edit this bug report at https://bugs.php.net/bug.php?id=79013&edit=1