From:             akbarovs at gmail dot com
Operating system: Any
PHP version:      5.4.13
Package:          Streams related
Bug Type:         Bug
Bug description:follow_location parameter of context is ignored for most 
response codes

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 bug report at https://bugs.php.net/bug.php?id=64433&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64433&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64433&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64433&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64433&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64433&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64433&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64433&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64433&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64433&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64433&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64433&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64433&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64433&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64433&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64433&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64433&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64433&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64433&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64433&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64433&r=mysqlcfg

Reply via email to