Re: Package proposal: HTTP_Status

From: Date: Tue, 26 Aug 2003 06:46:47 +0000
Subject: Re: Package proposal: HTTP_Status
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20510@lists.php.net to get a copy of this message
I've no idea what you would use it for :) I'd suggest someone does a status_codes.ini file and both (all?) packages share it.. $codes = parse_ini_file( dirname(__FILE__).'/status_codes.ini'); from the code below it looks like constants are a bit messy for this.. I think your checks look a bit buggy... function isInformational($code) { // should this be < 200?
        if ($code >= 100 && $code > 200) {
            return true;
        }
        return false;
    }
try: function isInformational($code) { return $code{0} == '1'; } Regards Alan Marshall Roch wrote:
I've created a class called HTTP_Status that translates HTTP (including WebDAV) status codes (e.g. 200, 404, 304) into human-readable form (respectively "OK", "Not Found", "Not Modified"). It also has methods to check whether a given status code is "informational," "success," "redirection," "client error," or "server error." There are a number of classes already in PEAR that could make use of this. HTTP_Header defines almost all of the status codes as constants, but it has a number of problems: 1) The constants can't be used by other packages. 2) The constants are only used for one method (a lot of code for a very specific gain), and the developer (Wolfram) seems to want to make it cleaner:
    function sendStatusCode ( $code )
    {
        if ( is_int($code) ) {
            // if the $code is an int we get the constant here
            // is there an easier way to build a constant dynamically?
            eval("\$code = HTTP_HEADER_STATUS_".$code.';');
        }
        ...
    }
With HTTP_Status, it would be:
    ...
    // eval("\$code = HTTP_HEADER_STATUS_".$code.';');
    $status = $code . HTTP_Status::getStatusMessage($code);
    ...
In HTTP_Client, the following is used to check for redirection: if ( ... in_array($code, array(300, 301, 302, 303, 307))) {
    ... do stuff because it's a redirection ...
} With HTTP_Status, it would be: if ( ... HTTP_Status::isRedirection($code)) {
    ... do stuff because it's a redirection ...
} If more redirection codes were added in a new version of HTTP, HTTP_Client, or any other class that makes use of HTTP status codes, would continue working fine. Also in HTTP_Client, the following code is used: if (400 >= $code) {
    $this->_notify('httpSuccess');
    ...
} This is saying that all status codes greater than 399 (redirection codes are 300 - 399) are not redirects, so it's successful. This isn't the case: 100 - 199 are informational; 200 - 299 show success. With HTTP_Status: if (!HTTP_Status::isRedirection($code)) {
    $this->_notify('httpSuccess');
    ...
} The same principal applies to each group of status codes (informational, success, redirection, client error, and server error). Source: http://www.exclupen.com/misc/php/pear_patches/HTTP_Status/Status.phps Package.xml: http://www.exclupen.com/misc/php/pear_patches/HTTP_Status/package.xml Package: http://www.exclupen.com/misc/php/pear_patches/HTTP_Status/HTTP_Status-1.0.tgz -- Marshall Roch
-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com

« previous php.pear.dev (#20510) next »