php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64298 Response body not parsed for OK 200 if If-Modified-Since matches Last-Modified
Submitted: 2013-02-25 14:24 UTC Modified: 2013-03-04 07:44 UTC
From: niko dot sams at gmail dot com Assigned: mike (profile)
Status: Not a bug Package: pecl_http (PECL)
PHP Version: 5.3.22 OS: Ubuntu 12.04
Private report: No CVE-ID: None
 [2013-02-25 14:24 UTC] niko dot sams at gmail dot com
Description:
------------
For some reason fetching the url with lastmodified and etag options doesn't work 
correctly. The server returns a 200 OK but the HttpRequest doesn't include the 
body.
 
I can reproduce this on:
Ubuntu 12.04
PHP 5.3.10-1ubuntu3.5
Extension Version => 1.7.4
Used Library => Compiled => Linked
libcurl => 7.22.0 => 7.22.0
libevent => 1.4 or greater => 2.0.16-stable
libz => 1.2.3.4 => 1.2.3.4
libmagic => disabled => disabled

Trying curl extension it works as expected.

Test script:
---------------
<?php
$url = 'http://nikosams.blogspot.com/feeds/posts/default?alt=rss';

//get the current last-modified date
$r = new HttpRequest($url);
$m = $r->send();
$lastModified = $m->getHeader('Last-Modified');


//try to fetch with lastmodified and etag
$r = new HttpRequest($url, HTTP_METH_GET, array(
    'lastmodified' => strtotime($lastModified),
    'etag' => "abcd", //if removed a 304 is returned
));
$m = $r->send();
var_dump($r->getHeaders());
echo $r->getRawResponseMessage();


Expected result:
----------------
Response header plus body.

Actual result:
--------------
Response header only.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-25 14:28 UTC] niko dot sams at gmail dot com
I can also reproduce on ArchLinux with PHP 5.4.11
 [2013-02-27 11:59 UTC] niko dot sams at gmail dot com
Better testcase that doesn't depend on external server:
server.php:
<?php 
$sock = socket_create_listen(1234); 
socket_getsockname($sock, $addr, $port); 
print "Server Listening on $addr:$port\n"; 
while($c = socket_accept($sock)) { 
    socket_getpeername($c, $raddr, $rport); 
    print "Received Connection from $raddr:$rport\n";
    $buf = '';
    do {
        $l = socket_read($c, 1024);
        $buf .= $l;
    } while (substr($buf, -4) != "\r\n\r\n");
    echo $buf."\n";
    $out = "HTTP/1.1 200 OK
Content-Type: text/plain
Last-Modified: Mon, 25 Feb 2013 13:35:56 GMT

test

";
    $out = str_replace("\n", "\r\n", $out);
    echo $out;
    socket_write($c, $out, strlen($out));
    socket_close($c);
} 
socket_close($sock); 
?>

test.php:
<?php
$url = 'http://localhost:1234/';
$lastModified = 'Mon, 25 Feb 2013 13:35:56 GMT';
$r = new HttpRequest($url, HTTP_METH_GET, array(
    'lastmodified' => strtotime($lastModified),
));
$m = $r->send();
echo $r->getRawResponseMessage();
?>
 [2013-02-27 12:42 UTC] niko dot sams at gmail dot com
-Summary: Response message not parsed correctly +Summary: Response body not parsed for OK 200 if If-Modified-Since matches Last-Modified
 [2013-02-27 12:42 UTC] niko dot sams at gmail dot com
improve summary
 [2013-03-02 16:51 UTC] mike@php.net
Sorry, this is an issue in libcurl then.

pecl_http sets CURLOPT_TIMECONDITION=CURL_TIMECOND_IFMODSINCE and 
CURLOPT_TIMEVALUE=$lastmodifed, just like curl:

$ curl localhost:1234 -v -z "Mon, 25 Feb 2013 13:35:56 GMT"
* About to connect() to localhost port 1234 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 1234 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:1234
> Accept: */*
> If-Modified-Since: Mon, 25 Feb 2013 13:35:56 GMT
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Last-Modified: Mon, 25 Feb 2013 13:35:56 GMT
* no chunk, no close, no size. Assume close to signal end
< 
* The requested document is not new enough
* Closing connection 0
 [2013-03-02 16:51 UTC] mike@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: mike
 [2013-03-04 07:44 UTC] niko dot sams at gmail dot com
Ok, thanks for investigating.

Upstream Bug: https://sourceforge.net/p/curl/bugs/1202/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 07:01:29 2024 UTC