equal
deleted
inserted
replaced
14 * to license@zend.com so we can send you a copy immediately. |
14 * to license@zend.com so we can send you a copy immediately. |
15 * |
15 * |
16 * @category Zend |
16 * @category Zend |
17 * @package Zend_Http |
17 * @package Zend_Http |
18 * @subpackage Client |
18 * @subpackage Client |
19 * @version $Id: Client.php 24593 2012-01-05 20:35:02Z matthew $ |
19 * @version $Id$ |
20 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
20 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
21 * @license http://framework.zend.com/license/new-bsd New BSD License |
21 * @license http://framework.zend.com/license/new-bsd New BSD License |
22 */ |
22 */ |
23 |
23 |
24 /** |
24 /** |
25 * @see Zend_Loader |
25 * @see Zend_Loader |
58 * @todo Implement proxy settings |
58 * @todo Implement proxy settings |
59 * @category Zend |
59 * @category Zend |
60 * @package Zend_Http |
60 * @package Zend_Http |
61 * @subpackage Client |
61 * @subpackage Client |
62 * @throws Zend_Http_Client_Exception |
62 * @throws Zend_Http_Client_Exception |
63 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
63 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
64 * @license http://framework.zend.com/license/new-bsd New BSD License |
64 * @license http://framework.zend.com/license/new-bsd New BSD License |
65 */ |
65 */ |
66 class Zend_Http_Client |
66 class Zend_Http_Client |
67 { |
67 { |
68 /** |
68 /** |
75 const DELETE = 'DELETE'; |
75 const DELETE = 'DELETE'; |
76 const TRACE = 'TRACE'; |
76 const TRACE = 'TRACE'; |
77 const OPTIONS = 'OPTIONS'; |
77 const OPTIONS = 'OPTIONS'; |
78 const CONNECT = 'CONNECT'; |
78 const CONNECT = 'CONNECT'; |
79 const MERGE = 'MERGE'; |
79 const MERGE = 'MERGE'; |
|
80 const PATCH = 'PATCH'; |
80 |
81 |
81 /** |
82 /** |
82 * Supported HTTP Authentication methods |
83 * Supported HTTP Authentication methods |
83 */ |
84 */ |
84 const AUTH_BASIC = 'basic'; |
85 const AUTH_BASIC = 'basic'; |
266 * This variable is populated the first time _detectFileMimeType is called |
267 * This variable is populated the first time _detectFileMimeType is called |
267 * and is then reused on every call to this method |
268 * and is then reused on every call to this method |
268 * |
269 * |
269 * @var resource |
270 * @var resource |
270 */ |
271 */ |
271 static protected $_fileInfoDb = null; |
272 protected static $_fileInfoDb = null; |
272 |
273 |
273 /** |
274 /** |
274 * Constructor method. Will create a new HTTP client. Accepts the target |
275 * Constructor method. Will create a new HTTP client. Accepts the target |
275 * URL and optionally configuration array. |
276 * URL and optionally configuration array. |
276 * |
277 * |
383 * @throws Zend_Http_Client_Exception |
384 * @throws Zend_Http_Client_Exception |
384 */ |
385 */ |
385 public function setMethod($method = self::GET) |
386 public function setMethod($method = self::GET) |
386 { |
387 { |
387 if (! preg_match('/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/', $method)) { |
388 if (! preg_match('/^[^\x00-\x1f\x7f-\xff\(\)<>@,;:\\\\"\/\[\]\?={}\s]+$/', $method)) { |
388 /** @see Zend_Http_Client_Exception */ |
|
389 require_once 'Zend/Http/Client/Exception.php'; |
389 require_once 'Zend/Http/Client/Exception.php'; |
390 throw new Zend_Http_Client_Exception("'{$method}' is not a valid HTTP request method."); |
390 throw new Zend_Http_Client_Exception("'{$method}' is not a valid HTTP request method."); |
391 } |
391 } |
392 |
392 |
393 if (($method == self::POST || $method == self::PUT || $method == self::DELETE) && $this->enctype === null) { |
393 if (($method == self::POST |
|
394 || $method == self::PUT |
|
395 || $method == self::DELETE |
|
396 || $method == self::PATCH |
|
397 || $method == self::OPTIONS) |
|
398 && $this->enctype === null |
|
399 ) { |
394 $this->setEncType(self::ENC_URLENCODED); |
400 $this->setEncType(self::ENC_URLENCODED); |
395 } |
401 } |
396 |
402 |
397 $this->method = $method; |
403 $this->method = $method; |
398 |
404 |
757 'formname' => $formname, |
763 'formname' => $formname, |
758 'filename' => basename($filename), |
764 'filename' => basename($filename), |
759 'ctype' => $ctype, |
765 'ctype' => $ctype, |
760 'data' => $data |
766 'data' => $data |
761 ); |
767 ); |
762 |
768 |
763 $this->body_field_order[$formname] = self::VTYPE_FILE; |
769 $this->body_field_order[$formname] = self::VTYPE_FILE; |
764 |
770 |
765 return $this; |
771 return $this; |
766 } |
772 } |
767 |
773 |
1452 * @param mixed $value |
1458 * @param mixed $value |
1453 * @param string $filename |
1459 * @param string $filename |
1454 * @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary") |
1460 * @param array $headers Associative array of optional headers @example ("Content-Transfer-Encoding" => "binary") |
1455 * @return string |
1461 * @return string |
1456 */ |
1462 */ |
1457 public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) { |
1463 public static function encodeFormData($boundary, $name, $value, $filename = null, $headers = array()) |
|
1464 { |
1458 $ret = "--{$boundary}\r\n" . |
1465 $ret = "--{$boundary}\r\n" . |
1459 'Content-Disposition: form-data; name="' . $name .'"'; |
1466 'Content-Disposition: form-data; name="' . $name .'"'; |
1460 |
1467 |
1461 if ($filename) { |
1468 if ($filename) { |
1462 $ret .= '; filename="' . $filename . '"'; |
1469 $ret .= '; filename="' . $filename . '"'; |
1527 * |
1534 * |
1528 * @param array $parray |
1535 * @param array $parray |
1529 * @param string $prefix |
1536 * @param string $prefix |
1530 * @return array |
1537 * @return array |
1531 */ |
1538 */ |
1532 static protected function _flattenParametersArray($parray, $prefix = null) |
1539 protected static function _flattenParametersArray($parray, $prefix = null) |
1533 { |
1540 { |
1534 if (! is_array($parray)) { |
1541 if (! is_array($parray)) { |
1535 return $parray; |
1542 return $parray; |
1536 } |
1543 } |
1537 |
1544 |