php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53556 cURL returns wrong Content-Length after a redirect to a page without CL-header
Submitted: 2010-12-16 13:27 UTC Modified: 2013-02-18 00:34 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: michael dot moench at marktjagd dot de Assigned:
Status: No Feedback Package: HTTP related
PHP Version: 5.3SVN-2010-12-16 (SVN) OS: Ubuntu 10.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael dot moench at marktjagd dot de
New email:
PHP Version: OS:

 

 [2010-12-16 13:27 UTC] michael dot moench at marktjagd dot de
Description:
------------
I have an URL which will redirect me to a second, final URL. The first response contains a Content-Length-Header, the second does not. If I set the CURLOPT_FOLLOWLOCATION option, I would expect that the "download_content_length"-field from curl_getinfo contains the Content-Length of the final URL, in this case 0, but it contains the Content-Length of the first Response.

The first Response:

HTTP/1.1 302 Found
Date: Thu, 16 Dec 2010 11:39:31 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Location: http://productdata.download.affili.net/xxx
Set-Cookie: ASP.NET_SessionId=xxx; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html; charset=Windows-1252
Content-Length: 214

The Second Response:

HTTP/1.1 200 OK
Date: Thu, 16 Dec 2010 11:39:32 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment; filename=xxx.gz
Transfer-Encoding: chunked
Cache-Control: private
Content-Type: application/gzip



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-16 18:24 UTC] cataphract@php.net
This looks like a problem upstream.
 [2010-12-21 23:02 UTC] iliaa@php.net
-Status: Open +Status: Feedback
 [2010-12-21 23:02 UTC] iliaa@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-03-04 14:17 UTC] michael dot moench at marktjagd dot de
To reproduce this error you can use the following three scripts. index.php and hello.php are placed on an Apache-Webserver. If you call test.php it will load index.php, which returns a content-length of 3 and redirects to hello.php, which uses output-buffering and thus causes Apache to omit the content-length header. The result is that "download_content_length" returned by cURL is 3 instead of NULL or -1.
This might be a bug in libCurl though.

test.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://php.local.site/index.php");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "\ndownload_content_length => ".$info['download_content_length']."\n";
?>

index.php
<?php
header('Location: http://php.local.site/hello.php');
echo "...";
?>

hello.php
<?php
ob_start();
echo 'hello world';
ob_flush();
flush();
ob_end_flush();
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 08:01:29 2024 UTC