Edit report at https://bugs.php.net/bug.php?id=64433&edit=1
ID: 64433
Comment by: akbarovs at gmail dot com
Reported by: akbarovs at gmail dot com
Summary: follow_location parameter of context is ignored for
most response codes
Status: Open
Type: Bug
Package: Streams related
Operating System: Any
PHP Version: 5.4.13
Block user comment: N
Private report: N
New Comment:
I've attached pull request for this issue:
https://github.com/php/php-src/pull/303
Previous Comments:
------------------------------------------------------------------------
[2013-03-15 16:41:23] akbarovs at gmail dot com
Description:
------------
Affected PHP versions: 5.4.12, 5.4.13, Git
The problem is that in new releases PHP ignores 'follow_location' context
parameters for the response codes not in (300, 301, 302, 303 and 307). Problem
is related to bugfix for bug #62524. Response codes should not be checked in
the
same condition where we check 'follow_location' parameter. And when we do that
'follow_location' is always 1 for most response codes (ex.: 201): so we always
redirect to the 'Location' and it cannot be changed using 'follow_location'=>0
You can see curl log for the sample resource where we combine 201 response code
with 'Location' header: https://gist.github.com/akbarovs/5171115
For the test script I expect following response:
{"success": "ok"}
But when I execute it I get: {"documentId": 15} regardless to the
follow_location parameter. I can remove it from the context parameter but I
will
continue receive wrong response.
I've attached patch for this issue. If 'follow_location' is not specified we do
redirect for 3xx response codes. Otherwise we do not follow redirect. If
'follow_location' is specified -> we do/do not follow redirects without
checking
response codes (if somebody really want to be redirected why we shouldn't allow
to do it?)
BTW, I can send pull request via github if needed
Test script:
---------------
<?php
$requestXML = '';
$arr = array('http'=>
array(
'method'=>'POST',
'follow_location'=>0,
'content' => $requestXML
)
);
$context = stream_context_create($arr);
$f = fopen('http://localhost:8000', 'r', FALSE, $context);
echo stream_get_contents($f);
?>
Expected result:
----------------
Expected result:
{"success": "ok"}
Actual result:
--------------
Redirected to localhost:8000?q=1 and got {"documentId": 15}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64433&edit=1