Bug #67351 [Opn->Fbk]: copy() should handle HTTP 304 response
| From: | cmb@php.net | Date: | Mon, 07 Sep 2020 13:17:31 +0000 |
| Subject: | Bug #67351 [Opn->Fbk]: copy() should handle HTTP 304 response | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228930@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67351&edit=1
ID: 67351
Updated by: cmb@php.net
Reported by: Andy_Schmidt at HM-Software dot com
Summary: copy() should handle HTTP 304 response
-Status: Open
+Status: Feedback
Type: Bug
Package: Streams related
Operating System: Windows 2012
PHP Version: 5.4.28
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
I agree that the current handling of 304 Not Modified doesn't make
much sense, but I wonder how that should be handled. Just do
nothing, but return true? And how to handle file_get_contents()
etc.?
Previous Comments:
------------------------------------------------------------------------
[2014-05-28 02:23:56] Andy_Schmidt at HM-Software dot com
Description:
------------
Using the "If-Modified-Since" header is desirable when copying from a remote web server,
to avoid unnecessarily copying unmodified files across the Internet.
However, the copy() function does not handle a HTTP 304 response, which indicates that the file on
the web server is NOT newer than the local file. It ignores the response code, uses the (empty)
content from the HTTP response and overwrites the existing local file with a zero length file. This
is not a useful course of action.
Since the copy() function DOES handle other 3xx return codes appropriately (such as following
permanent and temporary redirects), it would make particular sense to also handle 304.
Test script:
---------------
<?php
// $fURI: URL to a file located on a web server
// $target_file: Path to a local file
$arrRequestHeaders = array(
'http'=>array(
'method' =>'GET',
'protocol_version' =>1.1,
'follow_location' =>1,
'header' =>'If-Modified-Since: '.date( 'r', filemtime(
$target_file ) )."\r\n"
)
);
$rc = copy( $fURI, $target_file, stream_context_create($arrRequestHeaders) );
?>
Expected result:
----------------
When a HTTP 304 response is returned, the copy() function must NOT touch the target file. copy()
could return a FALSE (indicating that nothing was copied), and the script could check the HTTP
response to decide on any specialized processing.
Actual result:
--------------
When a HTTP 304 response is returned, the copy() function returns TRUE and overrides the target file
with a 0 length file.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67351&edit=1