Changeset 9963
- Timestamp:
- 11/17/08 14:17:18 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jaws/html/libraries/pear/HTTP/Request.php
r9092 r9963 4 4 * 5 5 * PHP versions 4 and 5 6 * 6 * 7 7 * LICENSE: 8 8 * … … 41 41 * @copyright 2002-2007 Richard Heyes 42 42 * @license http://opensource.org/licenses/bsd-license.php New BSD License 43 * @version CVS: $Id: Request.php,v 1.6 0 2008/07/21 17:41:56avb 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/ 45 45 */ 46 46 … … 55 55 /** 56 56 * URL handling class 57 */ 57 */ 58 58 require_once 'Net/URL.php'; 59 59 60 60 /**#@+ 61 61 * Constants for HTTP request methods 62 */ 62 */ 63 63 define('HTTP_REQUEST_METHOD_GET', 'GET', true); 64 64 define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true); … … 72 72 /**#@+ 73 73 * Constants for HTTP request error codes 74 */ 74 */ 75 75 define('HTTP_REQUEST_ERROR_FILE', 1); 76 76 define('HTTP_REQUEST_ERROR_URL', 2); 77 77 define('HTTP_REQUEST_ERROR_PROXY', 4); 78 78 define('HTTP_REQUEST_ERROR_REDIRECTS', 8); 79 define('HTTP_REQUEST_ERROR_RESPONSE', 16); 79 define('HTTP_REQUEST_ERROR_RESPONSE', 16); 80 80 define('HTTP_REQUEST_ERROR_GZIP_METHOD', 32); 81 81 define('HTTP_REQUEST_ERROR_GZIP_READ', 64); … … 93 93 if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) { 94 94 /** 95 * Whether string functions are overloaded by their mbstring equivalents 95 * Whether string functions are overloaded by their mbstring equivalents 96 96 */ 97 97 define('HTTP_REQUEST_MBSTRING', true); … … 117 117 * @author Richard Heyes <richard@phpguru.org> 118 118 * @author Alexey Borzov <avb@php.net> 119 * @version Release: 1.4. 3119 * @version Release: 1.4.4 120 120 */ 121 121 class HTTP_Request … … 153 153 */ 154 154 var $_user; 155 155 156 156 /** 157 157 * Basic Auth Password … … 165 165 */ 166 166 var $_sock; 167 167 168 168 /** 169 169 * Proxy server … … 171 171 */ 172 172 var $_proxy_host; 173 173 174 174 /** 175 175 * Proxy port … … 177 177 */ 178 178 var $_proxy_port; 179 179 180 180 /** 181 181 * Proxy username … … 183 183 */ 184 184 var $_proxy_user; 185 185 186 186 /** 187 187 * Proxy password … … 197 197 198 198 /** 199 * Request body 199 * Request body 200 200 * @var string 201 201 */ … … 209 209 210 210 /** 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 212 222 * @var array 213 223 */ … … 219 229 */ 220 230 var $_timeout; 221 231 222 232 /** 223 233 * HTTP_Response object … … 225 235 */ 226 236 var $_response; 227 237 228 238 /** 229 239 * Whether to allow redirects … … 231 241 */ 232 242 var $_allowRedirects; 233 243 234 244 /** 235 245 * Maximum redirects allowed … … 237 247 */ 238 248 var $_maxRedirects; 239 249 240 250 /** 241 251 * Current number of redirects … … 257 267 258 268 /** 259 * Whether to save response body in response object property 269 * Whether to save response body in response object property 260 270 * @var bool 261 271 */ … … 352 362 } 353 363 } 354 364 355 365 /** 356 366 * Generates a Host header for HTTP/1.1 requests … … 369 379 } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { 370 380 $host = $this->_url->host . ':' . $this->_url->port; 371 381 372 382 } else { 373 383 $host = $this->_url->host; … … 376 386 return $host; 377 387 } 378 388 379 389 /** 380 390 * Resets the object to its initial state (DEPRECATED). … … 413 423 if (empty($this->_url->path)) { 414 424 $this->_url->path = '/'; 415 } 416 } 417 418 /** 419 * Returns the current request URL 425 } 426 } 427 428 /** 429 * Returns the current request URL 420 430 * 421 431 * @return string Current request URL … … 520 530 { 521 531 $this->_url->addQueryString($name, $value, $preencoded); 522 } 523 532 } 533 524 534 /** 525 535 * Sets the querystring to literally what you supply … … 553 563 /** 554 564 * Recursively applies the callback function to the value 555 * 565 * 556 566 * @param mixed Callback function 557 567 * @param mixed Value to process … … 573 583 574 584 /** 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 * 579 593 * @access public 580 594 * @param string name of file-upload field … … 628 642 629 643 /** 630 * Clears any postdata that has been added (DEPRECATED). 631 * 644 * Clears any postdata that has been added (DEPRECATED). 645 * 632 646 * Useful for multiple request scenarios. 633 647 * … … 642 656 /** 643 657 * Appends a cookie to "Cookie:" header 644 * 658 * 645 659 * @param string $name cookie name 646 660 * @param string $value cookie value … … 652 666 $this->addHeader('Cookie', $cookies . $name . '=' . $value); 653 667 } 654 655 /** 656 * Clears any cookies that have been added (DEPRECATED). 657 * 668 669 /** 670 * Clears any cookies that have been added (DEPRECATED). 671 * 658 672 * Useful for multiple request scenarios 659 673 * … … 698 712 ini_set('magic_quotes_runtime', false); 699 713 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 701 715 // connection token to a proxy server... 702 716 if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && … … 714 728 // There is a connected socket in the "static" property? 715 729 if ($keepAlive && !empty($sockets[$sockKey]) && 716 !empty($sockets[$sockKey]->fp)) 730 !empty($sockets[$sockKey]->fp)) 717 731 { 718 732 $this->_sock =& $sockets[$sockKey]; … … 773 787 AND !empty($this->_response->_headers['location'])) { 774 788 775 789 776 790 $redirect = $this->_response->_headers['location']; 777 791 … … 783 797 } elseif ($redirect{0} == '/') { 784 798 $this->_url->path = $redirect; 785 799 786 800 // Relative path 787 801 } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { … … 793 807 $redirect = Net_URL::resolvePath($redirect); 794 808 $this->_url->path = $redirect; 795 809 796 810 // Filename, no path 797 811 } else { … … 881 895 /** 882 896 * Returns cookies set in response 883 * 897 * 884 898 * @access public 885 899 * @return mixed array of response cookies, false if none are present … … 943 957 944 958 // Post data if it's an array 945 } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 959 } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 946 960 (!empty($this->_postData) || !empty($this->_postFiles))) { 947 961 … … 949 963 if (!isset($boundary)) { 950 964 $postdata = implode('&', array_map( 951 create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 965 create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 952 966 $this->_flattenArray('', $this->_postData) 953 967 )); … … 972 986 } 973 987 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'); 977 989 $basename = basename($filename); 978 990 $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; … … 981 993 $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; 982 994 $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); 984 997 } 985 998 } … … 999 1012 $request .= $this->_body; 1000 1013 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) 1002 1016 } else { 1003 1017 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 1007 1024 return $request; 1008 1025 } … … 1041 1058 * Adds a Listener to the list of listeners that are notified of 1042 1059 * the object's events 1043 * 1060 * 1044 1061 * Events sent by HTTP_Request object 1045 1062 * - 'connect': on connection to server … … 1068 1085 1069 1086 /** 1070 * Removes a Listener from the list of listeners 1071 * 1087 * Removes a Listener from the list of listeners 1088 * 1072 1089 * @param HTTP_Request_Listener listener to detach 1073 1090 * @return boolean whether the listener was successfully detached … … 1076 1093 function detach(&$listener) 1077 1094 { 1078 if (!is_a($listener, 'HTTP_Request_Listener') || 1095 if (!is_a($listener, 'HTTP_Request_Listener') || 1079 1096 !isset($this->_listeners[$listener->getId()])) { 1080 1097 return false; … … 1087 1104 /** 1088 1105 * Notifies all registered listeners of an event. 1089 * 1106 * 1090 1107 * @param string Event name 1091 1108 * @param mixed Additional data … … 1109 1126 * @author Richard Heyes <richard@phpguru.org> 1110 1127 * @author Alexey Borzov <avb@php.net> 1111 * @version Release: 1.4. 31128 * @version Release: 1.4.4 1112 1129 */ 1113 1130 class HTTP_Response … … 1124 1141 */ 1125 1142 var $_protocol; 1126 1143 1127 1144 /** 1128 1145 * Return code … … 1130 1147 */ 1131 1148 var $_code; 1132 1149 1133 1150 /** 1134 1151 * Response reason phrase … … 1144 1161 1145 1162 /** 1146 * Cookies set in response 1163 * Cookies set in response 1147 1164 * @var array 1148 1165 */ … … 1188 1205 /** 1189 1206 * 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 1192 1209 * was encoded in some way 1193 1210 * … … 1220 1237 1221 1238 // 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 1224 1241 // 3. ... If a message is received with both a 1225 1242 // Transfer-Encoding header field and a Content-Length header field, 1226 1243 // the latter MUST be ignored. 1227 $canHaveBody = $canHaveBody && $this->_code >= 200 && 1244 $canHaveBody = $canHaveBody && $this->_code >= 200 && 1228 1245 $this->_code != 204 && $this->_code != 304; 1229 1246 … … 1232 1249 $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']); 1233 1250 $hasBody = false; 1234 if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 1251 if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 1235 1252 0 != $this->_headers['content-length'])) 1236 1253 { … … 1292 1309 $headername = strtolower($headername); 1293 1310 $headervalue = ltrim($headervalue); 1294 1311 1295 1312 if ('set-cookie' != $headername) { 1296 1313 if (isset($this->_headers[$headername])) { … … 1358 1375 /** 1359 1376 * Read a part of response body encoded with chunked Transfer-Encoding 1360 * 1377 * 1361 1378 * @access private 1362 1379 * @return string … … 1368 1385 $line = $this->_sock->readLine(); 1369 1386 if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) { 1370 $this->_chunkLength = hexdec($matches[1]); 1387 $this->_chunkLength = hexdec($matches[1]); 1371 1388 // Chunk with zero length indicates the end 1372 1389 if (0 == $this->_chunkLength) { … … 1389 1406 /** 1390 1407 * Notifies all registered listeners of an event. 1391 * 1408 * 1392 1409 * @param string Event name 1393 1410 * @param mixed Additional data … … 1408 1425 * The real decoding work is done by gzinflate() built-in function, this 1409 1426 * method only parses the header and checks data for compliance with 1410 * RFC 1952 1427 * RFC 1952 1411 1428 * 1412 1429 * @access private trunk/jaws/html/libraries/pear/HTTP/Request/Listener.php
r9092 r9963 53 53 * @package HTTP_Request 54 54 * @author Alexey Borzov <avb@php.net> 55 * @version Release: 1.4. 355 * @version Release: 1.4.4 56 56 */ 57 57 class HTTP_Request_Listener
