Export to GitHub

firephp - issue #154

getRequestHeader uses "getallheaders" even though it doesn't always exist.


Posted on Oct 11, 2010 by Happy Rhino

What versions and operating system are you using?

OS:Mac OS 10.6.4 Firefox:3.6.10 Firebug:1.5.4 FirePHP Server Library:0.3.2 FirePHP Extension:0.5rc1

What is the problem? The server library incorrectly assumes that the function getallheaders exists on all servers. It doesn't. Depending on the error level you have enabled on the server this can break a page.

What is the expected output? What do you see instead?

Suggested patch:

/**
 * Get a request header
 *
 * @return string|false
 */
protected function getRequestHeader($Name)
{   
    if(function_exists('getallheaders') === false)
    {
        return false;
    }
    $headers = getallheaders();
    if (isset($headers[$Name])) {
        return $headers[$Name];
    } else
    // just in case headers got lower-cased in transport
    if (isset($headers[strtolower($Name)])) {
        return $headers[strtolower($Name)];
    }
    return false;
}

Comment #1

Posted on Oct 11, 2010 by Happy Camel

Thanks for the heads up. I'll have a new release ASAP.

Comment #2

Posted on Oct 11, 2010 by Happy Rhino

np, glad to help.

Comment #3

Posted on Oct 12, 2010 by Happy Camel

Comitted:

public static function getAllRequestHeaders() {
    static $_cached_headers = false;
    if($_cached_headers!==false) {
        return $_cached_headers;
    }
    $headers = array();
    if(function_exists('getallheaders')) {
        foreach( getallheaders() as $name => $value ) {
            $headers[strtolower($name)] = $value;
        }
    } else {
        foreach($_SERVER as $name => $value) {
            if(substr($name, 0, 5) == 'HTTP_') {
                $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value;
            }
        }
    }
    return $_cached_headers = $headers;
}

Will be published with 0.3.2rc6

Comment #4

Posted on Oct 12, 2010 by Happy Camel

0.3.2rc6 is now published. Please verify:

http://www.firephp.org/HQ/ReleaseCandidate.htm

Comment #5

Posted on Oct 13, 2010 by Happy Rhino

yes, this fixes the problem. thanks.

Comment #6

Posted on Oct 27, 2010 by Happy Camel

Released: http://www.firephp.org/HQ/FinalRelease.htm

Status: Fixed

Labels:
Type-Defect Priority-Critical Milestone-FirePHPCore-0.3.2