*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Request2.php 324936 2012-04-07 07:49:03Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://tools.ietf.org/html/rfc2616#section-5\r
*/\r
'protocol_version' => '1.1',\r
'buffer_size' => 16384,\r
'store_body' => true,\r
+ 'local_ip' => null,\r
\r
'proxy_host' => '',\r
'proxy_port' => '',\r
$this->setMethod($method);\r
}\r
$this->setHeader(\r
- 'user-agent', 'HTTP_Request2/2.1.1 ' .\r
+ 'user-agent', 'HTTP_Request2/2.2.1 ' .\r
'(http://pear.php.net/package/http_request2) PHP/' . phpversion()\r
);\r
}\r
* <li> 'store_body' - Whether to store response body in response object.\r
* Set to false if receiving a huge response and\r
* using an Observer to save it (boolean)</li>\r
+ * <li> 'local_ip' - Specifies the IP address that will be used for accessing\r
+ * the network (string)</li>\r
* <li> 'proxy_type' - Proxy type, 'http' or 'socks5' (string)</li>\r
* <li> 'proxy_host' - Proxy server host (string)</li>\r
* <li> 'proxy_port' - Proxy server port (integer)</li>\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Adapter.php 324415 2012-03-21 10:50:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
abstract class HTTP_Request2_Adapter\r
if (empty($headers['content-type'])) {\r
$headers['content-type'] = 'application/x-www-form-urlencoded';\r
}\r
- $headers['content-length'] = $this->contentLength;\r
+ // Content-Length should not be sent for chunked Transfer-Encoding (bug #20125)\r
+ if (!isset($headers['transfer-encoding'])) {\r
+ $headers['content-length'] = $this->contentLength;\r
+ }\r
}\r
}\r
}\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Curl.php 324746 2012-04-03 15:09:16Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter\r
*\r
* @return resource a cURL handle, as created by curl_init()\r
* @throws HTTP_Request2_LogicException\r
+ * @throws HTTP_Request2_NotImplementedException\r
*/\r
protected function createCurlHandle()\r
{\r
}\r
}\r
\r
+ // set local IP via CURLOPT_INTERFACE (request #19515)\r
+ if ($ip = $this->request->getConfig('local_ip')) {\r
+ curl_setopt($ch, CURLOPT_INTERFACE, $ip);\r
+ }\r
+\r
// request timeout\r
if ($timeout = $this->request->getConfig('timeout')) {\r
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);\r
}\r
\r
$this->calculateRequestLength($headers);\r
- if (isset($headers['content-length'])) {\r
+ if (isset($headers['content-length']) || isset($headers['transfer-encoding'])) {\r
$this->workaroundPhpBug47204($ch, $headers);\r
}\r
\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Mock.php 324937 2012-04-07 10:05:57Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Socket.php 324953 2012-04-08 07:24:12Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/** Base class for HTTP_Request2 adapters */\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter\r
/**\r
* Regular expression for 'quoted-string' rule from RFC 2616\r
*/\r
- const REGEXP_QUOTED_STRING = '"(?:\\\\.|[^\\\\"])*"';\r
+ const REGEXP_QUOTED_STRING = '"(?>[^"\\\\]+|\\\\.)*"';\r
\r
/**\r
* Connected sockets, needed for Keep-Alive support\r
*/\r
protected $redirectCountdown = null;\r
\r
+ /**\r
+ * Whether to wait for "100 Continue" response before sending request body\r
+ * @var bool\r
+ */\r
+ protected $expect100Continue = false;\r
+\r
/**\r
* Sends request to the remote server and returns its response\r
*\r
$this->socket->write($headers);\r
// provide request headers to the observer, see request #7633\r
$this->request->setLastEvent('sentHeaders', $headers);\r
- $this->writeBody();\r
\r
- $response = $this->readResponse();\r
+ if (!$this->expect100Continue) {\r
+ $this->writeBody();\r
+ $response = $this->readResponse();\r
+\r
+ } else {\r
+ $response = $this->readResponse();\r
+ if (!$response || 100 == $response->getStatus()) {\r
+ $this->expect100Continue = false;\r
+ // either got "100 Continue" or timed out -> send body\r
+ $this->writeBody();\r
+ $response = $this->readResponse();\r
+ }\r
+ }\r
+\r
\r
if ($jar = $request->getCookieJar()) {\r
$jar->addCookiesFromResponse($response, $request->getUrl());\r
'Keep-Alive' == $headers['connection']);\r
\r
$options = array();\r
+ if ($ip = $this->request->getConfig('local_ip')) {\r
+ $options['socket'] = array(\r
+ 'bindto' => (false === strpos($ip, ':') ? $ip : '[' . $ip . ']') . ':0'\r
+ );\r
+ }\r
if ($secure || $tunnel) {\r
+ $options['ssl'] = array();\r
foreach ($this->request->getConfig() as $name => $value) {\r
if ('ssl_' == substr($name, 0, 4) && null !== $value) {\r
if ('ssl_verify_host' == $name) {\r
if ($value) {\r
- $options['CN_match'] = $reqHost;\r
+ $options['ssl']['CN_match'] = $reqHost;\r
}\r
} else {\r
- $options[substr($name, 4)] = $value;\r
+ $options['ssl'][substr($name, 4)] = $value;\r
}\r
}\r
}\r
- ksort($options);\r
+ ksort($options['ssl']);\r
}\r
\r
// Use global request timeout if given, see feature requests #5735, #8964\r
$this->addAuthorizationHeader($headers, $host, $requestUrl);\r
$this->addProxyAuthorizationHeader($headers, $requestUrl);\r
$this->calculateRequestLength($headers);\r
+ if ('1.1' == $this->request->getConfig('protocol_version')) {\r
+ $this->updateExpectHeader($headers);\r
+ } else {\r
+ $this->expect100Continue = false;\r
+ }\r
\r
$headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' .\r
$this->request->getConfig('protocol_version') . "\r\n";\r
return $headersStr . "\r\n";\r
}\r
\r
+ /**\r
+ * Adds or removes 'Expect: 100-continue' header from request headers\r
+ *\r
+ * Also sets the $expect100Continue property. Parsing of existing header\r
+ * is somewhat needed due to its complex structure and due to the\r
+ * requirement in section 8.2.3 of RFC 2616:\r
+ * > A client MUST NOT send an Expect request-header field (section\r
+ * > 14.20) with the "100-continue" expectation if it does not intend\r
+ * > to send a request body.\r
+ *\r
+ * @param array &$headers Array of headers prepared for the request\r
+ *\r
+ * @throws HTTP_Request2_LogicException\r
+ * @link http://pear.php.net/bugs/bug.php?id=19233\r
+ * @link http://tools.ietf.org/html/rfc2616#section-8.2.3\r
+ */\r
+ protected function updateExpectHeader(&$headers)\r
+ {\r
+ $this->expect100Continue = false;\r
+ $expectations = array();\r
+ if (isset($headers['expect'])) {\r
+ if ('' === $headers['expect']) {\r
+ // empty 'Expect' header is technically invalid, so just get rid of it\r
+ unset($headers['expect']);\r
+ return;\r
+ }\r
+ // build regexp to parse the value of existing Expect header\r
+ $expectParam = ';\s*' . self::REGEXP_TOKEN . '(?:\s*=\s*(?:'\r
+ . self::REGEXP_TOKEN . '|'\r
+ . self::REGEXP_QUOTED_STRING . '))?\s*';\r
+ $expectExtension = self::REGEXP_TOKEN . '(?:\s*=\s*(?:'\r
+ . self::REGEXP_TOKEN . '|'\r
+ . self::REGEXP_QUOTED_STRING . ')\s*(?:'\r
+ . $expectParam . ')*)?';\r
+ $expectItem = '!(100-continue|' . $expectExtension . ')!A';\r
+\r
+ $pos = 0;\r
+ $length = strlen($headers['expect']);\r
+\r
+ while ($pos < $length) {\r
+ $pos += strspn($headers['expect'], " \t", $pos);\r
+ if (',' === substr($headers['expect'], $pos, 1)) {\r
+ $pos++;\r
+ continue;\r
+\r
+ } elseif (!preg_match($expectItem, $headers['expect'], $m, 0, $pos)) {\r
+ throw new HTTP_Request2_LogicException(\r
+ "Cannot parse value '{$headers['expect']}' of Expect header",\r
+ HTTP_Request2_Exception::INVALID_ARGUMENT\r
+ );\r
+\r
+ } else {\r
+ $pos += strlen($m[0]);\r
+ if (strcasecmp('100-continue', $m[0])) {\r
+ $expectations[] = $m[0];\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ if (1024 < $this->contentLength) {\r
+ $expectations[] = '100-continue';\r
+ $this->expect100Continue = true;\r
+ }\r
+\r
+ if (empty($expectations)) {\r
+ unset($headers['expect']);\r
+ } else {\r
+ $headers['expect'] = implode(',', $expectations);\r
+ }\r
+ }\r
+\r
/**\r
* Sends the request body\r
*\r
\r
$position = 0;\r
$bufferSize = $this->request->getConfig('buffer_size');\r
+ $headers = $this->request->getHeaders();\r
+ $chunked = isset($headers['transfer-encoding']);\r
while ($position < $this->contentLength) {\r
if (is_string($this->requestBody)) {\r
$str = substr($this->requestBody, $position, $bufferSize);\r
} else {\r
$str = $this->requestBody->read($bufferSize);\r
}\r
- $this->socket->write($str);\r
+ if (!$chunked) {\r
+ $this->socket->write($str);\r
+ } else {\r
+ $this->socket->write(dechex(strlen($str)) . "\r\n{$str}\r\n");\r
+ }\r
// Provide the length of written string to the observer, request #7630\r
$this->request->setLastEvent('sentBodyPart', strlen($str));\r
$position += strlen($str);\r
}\r
+\r
+ // write zero-length chunk\r
+ if ($chunked) {\r
+ $this->socket->write("0\r\n\r\n");\r
+ }\r
$this->request->setLastEvent('sentBody', $this->contentLength);\r
}\r
\r
protected function readResponse()\r
{\r
$bufferSize = $this->request->getConfig('buffer_size');\r
+ // http://tools.ietf.org/html/rfc2616#section-8.2.3\r
+ // ...the client SHOULD NOT wait for an indefinite period before sending the request body\r
+ $timeout = $this->expect100Continue ? 1 : null;\r
\r
do {\r
- $response = new HTTP_Request2_Response(\r
- $this->socket->readLine($bufferSize), true, $this->request->getUrl()\r
- );\r
- do {\r
- $headerLine = $this->socket->readLine($bufferSize);\r
- $response->parseHeaderLine($headerLine);\r
- } while ('' != $headerLine);\r
+ try {\r
+ $response = new HTTP_Request2_Response(\r
+ $this->socket->readLine($bufferSize, $timeout), true, $this->request->getUrl()\r
+ );\r
+ do {\r
+ $headerLine = $this->socket->readLine($bufferSize);\r
+ $response->parseHeaderLine($headerLine);\r
+ } while ('' != $headerLine);\r
+\r
+ } catch (HTTP_Request2_MessageException $e) {\r
+ if (HTTP_Request2_Exception::TIMEOUT === $e->getCode()\r
+ && $this->expect100Continue\r
+ ) {\r
+ return null;\r
+ }\r
+ throw $e;\r
+ }\r
+ if ($this->expect100Continue && 100 == $response->getStatus()) {\r
+ return $response;\r
+ }\r
} while (in_array($response->getStatus(), array(100, 101)));\r
\r
$this->request->setLastEvent('receivedHeaders', $response);\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: CookieJar.php 324415 2012-03-21 10:50:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/** Class representing a HTTP request message */\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
* @version Release: @package_version@\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
- *\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Exception.php 324415 2012-03-21 10:50:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
+ *\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132\r
*/\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_LogicException extends HTTP_Request2_Exception\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_MessageException extends HTTP_Request2_Exception\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: MultipartBody.php 324415 2012-03-21 10:50:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
+/** Exception class for HTTP_Request2 package */\r
+require_once 'HTTP/Request2/Exception.php';\r
+\r
/**\r
* Class for building multipart/form-data request body\r
*\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://tools.ietf.org/html/rfc1867\r
*/\r
* @param integer $length Number of bytes to read\r
*\r
* @return string Up to $length bytes of data, empty string if at end\r
+ * @throws HTTP_Request2_LogicException\r
*/\r
public function read($length)\r
{\r
$length -= min(strlen($header) - $this->_pos[1], $length);\r
}\r
$filePos = max(0, $this->_pos[1] - strlen($header));\r
- if ($length > 0 && $filePos < $this->_uploads[$pos]['size']) {\r
- $ret .= fread($this->_uploads[$pos]['fp'], $length);\r
- $length -= min($length, $this->_uploads[$pos]['size'] - $filePos);\r
+ if ($filePos < $this->_uploads[$pos]['size']) {\r
+ while ($length > 0 && !feof($this->_uploads[$pos]['fp'])) {\r
+ if (false === ($chunk = fread($this->_uploads[$pos]['fp'], $length))) {\r
+ throw new HTTP_Request2_LogicException(\r
+ 'Failed reading file upload', HTTP_Request2_Exception::READ_ERROR\r
+ );\r
+ }\r
+ $ret .= $chunk;\r
+ $length -= strlen($chunk);\r
+ }\r
}\r
if ($length > 0) {\r
$start = $this->_pos[1] + ($oldLength - $length) -\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author David Jean Louis <izi@php.net>\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Log.php 324415 2012-03-21 10:50:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author David Jean Louis <izi@php.net>\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @package HTTP_Request2\r
* @author David Jean Louis <izi@php.net>\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
class HTTP_Request2_Observer_Log implements SplObserver\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: Response.php 324936 2012-04-07 07:49:03Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/**\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://tools.ietf.org/html/rfc2616#section-6\r
*/\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: SOCKS5.php 324953 2012-04-08 07:24:12Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/** Socket wrapper class used by Socket Adapter */\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://pear.php.net/bugs/bug.php?id=19332\r
* @link http://tools.ietf.org/html/rfc1928\r
/**\r
* Constructor, tries to connect and authenticate to a SOCKS5 proxy\r
*\r
- * @param string $address Proxy address, e.g. 'tcp://localhost:1080'\r
- * @param int $timeout Connection timeout (seconds)\r
- * @param array $sslOptions SSL context options\r
- * @param string $username Proxy user name\r
- * @param string $password Proxy password\r
+ * @param string $address Proxy address, e.g. 'tcp://localhost:1080'\r
+ * @param int $timeout Connection timeout (seconds)\r
+ * @param array $contextOptions Stream context options\r
+ * @param string $username Proxy user name\r
+ * @param string $password Proxy password\r
*\r
* @throws HTTP_Request2_LogicException\r
* @throws HTTP_Request2_ConnectionException\r
* @throws HTTP_Request2_MessageException\r
*/\r
public function __construct(\r
- $address, $timeout = 10, array $sslOptions = array(),\r
+ $address, $timeout = 10, array $contextOptions = array(),\r
$username = null, $password = null\r
) {\r
- parent::__construct($address, $timeout, $sslOptions);\r
+ parent::__construct($address, $timeout, $contextOptions);\r
\r
if (strlen($username)) {\r
$request = pack('C4', 5, 2, 0, 2);\r
*\r
* PHP version 5\r
*\r
- * LICENSE:\r
+ * LICENSE\r
*\r
- * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>\r
- * All rights reserved.\r
+ * This source file is subject to BSD 3-Clause License that is bundled\r
+ * with this package in the file LICENSE and available at the URL\r
+ * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE\r
*\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * * Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * * Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * * The names of the authors may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\r
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * @category HTTP\r
- * @package HTTP_Request2\r
- * @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version SVN: $Id: SocketWrapper.php 324935 2012-04-07 07:10:50Z avb $\r
- * @link http://pear.php.net/package/HTTP_Request2\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @author Alexey Borzov <avb@php.net>\r
+ * @copyright 2008-2014 Alexey Borzov <avb@php.net>\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
/** Exception classes for HTTP_Request2 package */\r
* @category HTTP\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
- * @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version Release: 2.1.1\r
+ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License\r
+ * @version Release: 2.2.1\r
* @link http://pear.php.net/package/HTTP_Request2\r
* @link http://pear.php.net/bugs/bug.php?id=19332\r
* @link http://tools.ietf.org/html/rfc1928\r
/**\r
* Class constructor, tries to establish connection\r
*\r
- * @param string $address Address for stream_socket_client() call,\r
- * e.g. 'tcp://localhost:80'\r
- * @param int $timeout Connection timeout (seconds)\r
- * @param array $sslOptions SSL context options\r
+ * @param string $address Address for stream_socket_client() call,\r
+ * e.g. 'tcp://localhost:80'\r
+ * @param int $timeout Connection timeout (seconds)\r
+ * @param array $contextOptions Context options\r
*\r
* @throws HTTP_Request2_LogicException\r
* @throws HTTP_Request2_ConnectionException\r
*/\r
- public function __construct($address, $timeout, array $sslOptions = array())\r
+ public function __construct($address, $timeout, array $contextOptions = array())\r
{\r
+ if (!empty($contextOptions)\r
+ && !isset($contextOptions['socket']) && !isset($contextOptions['ssl'])\r
+ ) {\r
+ // Backwards compatibility with 2.1.0 and 2.1.1 releases\r
+ $contextOptions = array('ssl' => $contextOptions);\r
+ }\r
$context = stream_context_create();\r
- foreach ($sslOptions as $name => $value) {\r
- if (!stream_context_set_option($context, 'ssl', $name, $value)) {\r
- throw new HTTP_Request2_LogicException(\r
- "Error setting SSL context option '{$name}'"\r
- );\r
+ foreach ($contextOptions as $wrapper => $options) {\r
+ foreach ($options as $name => $value) {\r
+ if (!stream_context_set_option($context, $wrapper, $name, $value)) {\r
+ throw new HTTP_Request2_LogicException(\r
+ "Error setting '{$wrapper}' wrapper context option '{$name}'"\r
+ );\r
+ }\r
}\r
}\r
set_error_handler(array($this, 'connectionWarningsHandler'));\r
$address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context\r
);\r
restore_error_handler();\r
- if (!$this->socket) {\r
+ // if we fail to bind to a specified local address (see request #19515),\r
+ // connection still succeeds, albeit with a warning. Throw an Exception\r
+ // with the warning text in this case as that connection is unlikely\r
+ // to be what user wants and as Curl throws an error in similar case.\r
+ if ($this->connectionWarnings) {\r
+ if ($this->socket) {\r
+ fclose($this->socket);\r
+ }\r
$error = $errstr ? $errstr : implode("\n", $this->connectionWarnings);\r
throw new HTTP_Request2_ConnectionException(\r
"Unable to connect to {$address}. Error: {$error}", 0, $errno\r
* Strips the trailing newline from the returned data, handles global\r
* request timeout. Method idea borrowed from Net_Socket PEAR package.\r
*\r
- * @param int $bufferSize buffer size to use for reading\r
+ * @param int $bufferSize buffer size to use for reading\r
+ * @param int $localTimeout timeout value to use just for this call\r
+ * (used when waiting for "100 Continue" response)\r
*\r
* @return string Available data up to the newline (not including newline)\r
* @throws HTTP_Request2_MessageException In case of timeout\r
*/\r
- public function readLine($bufferSize)\r
+ public function readLine($bufferSize, $localTimeout = null)\r
{\r
$line = '';\r
while (!feof($this->socket)) {\r
- if ($this->deadline) {\r
+ if (null !== $localTimeout) {\r
+ stream_set_timeout($this->socket, $localTimeout);\r
+ } elseif ($this->deadline) {\r
stream_set_timeout($this->socket, max($this->deadline - time(), 1));\r
}\r
+\r
$line .= @fgets($this->socket, $bufferSize);\r
- $this->checkTimeout();\r
+\r
+ if (null === $localTimeout) {\r
+ $this->checkTimeout();\r
+\r
+ } else {\r
+ $info = stream_get_meta_data($this->socket);\r
+ // reset socket timeout if we don't have request timeout specified,\r
+ // prevents further calls failing with a bogus Exception\r
+ if (!$this->deadline) {\r
+ $default = (int)@ini_get('default_socket_timeout');\r
+ stream_set_timeout($this->socket, $default > 0 ? $default : PHP_INT_MAX);\r
+ }\r
+ if ($info['timed_out']) {\r
+ throw new HTTP_Request2_MessageException(\r
+ "readLine() call timed out", HTTP_Request2_Exception::TIMEOUT\r
+ );\r
+ }\r
+ }\r
if (substr($line, -1) == "\n") {\r
return rtrim($line, "\r\n");\r
}\r
--- /dev/null
+HTTP_Request2\r
+\r
+Copyright (c) 2008-2014, Alexey Borzov <avb@php.net>\r
+All rights reserved.\r
+\r
+Redistribution and use in source and binary forms, with or without\r
+modification, are permitted provided that the following conditions\r
+are met:\r
+\r
+ 1. Redistributions of source code must retain the above copyright\r
+ notice, this list of conditions and the following disclaimer.\r
+\r
+ 2. Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in the\r
+ documentation and/or other materials provided with the distribution.\r
+\r
+ 3. Neither the name of Alexey Borzov nor the names of his contributors\r
+ may be used to endorse or promote products derived from this software\r
+ without specific prior written permission.\r
+\r
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\r
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
+THE POSSIBILITY OF SUCH DAMAGE.\r