Bug #79013 [NEW]: Content-Length missing when posting a curlFile with curl
| From: | christian at klemmer dot io | Date: | Sat, 21 Dec 2019 16:19:44 +0000 |
| Subject: | Bug #79013 [NEW]: Content-Length missing when posting a curlFile with curl | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224462@lists.php.net to get a copy of this message | ||
From: christian at klemmer dot io
Operating system: debian 10.2
PHP version: 7.4.1
Package: cURL related
Bug Type: Bug
Bug description:Content-Length missing when posting a curlFile with curl
Description:
------------
When posting a curlFile with curl, I get different results with the same
code (and curlFile) if I run it with PHP 7.3 or PHP 7.4.
"Content-Length" is missing and instead replaced by "Transfer-Encoding:
chunked". I query an API which is behind an haproxy server. Missing
content-lenght seems to remove all files posted on their side.
Nevertheless I would've expected the same behaviour with PHP 7.4 running
with the same curl-version.
I'm using the deb.sury.org repository on a debian 10.2 server.
dpkg -l | grep curl
ii curl 7.64.0-4
ii libcurl3-gnutls:amd64 7.64.0-4
ii libcurl4:amd64 7.64.0-4
ii php7.3-curl
7.3.13-1+0~20191218.50+debian10~1.gbp23c2da
ii php7.4-curl
7.4.1-1+0~20191218.8+debian10~1.gbp21c50e
ii python3-pycurl 7.43.0.2-0.1
curl-information out of phpinfo (7.3 testenv and 7.4 testenv are exactly
the same):
cURL support enabled
cURL Information 7.64.0
Age 4
Features:
AsynchDNS Yes
CharConv No
Debug No
GSS-Negotiate No
IDN Yes
IPv6 Yes
krb4 No
Largefile Yes
libz Yes
NTLM Yes
NTLMWB Yes
SPNEGO Yes
SSL Yes
SSPI No
TLS-SRP Yes
HTTP2 Yes
GSSAPI Yes
KERBEROS5 Yes
UNIX_SOCKETS Yes
PSL Yes
HTTPS_PROXY Yes
MULTI_SSL No
BROTLI No
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap,
ldaps, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps,
telnet, tftp
Host x86_64-pc-linux-gnu
SSL Version OpenSSL/1.1.1d
ZLib Version 1.2.11
libSSH Version libssh2/1.8.0
Test script:
---------------
$filename = 'testfile.txt';
if(file_exists($filename) && is_file($filename) &&
(int)filesize($filename) > 0) {
try {
$ch = curl_init('https://example.com/')
or die('API down');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('test' => new
CurlFile($filename)));
curl_exec($ch);
$curlInfo = curl_getinfo($ch);
echo '<pre>'; print_r($curlInfo["request_header"]); echo
'</pre>';
curl_close($ch);
} catch(Exception $e) {
echo $e->getMessage();
}
}
Expected result:
----------------
With PHP 7.3.13:
POST / HTTP/2
Host: example.com
Accept: */*
Content-Length: 245
Content-Type: multipart/form-data;
boundary=------------------------c129897ae3ed733b
Actual result:
--------------
With PHP 7.4.1:
POST / HTTP/2
Host: example.com
Accept: */*
Transfer-Encoding: chunked
Content-Type: multipart/form-data;
boundary=------------------------ef5ab6d1e2455a47
--
Edit bug report at https://bugs.php.net/bug.php?id=79013&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79013&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79013&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79013&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79013&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79013&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79013&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79013&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79013&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79013&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79013&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79013&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79013&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79013&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79013&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79013&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79013&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79013&r=mysqlcfg