Bug #53556 [Com]: cURL returns wrong Content-Length after a redirect to a page without CL-header

From: Date: Mon, 04 Mar 2013 14:17:16 +0000
Subject: Bug #53556 [Com]: cURL returns wrong Content-Length after a redirect to a page without CL-header
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-177567@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53556&edit=1

 ID:                 53556
 Comment by:         michael dot moench at marktjagd dot de
 Reported by:        michael dot moench at marktjagd dot de
 Summary:            cURL returns wrong Content-Length after a redirect
                     to a page without CL-header
 Status:             No Feedback
 Type:               Bug
 Package:            HTTP related
 Operating System:   Ubuntu 10.04
 PHP Version:        5.3SVN-2010-12-16 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

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();
?>


Previous Comments:
------------------------------------------------------------------------
[2013-02-18 00:34:37] 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.

------------------------------------------------------------------------
[2010-12-21 23:02:39] 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.



------------------------------------------------------------------------
[2010-12-16 18:24:03] cataphract@php.net

This looks like a problem upstream.

------------------------------------------------------------------------
[2010-12-16 13:27:22] 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




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=53556&edit=1


Thread (5 messages)

« previous php.bugs (#177567) next »