PEAR::HTTP_Request2 updated to 2.2.1

Release date: 2014-01-16 19:53 UTC
This commit is contained in:
Mikael Nordfeldth 2014-07-10 16:23:21 +02:00
parent b3d6c51c79
commit e328fd7901
13 changed files with 413 additions and 470 deletions

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Request2.php 324936 2012-04-07 07:49:03Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -57,8 +34,8 @@ require_once 'HTTP/Request2/Exception.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://tools.ietf.org/html/rfc2616#section-5 * @link http://tools.ietf.org/html/rfc2616#section-5
*/ */
@ -152,6 +129,7 @@ class HTTP_Request2 implements SplSubject
'protocol_version' => '1.1', 'protocol_version' => '1.1',
'buffer_size' => 16384, 'buffer_size' => 16384,
'store_body' => true, 'store_body' => true,
'local_ip' => null,
'proxy_host' => '', 'proxy_host' => '',
'proxy_port' => '', 'proxy_port' => '',
@ -235,7 +213,7 @@ class HTTP_Request2 implements SplSubject
$this->setMethod($method); $this->setMethod($method);
} }
$this->setHeader( $this->setHeader(
'user-agent', 'HTTP_Request2/2.1.1 ' . 'user-agent', 'HTTP_Request2/2.2.1 ' .
'(http://pear.php.net/package/http_request2) PHP/' . phpversion() '(http://pear.php.net/package/http_request2) PHP/' . phpversion()
); );
} }
@ -338,6 +316,8 @@ class HTTP_Request2 implements SplSubject
* <li> 'store_body' - Whether to store response body in response object. * <li> 'store_body' - Whether to store response body in response object.
* Set to false if receiving a huge response and * Set to false if receiving a huge response and
* using an Observer to save it (boolean)</li> * using an Observer to save it (boolean)</li>
* <li> 'local_ip' - Specifies the IP address that will be used for accessing
* the network (string)</li>
* <li> 'proxy_type' - Proxy type, 'http' or 'socks5' (string)</li> * <li> 'proxy_type' - Proxy type, 'http' or 'socks5' (string)</li>
* <li> 'proxy_host' - Proxy server host (string)</li> * <li> 'proxy_host' - Proxy server host (string)</li>
* <li> 'proxy_port' - Proxy server port (integer)</li> * <li> 'proxy_port' - Proxy server port (integer)</li>

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Adapter.php 324415 2012-03-21 10:50:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -56,8 +33,8 @@ require_once 'HTTP/Request2/Response.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
abstract class HTTP_Request2_Adapter abstract class HTTP_Request2_Adapter
@ -150,8 +127,11 @@ abstract class HTTP_Request2_Adapter
if (empty($headers['content-type'])) { if (empty($headers['content-type'])) {
$headers['content-type'] = 'application/x-www-form-urlencoded'; $headers['content-type'] = 'application/x-www-form-urlencoded';
} }
// Content-Length should not be sent for chunked Transfer-Encoding (bug #20125)
if (!isset($headers['transfer-encoding'])) {
$headers['content-length'] = $this->contentLength; $headers['content-length'] = $this->contentLength;
} }
} }
} }
}
?> ?>

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Curl.php 324746 2012-04-03 15:09:16Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -52,8 +29,8 @@ require_once 'HTTP/Request2/Adapter.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
@ -238,6 +215,7 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
* *
* @return resource a cURL handle, as created by curl_init() * @return resource a cURL handle, as created by curl_init()
* @throws HTTP_Request2_LogicException * @throws HTTP_Request2_LogicException
* @throws HTTP_Request2_NotImplementedException
*/ */
protected function createCurlHandle() protected function createCurlHandle()
{ {
@ -278,6 +256,11 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
} }
} }
// set local IP via CURLOPT_INTERFACE (request #19515)
if ($ip = $this->request->getConfig('local_ip')) {
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
}
// request timeout // request timeout
if ($timeout = $this->request->getConfig('timeout')) { if ($timeout = $this->request->getConfig('timeout')) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
@ -389,7 +372,7 @@ class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
} }
$this->calculateRequestLength($headers); $this->calculateRequestLength($headers);
if (isset($headers['content-length'])) { if (isset($headers['content-length']) || isset($headers['transfer-encoding'])) {
$this->workaroundPhpBug47204($ch, $headers); $this->workaroundPhpBug47204($ch, $headers);
} }

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Mock.php 324937 2012-04-07 10:05:57Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -66,8 +43,8 @@ require_once 'HTTP/Request2/Adapter.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Socket.php 324953 2012-04-08 07:24:12Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -56,8 +33,8 @@ require_once 'HTTP/Request2/SocketWrapper.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
@ -70,7 +47,7 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
/** /**
* Regular expression for 'quoted-string' rule from RFC 2616 * Regular expression for 'quoted-string' rule from RFC 2616
*/ */
const REGEXP_QUOTED_STRING = '"(?:\\\\.|[^\\\\"])*"'; const REGEXP_QUOTED_STRING = '"(?>[^"\\\\]+|\\\\.)*"';
/** /**
* Connected sockets, needed for Keep-Alive support * Connected sockets, needed for Keep-Alive support
@ -129,6 +106,12 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
*/ */
protected $redirectCountdown = null; protected $redirectCountdown = null;
/**
* Whether to wait for "100 Continue" response before sending request body
* @var bool
*/
protected $expect100Continue = false;
/** /**
* Sends request to the remote server and returns its response * Sends request to the remote server and returns its response
* *
@ -147,10 +130,22 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
$this->socket->write($headers); $this->socket->write($headers);
// provide request headers to the observer, see request #7633 // provide request headers to the observer, see request #7633
$this->request->setLastEvent('sentHeaders', $headers); $this->request->setLastEvent('sentHeaders', $headers);
$this->writeBody();
if (!$this->expect100Continue) {
$this->writeBody();
$response = $this->readResponse(); $response = $this->readResponse();
} else {
$response = $this->readResponse();
if (!$response || 100 == $response->getStatus()) {
$this->expect100Continue = false;
// either got "100 Continue" or timed out -> send body
$this->writeBody();
$response = $this->readResponse();
}
}
if ($jar = $request->getCookieJar()) { if ($jar = $request->getCookieJar()) {
$jar->addCookiesFromResponse($response, $request->getUrl()); $jar->addCookiesFromResponse($response, $request->getUrl());
} }
@ -256,19 +251,25 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
'Keep-Alive' == $headers['connection']); 'Keep-Alive' == $headers['connection']);
$options = array(); $options = array();
if ($ip = $this->request->getConfig('local_ip')) {
$options['socket'] = array(
'bindto' => (false === strpos($ip, ':') ? $ip : '[' . $ip . ']') . ':0'
);
}
if ($secure || $tunnel) { if ($secure || $tunnel) {
$options['ssl'] = array();
foreach ($this->request->getConfig() as $name => $value) { foreach ($this->request->getConfig() as $name => $value) {
if ('ssl_' == substr($name, 0, 4) && null !== $value) { if ('ssl_' == substr($name, 0, 4) && null !== $value) {
if ('ssl_verify_host' == $name) { if ('ssl_verify_host' == $name) {
if ($value) { if ($value) {
$options['CN_match'] = $reqHost; $options['ssl']['CN_match'] = $reqHost;
} }
} else { } else {
$options[substr($name, 4)] = $value; $options['ssl'][substr($name, 4)] = $value;
} }
} }
} }
ksort($options); ksort($options['ssl']);
} }
// Use global request timeout if given, see feature requests #5735, #8964 // Use global request timeout if given, see feature requests #5735, #8964
@ -863,6 +864,11 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
$this->addAuthorizationHeader($headers, $host, $requestUrl); $this->addAuthorizationHeader($headers, $host, $requestUrl);
$this->addProxyAuthorizationHeader($headers, $requestUrl); $this->addProxyAuthorizationHeader($headers, $requestUrl);
$this->calculateRequestLength($headers); $this->calculateRequestLength($headers);
if ('1.1' == $this->request->getConfig('protocol_version')) {
$this->updateExpectHeader($headers);
} else {
$this->expect100Continue = false;
}
$headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' . $headersStr = $this->request->getMethod() . ' ' . $requestUrl . ' HTTP/' .
$this->request->getConfig('protocol_version') . "\r\n"; $this->request->getConfig('protocol_version') . "\r\n";
@ -873,6 +879,78 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
return $headersStr . "\r\n"; return $headersStr . "\r\n";
} }
/**
* Adds or removes 'Expect: 100-continue' header from request headers
*
* Also sets the $expect100Continue property. Parsing of existing header
* is somewhat needed due to its complex structure and due to the
* requirement in section 8.2.3 of RFC 2616:
* > A client MUST NOT send an Expect request-header field (section
* > 14.20) with the "100-continue" expectation if it does not intend
* > to send a request body.
*
* @param array &$headers Array of headers prepared for the request
*
* @throws HTTP_Request2_LogicException
* @link http://pear.php.net/bugs/bug.php?id=19233
* @link http://tools.ietf.org/html/rfc2616#section-8.2.3
*/
protected function updateExpectHeader(&$headers)
{
$this->expect100Continue = false;
$expectations = array();
if (isset($headers['expect'])) {
if ('' === $headers['expect']) {
// empty 'Expect' header is technically invalid, so just get rid of it
unset($headers['expect']);
return;
}
// build regexp to parse the value of existing Expect header
$expectParam = ';\s*' . self::REGEXP_TOKEN . '(?:\s*=\s*(?:'
. self::REGEXP_TOKEN . '|'
. self::REGEXP_QUOTED_STRING . '))?\s*';
$expectExtension = self::REGEXP_TOKEN . '(?:\s*=\s*(?:'
. self::REGEXP_TOKEN . '|'
. self::REGEXP_QUOTED_STRING . ')\s*(?:'
. $expectParam . ')*)?';
$expectItem = '!(100-continue|' . $expectExtension . ')!A';
$pos = 0;
$length = strlen($headers['expect']);
while ($pos < $length) {
$pos += strspn($headers['expect'], " \t", $pos);
if (',' === substr($headers['expect'], $pos, 1)) {
$pos++;
continue;
} elseif (!preg_match($expectItem, $headers['expect'], $m, 0, $pos)) {
throw new HTTP_Request2_LogicException(
"Cannot parse value '{$headers['expect']}' of Expect header",
HTTP_Request2_Exception::INVALID_ARGUMENT
);
} else {
$pos += strlen($m[0]);
if (strcasecmp('100-continue', $m[0])) {
$expectations[] = $m[0];
}
}
}
}
if (1024 < $this->contentLength) {
$expectations[] = '100-continue';
$this->expect100Continue = true;
}
if (empty($expectations)) {
unset($headers['expect']);
} else {
$headers['expect'] = implode(',', $expectations);
}
}
/** /**
* Sends the request body * Sends the request body
* *
@ -888,6 +966,8 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
$position = 0; $position = 0;
$bufferSize = $this->request->getConfig('buffer_size'); $bufferSize = $this->request->getConfig('buffer_size');
$headers = $this->request->getHeaders();
$chunked = isset($headers['transfer-encoding']);
while ($position < $this->contentLength) { while ($position < $this->contentLength) {
if (is_string($this->requestBody)) { if (is_string($this->requestBody)) {
$str = substr($this->requestBody, $position, $bufferSize); $str = substr($this->requestBody, $position, $bufferSize);
@ -896,11 +976,20 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
} else { } else {
$str = $this->requestBody->read($bufferSize); $str = $this->requestBody->read($bufferSize);
} }
if (!$chunked) {
$this->socket->write($str); $this->socket->write($str);
} else {
$this->socket->write(dechex(strlen($str)) . "\r\n{$str}\r\n");
}
// Provide the length of written string to the observer, request #7630 // Provide the length of written string to the observer, request #7630
$this->request->setLastEvent('sentBodyPart', strlen($str)); $this->request->setLastEvent('sentBodyPart', strlen($str));
$position += strlen($str); $position += strlen($str);
} }
// write zero-length chunk
if ($chunked) {
$this->socket->write("0\r\n\r\n");
}
$this->request->setLastEvent('sentBody', $this->contentLength); $this->request->setLastEvent('sentBody', $this->contentLength);
} }
@ -913,15 +1002,31 @@ class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter
protected function readResponse() protected function readResponse()
{ {
$bufferSize = $this->request->getConfig('buffer_size'); $bufferSize = $this->request->getConfig('buffer_size');
// http://tools.ietf.org/html/rfc2616#section-8.2.3
// ...the client SHOULD NOT wait for an indefinite period before sending the request body
$timeout = $this->expect100Continue ? 1 : null;
do { do {
try {
$response = new HTTP_Request2_Response( $response = new HTTP_Request2_Response(
$this->socket->readLine($bufferSize), true, $this->request->getUrl() $this->socket->readLine($bufferSize, $timeout), true, $this->request->getUrl()
); );
do { do {
$headerLine = $this->socket->readLine($bufferSize); $headerLine = $this->socket->readLine($bufferSize);
$response->parseHeaderLine($headerLine); $response->parseHeaderLine($headerLine);
} while ('' != $headerLine); } while ('' != $headerLine);
} catch (HTTP_Request2_MessageException $e) {
if (HTTP_Request2_Exception::TIMEOUT === $e->getCode()
&& $this->expect100Continue
) {
return null;
}
throw $e;
}
if ($this->expect100Continue && 100 == $response->getStatus()) {
return $response;
}
} while (in_array($response->getStatus(), array(100, 101))); } while (in_array($response->getStatus(), array(100, 101)));
$this->request->setLastEvent('receivedHeaders', $response); $this->request->setLastEvent('receivedHeaders', $response);

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: CookieJar.php 324415 2012-03-21 10:50:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -50,7 +27,7 @@ require_once 'HTTP/Request2.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Exception.php 324415 2012-03-21 10:50:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -52,8 +29,8 @@ require_once 'PEAR/Exception.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132 * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
*/ */
@ -119,8 +96,8 @@ class HTTP_Request2_Exception extends PEAR_Exception
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
@ -140,8 +117,8 @@ class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_LogicException extends HTTP_Request2_Exception class HTTP_Request2_LogicException extends HTTP_Request2_Exception
@ -157,8 +134,8 @@ class HTTP_Request2_LogicException extends HTTP_Request2_Exception
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
@ -173,8 +150,8 @@ class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_MessageException extends HTTP_Request2_Exception class HTTP_Request2_MessageException extends HTTP_Request2_Exception

View File

@ -4,43 +4,23 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: MultipartBody.php 324415 2012-03-21 10:50:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
/** Exception class for HTTP_Request2 package */
require_once 'HTTP/Request2/Exception.php';
/** /**
* Class for building multipart/form-data request body * Class for building multipart/form-data request body
* *
@ -50,8 +30,8 @@
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://tools.ietf.org/html/rfc1867 * @link http://tools.ietf.org/html/rfc1867
*/ */
@ -167,6 +147,7 @@ class HTTP_Request2_MultipartBody
* @param integer $length Number of bytes to read * @param integer $length Number of bytes to read
* *
* @return string Up to $length bytes of data, empty string if at end * @return string Up to $length bytes of data, empty string if at end
* @throws HTTP_Request2_LogicException
*/ */
public function read($length) public function read($length)
{ {
@ -194,9 +175,16 @@ class HTTP_Request2_MultipartBody
$length -= min(strlen($header) - $this->_pos[1], $length); $length -= min(strlen($header) - $this->_pos[1], $length);
} }
$filePos = max(0, $this->_pos[1] - strlen($header)); $filePos = max(0, $this->_pos[1] - strlen($header));
if ($length > 0 && $filePos < $this->_uploads[$pos]['size']) { if ($filePos < $this->_uploads[$pos]['size']) {
$ret .= fread($this->_uploads[$pos]['fp'], $length); while ($length > 0 && !feof($this->_uploads[$pos]['fp'])) {
$length -= min($length, $this->_uploads[$pos]['size'] - $filePos); if (false === ($chunk = fread($this->_uploads[$pos]['fp'], $length))) {
throw new HTTP_Request2_LogicException(
'Failed reading file upload', HTTP_Request2_Exception::READ_ERROR
);
}
$ret .= $chunk;
$length -= strlen($chunk);
}
} }
if ($length > 0) { if ($length > 0) {
$start = $this->_pos[1] + ($oldLength - $length) - $start = $this->_pos[1] + ($oldLength - $length) -

View File

@ -4,41 +4,18 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author David Jean Louis <izi@php.net> * @author David Jean Louis <izi@php.net>
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Log.php 324415 2012-03-21 10:50:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -86,8 +63,8 @@ require_once 'HTTP/Request2/Exception.php';
* @package HTTP_Request2 * @package HTTP_Request2
* @author David Jean Louis <izi@php.net> * @author David Jean Louis <izi@php.net>
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
class HTTP_Request2_Observer_Log implements SplObserver class HTTP_Request2_Observer_Log implements SplObserver

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: Response.php 324936 2012-04-07 07:49:03Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -69,8 +46,8 @@ require_once 'HTTP/Request2/Exception.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://tools.ietf.org/html/rfc2616#section-6 * @link http://tools.ietf.org/html/rfc2616#section-6
*/ */

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: SOCKS5.php 324953 2012-04-08 07:24:12Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -50,8 +27,8 @@ require_once 'HTTP/Request2/SocketWrapper.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://pear.php.net/bugs/bug.php?id=19332 * @link http://pear.php.net/bugs/bug.php?id=19332
* @link http://tools.ietf.org/html/rfc1928 * @link http://tools.ietf.org/html/rfc1928
@ -63,7 +40,7 @@ class HTTP_Request2_SOCKS5 extends HTTP_Request2_SocketWrapper
* *
* @param string $address Proxy address, e.g. 'tcp://localhost:1080' * @param string $address Proxy address, e.g. 'tcp://localhost:1080'
* @param int $timeout Connection timeout (seconds) * @param int $timeout Connection timeout (seconds)
* @param array $sslOptions SSL context options * @param array $contextOptions Stream context options
* @param string $username Proxy user name * @param string $username Proxy user name
* @param string $password Proxy password * @param string $password Proxy password
* *
@ -72,10 +49,10 @@ class HTTP_Request2_SOCKS5 extends HTTP_Request2_SocketWrapper
* @throws HTTP_Request2_MessageException * @throws HTTP_Request2_MessageException
*/ */
public function __construct( public function __construct(
$address, $timeout = 10, array $sslOptions = array(), $address, $timeout = 10, array $contextOptions = array(),
$username = null, $password = null $username = null, $password = null
) { ) {
parent::__construct($address, $timeout, $sslOptions); parent::__construct($address, $timeout, $contextOptions);
if (strlen($username)) { if (strlen($username)) {
$request = pack('C4', 5, 2, 0, 2); $request = pack('C4', 5, 2, 0, 2);

View File

@ -4,40 +4,17 @@
* *
* PHP version 5 * PHP version 5
* *
* LICENSE: * LICENSE
* *
* Copyright (c) 2008-2012, Alexey Borzov <avb@php.net> * This source file is subject to BSD 3-Clause License that is bundled
* All rights reserved. * with this package in the file LICENSE and available at the URL
* * https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @copyright 2008-2014 Alexey Borzov <avb@php.net>
* @version SVN: $Id: SocketWrapper.php 324935 2012-04-07 07:10:50Z avb $ * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
*/ */
@ -53,8 +30,8 @@ require_once 'HTTP/Request2/Exception.php';
* @category HTTP * @category HTTP
* @package HTTP_Request2 * @package HTTP_Request2
* @author Alexey Borzov <avb@php.net> * @author Alexey Borzov <avb@php.net>
* @license http://opensource.org/licenses/bsd-license.php New BSD License * @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @version Release: 2.1.1 * @version Release: 2.2.1
* @link http://pear.php.net/package/HTTP_Request2 * @link http://pear.php.net/package/HTTP_Request2
* @link http://pear.php.net/bugs/bug.php?id=19332 * @link http://pear.php.net/bugs/bug.php?id=19332
* @link http://tools.ietf.org/html/rfc1928 * @link http://tools.ietf.org/html/rfc1928
@ -91,27 +68,42 @@ class HTTP_Request2_SocketWrapper
* @param string $address Address for stream_socket_client() call, * @param string $address Address for stream_socket_client() call,
* e.g. 'tcp://localhost:80' * e.g. 'tcp://localhost:80'
* @param int $timeout Connection timeout (seconds) * @param int $timeout Connection timeout (seconds)
* @param array $sslOptions SSL context options * @param array $contextOptions Context options
* *
* @throws HTTP_Request2_LogicException * @throws HTTP_Request2_LogicException
* @throws HTTP_Request2_ConnectionException * @throws HTTP_Request2_ConnectionException
*/ */
public function __construct($address, $timeout, array $sslOptions = array()) public function __construct($address, $timeout, array $contextOptions = array())
{ {
if (!empty($contextOptions)
&& !isset($contextOptions['socket']) && !isset($contextOptions['ssl'])
) {
// Backwards compatibility with 2.1.0 and 2.1.1 releases
$contextOptions = array('ssl' => $contextOptions);
}
$context = stream_context_create(); $context = stream_context_create();
foreach ($sslOptions as $name => $value) { foreach ($contextOptions as $wrapper => $options) {
if (!stream_context_set_option($context, 'ssl', $name, $value)) { foreach ($options as $name => $value) {
if (!stream_context_set_option($context, $wrapper, $name, $value)) {
throw new HTTP_Request2_LogicException( throw new HTTP_Request2_LogicException(
"Error setting SSL context option '{$name}'" "Error setting '{$wrapper}' wrapper context option '{$name}'"
); );
} }
} }
}
set_error_handler(array($this, 'connectionWarningsHandler')); set_error_handler(array($this, 'connectionWarningsHandler'));
$this->socket = stream_socket_client( $this->socket = stream_socket_client(
$address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context $address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context
); );
restore_error_handler(); restore_error_handler();
if (!$this->socket) { // if we fail to bind to a specified local address (see request #19515),
// connection still succeeds, albeit with a warning. Throw an Exception
// with the warning text in this case as that connection is unlikely
// to be what user wants and as Curl throws an error in similar case.
if ($this->connectionWarnings) {
if ($this->socket) {
fclose($this->socket);
}
$error = $errstr ? $errstr : implode("\n", $this->connectionWarnings); $error = $errstr ? $errstr : implode("\n", $this->connectionWarnings);
throw new HTTP_Request2_ConnectionException( throw new HTTP_Request2_ConnectionException(
"Unable to connect to {$address}. Error: {$error}", 0, $errno "Unable to connect to {$address}. Error: {$error}", 0, $errno
@ -152,19 +144,41 @@ class HTTP_Request2_SocketWrapper
* request timeout. Method idea borrowed from Net_Socket PEAR package. * request timeout. Method idea borrowed from Net_Socket PEAR package.
* *
* @param int $bufferSize buffer size to use for reading * @param int $bufferSize buffer size to use for reading
* @param int $localTimeout timeout value to use just for this call
* (used when waiting for "100 Continue" response)
* *
* @return string Available data up to the newline (not including newline) * @return string Available data up to the newline (not including newline)
* @throws HTTP_Request2_MessageException In case of timeout * @throws HTTP_Request2_MessageException In case of timeout
*/ */
public function readLine($bufferSize) public function readLine($bufferSize, $localTimeout = null)
{ {
$line = ''; $line = '';
while (!feof($this->socket)) { while (!feof($this->socket)) {
if ($this->deadline) { if (null !== $localTimeout) {
stream_set_timeout($this->socket, $localTimeout);
} elseif ($this->deadline) {
stream_set_timeout($this->socket, max($this->deadline - time(), 1)); stream_set_timeout($this->socket, max($this->deadline - time(), 1));
} }
$line .= @fgets($this->socket, $bufferSize); $line .= @fgets($this->socket, $bufferSize);
if (null === $localTimeout) {
$this->checkTimeout(); $this->checkTimeout();
} else {
$info = stream_get_meta_data($this->socket);
// reset socket timeout if we don't have request timeout specified,
// prevents further calls failing with a bogus Exception
if (!$this->deadline) {
$default = (int)@ini_get('default_socket_timeout');
stream_set_timeout($this->socket, $default > 0 ? $default : PHP_INT_MAX);
}
if ($info['timed_out']) {
throw new HTTP_Request2_MessageException(
"readLine() call timed out", HTTP_Request2_Exception::TIMEOUT
);
}
}
if (substr($line, -1) == "\n") { if (substr($line, -1) == "\n") {
return rtrim($line, "\r\n"); return rtrim($line, "\r\n");
} }

View File

@ -0,0 +1,31 @@
HTTP_Request2
Copyright (c) 2008-2014, Alexey Borzov <avb@php.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of Alexey Borzov nor the names of his contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.