Changeset 9963

Show
Ignore:
Timestamp:
11/17/08 14:17:18 (2 months ago)
Author:
afz
Message:

Update HTTP_Request to 1.4.4

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/jaws/html/libraries/pear/HTTP/Request.php

    r9092 r9963  
    44 * 
    55 * PHP versions 4 and 5 
    6  *  
     6 * 
    77 * LICENSE: 
    88 * 
     
    4141 * @copyright   2002-2007 Richard Heyes 
    4242 * @license     http://opensource.org/licenses/bsd-license.php New BSD License 
    43  * @version     CVS: $Id: Request.php,v 1.60 2008/07/21 17:41:56 avb Exp $ 
    44  * @link        http://pear.php.net/package/HTTP_Request/  
     43 * @version     CVS: $Id: Request.php,v 1.63 2008/10/11 11:07:10 avb Exp $ 
     44 * @link        http://pear.php.net/package/HTTP_Request/ 
    4545 */ 
    4646 
     
    5555/** 
    5656 * URL handling class 
    57  */  
     57 */ 
    5858require_once 'Net/URL.php'; 
    5959 
    6060/**#@+ 
    6161 * Constants for HTTP request methods 
    62  */  
     62 */ 
    6363define('HTTP_REQUEST_METHOD_GET',     'GET',     true); 
    6464define('HTTP_REQUEST_METHOD_HEAD',    'HEAD',    true); 
     
    7272/**#@+ 
    7373 * Constants for HTTP request error codes 
    74  */  
     74 */ 
    7575define('HTTP_REQUEST_ERROR_FILE',             1); 
    7676define('HTTP_REQUEST_ERROR_URL',              2); 
    7777define('HTTP_REQUEST_ERROR_PROXY',            4); 
    7878define('HTTP_REQUEST_ERROR_REDIRECTS',        8); 
    79 define('HTTP_REQUEST_ERROR_RESPONSE',        16);   
     79define('HTTP_REQUEST_ERROR_RESPONSE',        16); 
    8080define('HTTP_REQUEST_ERROR_GZIP_METHOD',     32); 
    8181define('HTTP_REQUEST_ERROR_GZIP_READ',       64); 
     
    9393if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) { 
    9494   /** 
    95     * Whether string functions are overloaded by their mbstring equivalents  
     95    * Whether string functions are overloaded by their mbstring equivalents 
    9696    */ 
    9797    define('HTTP_REQUEST_MBSTRING', true); 
     
    117117 * @author      Richard Heyes <richard@phpguru.org> 
    118118 * @author      Alexey Borzov <avb@php.net> 
    119  * @version     Release: 1.4.3 
     119 * @version     Release: 1.4.4 
    120120 */ 
    121121class HTTP_Request 
     
    153153    */ 
    154154    var $_user; 
    155      
     155 
    156156    /** 
    157157    * Basic Auth Password 
     
    165165    */ 
    166166    var $_sock; 
    167      
     167 
    168168    /** 
    169169    * Proxy server 
     
    171171    */ 
    172172    var $_proxy_host; 
    173      
     173 
    174174    /** 
    175175    * Proxy port 
     
    177177    */ 
    178178    var $_proxy_port; 
    179      
     179 
    180180    /** 
    181181    * Proxy username 
     
    183183    */ 
    184184    var $_proxy_user; 
    185      
     185 
    186186    /** 
    187187    * Proxy password 
     
    197197 
    198198   /** 
    199     * Request body   
     199    * Request body 
    200200    * @var string 
    201201    */ 
     
    209209 
    210210   /** 
    211     * Files to post  
     211    * Methods having defined semantics for request body 
     212    * 
     213    * Content-Length header (indicating that the body follows, section 4.3 of 
     214    * RFC 2616) will be sent for these methods even if no body was added 
     215    * 
     216    * @var array 
     217    */ 
     218    var $_bodyRequired = array('POST', 'PUT'); 
     219 
     220   /** 
     221    * Files to post 
    212222    * @var array 
    213223    */ 
     
    219229    */ 
    220230    var $_timeout; 
    221      
     231 
    222232    /** 
    223233    * HTTP_Response object 
     
    225235    */ 
    226236    var $_response; 
    227      
     237 
    228238    /** 
    229239    * Whether to allow redirects 
     
    231241    */ 
    232242    var $_allowRedirects; 
    233      
     243 
    234244    /** 
    235245    * Maximum redirects allowed 
     
    237247    */ 
    238248    var $_maxRedirects; 
    239      
     249 
    240250    /** 
    241251    * Current number of redirects 
     
    257267 
    258268   /** 
    259     * Whether to save response body in response object property   
     269    * Whether to save response body in response object property 
    260270    * @var bool 
    261271    */ 
     
    352362        } 
    353363    } 
    354      
     364 
    355365    /** 
    356366    * Generates a Host header for HTTP/1.1 requests 
     
    369379        } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { 
    370380            $host = $this->_url->host . ':' . $this->_url->port; 
    371          
     381 
    372382        } else { 
    373383            $host = $this->_url->host; 
     
    376386        return $host; 
    377387    } 
    378      
     388 
    379389    /** 
    380390    * Resets the object to its initial state (DEPRECATED). 
     
    413423        if (empty($this->_url->path)) { 
    414424            $this->_url->path = '/'; 
    415         }  
    416     } 
    417      
    418    /** 
    419     * Returns the current request URL   
     425        } 
     426    } 
     427 
     428   /** 
     429    * Returns the current request URL 
    420430    * 
    421431    * @return   string  Current request URL 
     
    520530    { 
    521531        $this->_url->addQueryString($name, $value, $preencoded); 
    522     }     
    523      
     532    } 
     533 
    524534    /** 
    525535    * Sets the querystring to literally what you supply 
     
    553563   /** 
    554564    * Recursively applies the callback function to the value 
    555     *  
     565    * 
    556566    * @param    mixed   Callback function 
    557567    * @param    mixed   Value to process 
     
    573583 
    574584   /** 
    575     * Adds a file to upload 
    576     *  
    577     * This also changes content-type to 'multipart/form-data' for proper upload 
    578     *  
     585    * Adds a file to form-based file upload 
     586    * 
     587    * Used to emulate file upload via a HTML form. The method also sets 
     588    * Content-Type of HTTP request to 'multipart/form-data'. 
     589    * 
     590    * If you just want to send the contents of a file as the body of HTTP 
     591    * request you should use setBody() method. 
     592    * 
    579593    * @access public 
    580594    * @param  string    name of file-upload field 
     
    628642 
    629643    /** 
    630     * Clears any postdata that has been added (DEPRECATED).  
    631     *  
     644    * Clears any postdata that has been added (DEPRECATED). 
     645    * 
    632646    * Useful for multiple request scenarios. 
    633647    * 
     
    642656    /** 
    643657    * Appends a cookie to "Cookie:" header 
    644     *  
     658    * 
    645659    * @param string $name cookie name 
    646660    * @param string $value cookie value 
     
    652666        $this->addHeader('Cookie', $cookies . $name . '=' . $value); 
    653667    } 
    654      
    655     /** 
    656     * Clears any cookies that have been added (DEPRECATED).  
    657     *  
     668 
     669    /** 
     670    * Clears any cookies that have been added (DEPRECATED). 
     671    * 
    658672    * Useful for multiple request scenarios 
    659673    * 
     
    698712        ini_set('magic_quotes_runtime', false); 
    699713 
    700         // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive  
     714        // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive 
    701715        // connection token to a proxy server... 
    702716        if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && 
     
    714728        // There is a connected socket in the "static" property? 
    715729        if ($keepAlive && !empty($sockets[$sockKey]) && 
    716             !empty($sockets[$sockKey]->fp))  
     730            !empty($sockets[$sockKey]->fp)) 
    717731        { 
    718732            $this->_sock =& $sockets[$sockKey]; 
     
    773787            AND !empty($this->_response->_headers['location'])) { 
    774788 
    775              
     789 
    776790            $redirect = $this->_response->_headers['location']; 
    777791 
     
    783797            } elseif ($redirect{0} == '/') { 
    784798                $this->_url->path = $redirect; 
    785              
     799 
    786800            // Relative path 
    787801            } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { 
     
    793807                $redirect = Net_URL::resolvePath($redirect); 
    794808                $this->_url->path = $redirect; 
    795                  
     809 
    796810            // Filename, no path 
    797811            } else { 
     
    881895    /** 
    882896    * Returns cookies set in response 
    883     *  
     897    * 
    884898    * @access public 
    885899    * @return mixed     array of response cookies, false if none are present 
     
    943957 
    944958        // Post data if it's an array 
    945         } elseif (HTTP_REQUEST_METHOD_POST == $this->_method &&  
     959        } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 
    946960                  (!empty($this->_postData) || !empty($this->_postFiles))) { 
    947961 
     
    949963            if (!isset($boundary)) { 
    950964                $postdata = implode('&', array_map( 
    951                     create_function('$a', 'return $a[0] . \'=\' . $a[1];'),  
     965                    create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 
    952966                    $this->_flattenArray('', $this->_postData) 
    953967                )); 
     
    972986                    } 
    973987                    foreach ($value['name'] as $key => $filename) { 
    974                         $fp   = fopen($filename, 'r'); 
    975                         $data = fread($fp, filesize($filename)); 
    976                         fclose($fp); 
     988                        $fp       = fopen($filename, 'r'); 
    977989                        $basename = basename($filename); 
    978990                        $type     = is_array($value['type'])? @$value['type'][$key]: $value['type']; 
     
    981993                        $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; 
    982994                        $postdata .= "\r\nContent-Type: " . $type; 
    983                         $postdata .= "\r\n\r\n" . $data . "\r\n"; 
     995                        $postdata .= "\r\n\r\n" . fread($fp, filesize($filename)) . "\r\n"; 
     996                        fclose($fp); 
    984997                    } 
    985998                } 
     
    9991012            $request .= $this->_body; 
    10001013 
    1001         // No body: send a Content-Length header nonetheless (request #12900) 
     1014        // No body: send a Content-Length header nonetheless (request #12900), 
     1015        // but do that only for methods that require a body (bug #14740) 
    10021016        } else { 
    10031017 
    1004             $request .= "Content-Length: 0\r\n\r\n"; 
    1005         } 
    1006          
     1018            if (in_array($this->_method, $this->_bodyRequired)) { 
     1019                $request .= "Content-Length: 0\r\n"; 
     1020            } 
     1021            $request .= "\r\n"; 
     1022        } 
     1023 
    10071024        return $request; 
    10081025    } 
     
    10411058    * Adds a Listener to the list of listeners that are notified of 
    10421059    * the object's events 
    1043     *  
     1060    * 
    10441061    * Events sent by HTTP_Request object 
    10451062    * - 'connect': on connection to server 
     
    10681085 
    10691086   /** 
    1070     * Removes a Listener from the list of listeners  
    1071     *  
     1087    * Removes a Listener from the list of listeners 
     1088    * 
    10721089    * @param    HTTP_Request_Listener   listener to detach 
    10731090    * @return   boolean                 whether the listener was successfully detached 
     
    10761093    function detach(&$listener) 
    10771094    { 
    1078         if (!is_a($listener, 'HTTP_Request_Listener') ||  
     1095        if (!is_a($listener, 'HTTP_Request_Listener') || 
    10791096            !isset($this->_listeners[$listener->getId()])) { 
    10801097            return false; 
     
    10871104   /** 
    10881105    * Notifies all registered listeners of an event. 
    1089     *  
     1106    * 
    10901107    * @param    string  Event name 
    10911108    * @param    mixed   Additional data 
     
    11091126 * @author      Richard Heyes <richard@phpguru.org> 
    11101127 * @author      Alexey Borzov <avb@php.net> 
    1111  * @version     Release: 1.4.3 
     1128 * @version     Release: 1.4.4 
    11121129 */ 
    11131130class HTTP_Response 
     
    11241141    */ 
    11251142    var $_protocol; 
    1126      
     1143 
    11271144    /** 
    11281145    * Return code 
     
    11301147    */ 
    11311148    var $_code; 
    1132      
     1149 
    11331150    /** 
    11341151    * Response reason phrase 
     
    11441161 
    11451162    /** 
    1146     * Cookies set in response   
     1163    * Cookies set in response 
    11471164    * @var array 
    11481165    */ 
     
    11881205   /** 
    11891206    * Processes a HTTP response 
    1190     *  
    1191     * This extracts response code, headers, cookies and decodes body if it  
     1207    * 
     1208    * This extracts response code, headers, cookies and decodes body if it 
    11921209    * was encoded in some way 
    11931210    * 
     
    12201237 
    12211238        // RFC 2616, section 4.4: 
    1222         // 1. Any response message which "MUST NOT" include a message-body ...  
    1223         // is always terminated by the first empty line after the header fields  
     1239        // 1. Any response message which "MUST NOT" include a message-body ... 
     1240        // is always terminated by the first empty line after the header fields 
    12241241        // 3. ... If a message is received with both a 
    12251242        // Transfer-Encoding header field and a Content-Length header field, 
    12261243        // the latter MUST be ignored. 
    1227         $canHaveBody = $canHaveBody && $this->_code >= 200 &&  
     1244        $canHaveBody = $canHaveBody && $this->_code >= 200 && 
    12281245                       $this->_code != 204 && $this->_code != 304; 
    12291246 
     
    12321249        $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']); 
    12331250        $hasBody = false; 
    1234         if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) ||  
     1251        if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 
    12351252                0 != $this->_headers['content-length'])) 
    12361253        { 
     
    12921309        $headername  = strtolower($headername); 
    12931310        $headervalue = ltrim($headervalue); 
    1294          
     1311 
    12951312        if ('set-cookie' != $headername) { 
    12961313            if (isset($this->_headers[$headername])) { 
     
    13581375   /** 
    13591376    * Read a part of response body encoded with chunked Transfer-Encoding 
    1360     *  
     1377    * 
    13611378    * @access private 
    13621379    * @return string 
     
    13681385            $line = $this->_sock->readLine(); 
    13691386            if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) { 
    1370                 $this->_chunkLength = hexdec($matches[1]);  
     1387                $this->_chunkLength = hexdec($matches[1]); 
    13711388                // Chunk with zero length indicates the end 
    13721389                if (0 == $this->_chunkLength) { 
     
    13891406   /** 
    13901407    * Notifies all registered listeners of an event. 
    1391     *  
     1408    * 
    13921409    * @param    string  Event name 
    13931410    * @param    mixed   Additional data 
     
    14081425    * The real decoding work is done by gzinflate() built-in function, this 
    14091426    * method only parses the header and checks data for compliance with 
    1410     * RFC 1952   
     1427    * RFC 1952 
    14111428    * 
    14121429    * @access   private 
  • trunk/jaws/html/libraries/pear/HTTP/Request/Listener.php

    r9092 r9963  
    5353 * @package     HTTP_Request 
    5454 * @author      Alexey Borzov <avb@php.net> 
    55  * @version     Release: 1.4.3 
     55 * @version     Release: 1.4.4 
    5656 */ 
    5757class HTTP_Request_Listener