• Etienne CHAMPETIER's avatar
    ZP-797 WBXMLDecoder remove inlog / reread php://input. · 40f4b10c
    Etienne CHAMPETIER authored
    Released under the Affero GNU General Public License (AGPL) version 3.
    
    With POST request, we can read multiple times php://input,
    this permit us to drop "inlog", which is an "always on" debug code
    (introduced in ZP-608 / bbfe372c)
    see Notes in http://php.net/manual/en/wrappers.php.php#wrappers.php.input
    see also http://stackoverflow.com/a/3402343
    
    we keep readRemainingData() as it's used in printwbxml.php
    
    here is my test:
    
    <?php
    
    // tested working version:
    
    // 5.6.15/fpm-fcgi (fedora22/php-fpm)
    // 5.6.5/fpm-fcgi (centos6 php56 scl/php-fpm)
    // 5.5.21/fpm-fcgi (centos6 php55 scl/php-fpm)
    // 5.3.29/fpm-fcgi (centos6 php53 ius/php-fpm)
    
    // 5.4.45-0+deb7u2/apache2handler
    // 5.3.28/apache2handler (rhel6 php53 ius/apache)
    
    if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
            echo 'not a post request!';
            echo '<br>'.PHP_EOL;
            echo 'curl --data "test POST" http://<server>/test-multi-read-input.php';
            echo PHP_EOL;
            exit();
    }
    
    function readinput($close = true) {
            $input = fopen('php://input', 'r');
            $content = stream_get_contents($input);
            if ($close)
                    fclose($input);
            return $content;
    }
    
    echo "Reading multiple time php://input ";
    if (readinput() === readinput() && readinput(false) === readinput(false)) {
            echo "WORKS \o/";
    } else {
            echo "DOESN'T WORK :(";
    }
    echo PHP_EOL;
    echo 'Version: '.PHP_VERSION.'/'.PHP_SAPI;
    echo PHP_EOL;
    echo PHP_EOL;
    
    echo "Input was: ".readinput();
    echo PHP_EOL;
    40f4b10c
requestprocessor.php 6.48 KB