mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 08:41:39 +09:00
Replace Pear HTTP_Request with rmccue/Requests
This commit is contained in:
parent
ecbf7e188b
commit
192e81620d
120 changed files with 94 additions and 37803 deletions
|
|
@ -516,8 +516,6 @@ class FileHandler
|
|||
/**
|
||||
* Return remote file's content via HTTP
|
||||
*
|
||||
* If the target is moved (when return code is 300~399), this function follows the location specified response header.
|
||||
*
|
||||
* @param string $url The address of the target file
|
||||
* @param string $body HTTP request body
|
||||
* @param int $timeout Connection timeout
|
||||
|
|
@ -532,89 +530,66 @@ class FileHandler
|
|||
{
|
||||
try
|
||||
{
|
||||
requirePear();
|
||||
if(!class_exists('HTTP_Request')) require_once('HTTP/Request.php');
|
||||
|
||||
$parsed_url = parse_url(__PROXY_SERVER__);
|
||||
if($parsed_url["host"])
|
||||
$request_headers = array();
|
||||
$request_cookies = array();
|
||||
$request_options = array('timeout' => $timeout);
|
||||
|
||||
foreach($headers as $key => $val)
|
||||
{
|
||||
$oRequest = new HTTP_Request(__PROXY_SERVER__);
|
||||
$oRequest->setMethod('POST');
|
||||
$oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data)));
|
||||
$request_headers[$key] = $val;
|
||||
}
|
||||
|
||||
if(isset($cookies[$host]) && is_array($cookies[$host]))
|
||||
{
|
||||
foreach($cookies[$host] as $key => $val)
|
||||
{
|
||||
$request_cookies[] = rawurlencode($key) . '=' . rawurlencode($val);
|
||||
}
|
||||
}
|
||||
if(count($request_cookies))
|
||||
{
|
||||
$request_headers['Cookie'] = implode('; ', $request_cookies);
|
||||
}
|
||||
|
||||
foreach($request_config as $key => $val)
|
||||
{
|
||||
$request_options[$key] = $val;
|
||||
}
|
||||
|
||||
if($content_type)
|
||||
{
|
||||
$request_headers['Content-Type'] = $content_type;
|
||||
}
|
||||
|
||||
$proxy = parse_url(__PROXY_SERVER__);
|
||||
if($proxy["host"])
|
||||
{
|
||||
$request_options['proxy'] = array($proxy['host'] . ($proxy['port'] ? (':' . $proxy['port']) : ''));
|
||||
if($proxy['user'] && $proxy['pass'])
|
||||
{
|
||||
$request_options['proxy'][] = $proxy['user'];
|
||||
$request_options['proxy'][] = $proxy['pass'];
|
||||
}
|
||||
}
|
||||
|
||||
$response = Requests::request($url, $request_headers, $body ?: $post_data, $method, $request_options);
|
||||
|
||||
if(count($response->cookies))
|
||||
{
|
||||
foreach($response->cookies as $cookie)
|
||||
{
|
||||
$cookies[$host][$cookie->name] = $cookie->value;
|
||||
}
|
||||
}
|
||||
|
||||
if($response->success)
|
||||
{
|
||||
return $response->body;
|
||||
}
|
||||
else
|
||||
{
|
||||
$oRequest = new HTTP_Request($url);
|
||||
|
||||
if(count($request_config) && method_exists($oRequest, 'setConfig'))
|
||||
{
|
||||
foreach($request_config as $key=>$val)
|
||||
{
|
||||
$oRequest->setConfig($key, $val);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($headers) > 0)
|
||||
{
|
||||
foreach($headers as $key => $val)
|
||||
{
|
||||
$oRequest->addHeader($key, $val);
|
||||
}
|
||||
}
|
||||
if($cookies[$host])
|
||||
{
|
||||
foreach($cookies[$host] as $key => $val)
|
||||
{
|
||||
$oRequest->addCookie($key, $val);
|
||||
}
|
||||
}
|
||||
if(count($post_data) > 0)
|
||||
{
|
||||
foreach($post_data as $key => $val)
|
||||
{
|
||||
$oRequest->addPostData($key, $val);
|
||||
}
|
||||
}
|
||||
if(!$content_type)
|
||||
$oRequest->addHeader('Content-Type', 'text/html');
|
||||
else
|
||||
$oRequest->addHeader('Content-Type', $content_type);
|
||||
$oRequest->setMethod($method);
|
||||
if($body)
|
||||
$oRequest->setBody($body);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(method_exists($oRequest, 'setConfig'))
|
||||
{
|
||||
$oRequest->setConfig('timeout', $timeout);
|
||||
}
|
||||
elseif(property_exists($oRequest, '_timeout'))
|
||||
{
|
||||
$oRequest->_timeout = $timeout;
|
||||
}
|
||||
|
||||
$oResponse = $oRequest->sendRequest();
|
||||
|
||||
$code = $oRequest->getResponseCode();
|
||||
$header = $oRequest->getResponseHeader();
|
||||
$response = $oRequest->getResponseBody();
|
||||
if($c = $oRequest->getResponseCookies())
|
||||
{
|
||||
foreach($c as $k => $v)
|
||||
{
|
||||
$cookies[$host][$v['name']] = $v['value'];
|
||||
}
|
||||
}
|
||||
|
||||
if($code > 300 && $code < 399 && $header['location'])
|
||||
{
|
||||
return self::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data);
|
||||
}
|
||||
|
||||
if($code != 200)
|
||||
return;
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
"firephp/firephp-core": "0.4.0",
|
||||
"matthiasmullie/minify": "1.3.*",
|
||||
"michelf/php-markdown": "1.5.*",
|
||||
"pear/http_request2": "2.2.*",
|
||||
"rmccue/requests": "1.6.*",
|
||||
"sunra/php-simple-html-dom-parser": "1.5.*",
|
||||
"swiftmailer/swiftmailer": "5.4.*",
|
||||
|
|
|
|||
208
composer.lock
generated
208
composer.lock
generated
|
|
@ -4,8 +4,8 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "97c72bd2862f9d0a77824d769085e926",
|
||||
"content-hash": "ffd2aaf7dc6705d78c09488d2c7ab024",
|
||||
"hash": "a35061b94658a2dbdafe943dddcdc898",
|
||||
"content-hash": "1a71937e1cbc600f8a237c6445d6a69f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "defuse/php-encryption",
|
||||
|
|
@ -96,6 +96,42 @@
|
|||
],
|
||||
"time": "2015-08-05 01:03:42"
|
||||
},
|
||||
{
|
||||
"name": "firephp/firephp-core",
|
||||
"version": "v0.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/firephp/firephp-core.git",
|
||||
"reference": "fabad0f2503f9577fe8dd2cb1d1c7cd73ed2aacf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/firephp/firephp-core/zipball/fabad0f2503f9577fe8dd2cb1d1c7cd73ed2aacf",
|
||||
"reference": "fabad0f2503f9577fe8dd2cb1d1c7cd73ed2aacf",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"lib/FirePHPCore/FirePHP.class.php",
|
||||
"lib/FirePHPCore/fb.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Christoph Dorn",
|
||||
"email": "christoph@christophdorn.com",
|
||||
"homepage": "http://christophdorn.com"
|
||||
}
|
||||
],
|
||||
"description": "Traditional FirePHPCore library for sending PHP variables to the browser.",
|
||||
"homepage": "https://github.com/firephp/firephp-core",
|
||||
"time": "2013-04-23 15:28:20"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
"version": "1.3.32",
|
||||
|
|
@ -254,174 +290,6 @@
|
|||
],
|
||||
"time": "2015-03-01 12:03:08"
|
||||
},
|
||||
{
|
||||
"name": "pear/http_request2",
|
||||
"version": "v2.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/HTTP_Request2.git",
|
||||
"reference": "d6c81670c504045248c1afdf896bb9a3288158de"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/HTTP_Request2/zipball/d6c81670c504045248c1afdf896bb9a3288158de",
|
||||
"reference": "d6c81670c504045248c1afdf896bb9a3288158de",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"pear/net_url2": ">=2.0.0",
|
||||
"pear/pear_exception": "*",
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-fileinfo": "Adds support for looking up mime-types using finfo.",
|
||||
"ext-zlib": "Allows handling gzip compressed responses.",
|
||||
"lib-curl": "Allows using cURL as a request backend.",
|
||||
"lib-openssl": "Allows handling SSL requests when not using cURL."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"HTTP_Request2": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alexey Borzov",
|
||||
"email": "avb@php.net",
|
||||
"role": "Developer HTML_Common2"
|
||||
}
|
||||
],
|
||||
"description": "Provides an easy way to perform HTTP requests.",
|
||||
"homepage": "http://pear.php.net/package/HTTP_Request2",
|
||||
"keywords": [
|
||||
"PEAR",
|
||||
"curl",
|
||||
"http",
|
||||
"request"
|
||||
],
|
||||
"time": "2014-01-16 17:27:21"
|
||||
},
|
||||
{
|
||||
"name": "pear/net_url2",
|
||||
"version": "v2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/Net_URL2.git",
|
||||
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/Net_URL2/zipball/fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
|
||||
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.1.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=3.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"Net/URL2.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Coallier",
|
||||
"email": "davidc@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Tom Klingenberg",
|
||||
"email": "tkli@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Christian Schmidt",
|
||||
"email": "chmidt@php.net"
|
||||
}
|
||||
],
|
||||
"description": "Class for parsing and handling URL. Provides parsing of URLs into their constituent parts (scheme, host, path etc.), URL generation, and resolving of relative URLs.",
|
||||
"homepage": "https://github.com/pear/Net_URL2",
|
||||
"keywords": [
|
||||
"PEAR",
|
||||
"net",
|
||||
"networking",
|
||||
"rfc3986",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2015-04-18 17:36:57"
|
||||
},
|
||||
{
|
||||
"name": "pear/pear_exception",
|
||||
"version": "v1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/PEAR_Exception.git",
|
||||
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
|
||||
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"type": "class",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"PEAR": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"include-path": [
|
||||
"."
|
||||
],
|
||||
"license": [
|
||||
"BSD-2-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Helgi Thormar",
|
||||
"email": "dufuz@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Greg Beaver",
|
||||
"email": "cellog@php.net"
|
||||
}
|
||||
],
|
||||
"description": "The PEAR Exception base class.",
|
||||
"homepage": "https://github.com/pear/PEAR_Exception",
|
||||
"keywords": [
|
||||
"exception"
|
||||
],
|
||||
"time": "2015-02-10 20:07:52"
|
||||
},
|
||||
{
|
||||
"name": "rmccue/requests",
|
||||
"version": "v1.6.1",
|
||||
|
|
|
|||
|
|
@ -1448,7 +1448,7 @@ function stripEmbedTagForAdmin(&$content, $writer_member_srl)
|
|||
*/
|
||||
function requirePear()
|
||||
{
|
||||
set_include_path(_XE_PATH_ . "libs/PEAR.1.9.5" . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
class HTTP_Request extends HTTP_Request2
|
||||
{
|
||||
private $reponse = null;
|
||||
|
||||
public function addHeader($name, $value)
|
||||
{
|
||||
$this->setHeader($name, $value);
|
||||
}
|
||||
|
||||
public function sendRequest($saveBody = true)
|
||||
{
|
||||
$response = $this->send();
|
||||
$this->response = $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getResponseCode() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseHeader() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getHeader();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseBody() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseCookies() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getCookies();
|
||||
}
|
||||
}
|
||||
|
||||
public function addPostData($name, $value, $preencoded = false)
|
||||
{
|
||||
$this->addPostParameter($name, $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*/
|
||||
require_once 'HTTP/Request2/Response.php';
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* HTTP_Request2 class itself only defines methods for aggregating the request
|
||||
* data, all actual work of sending the request to the remote server and
|
||||
* receiving its response is performed by adapters.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
abstract class HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A list of methods that MUST NOT have a request body, per RFC 2616
|
||||
* @var array
|
||||
*/
|
||||
protected static $bodyDisallowed = array('TRACE');
|
||||
|
||||
/**
|
||||
* Methods having defined semantics for request body
|
||||
*
|
||||
* Content-Length header (indicating that the body follows, section 4.3 of
|
||||
* RFC 2616) will be sent for these methods even if no body was added
|
||||
*
|
||||
* @var array
|
||||
* @link http://pear.php.net/bugs/bug.php?id=12900
|
||||
* @link http://pear.php.net/bugs/bug.php?id=14740
|
||||
*/
|
||||
protected static $bodyRequired = array('POST', 'PUT');
|
||||
|
||||
/**
|
||||
* Request being sent
|
||||
* @var HTTP_Request2
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource|HTTP_Request2_MultipartBody
|
||||
* @see HTTP_Request2::getBody()
|
||||
*/
|
||||
protected $requestBody;
|
||||
|
||||
/**
|
||||
* Length of the request body
|
||||
* @var integer
|
||||
*/
|
||||
protected $contentLength;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
abstract public function sendRequest(HTTP_Request2 $request);
|
||||
|
||||
/**
|
||||
* Calculates length of the request body, adds proper headers
|
||||
*
|
||||
* @param array &$headers associative array of request headers, this method
|
||||
* will add proper 'Content-Length' and 'Content-Type'
|
||||
* headers to this array (or remove them if not needed)
|
||||
*/
|
||||
protected function calculateRequestLength(&$headers)
|
||||
{
|
||||
$this->requestBody = $this->request->getBody();
|
||||
|
||||
if (is_string($this->requestBody)) {
|
||||
$this->contentLength = strlen($this->requestBody);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$stat = fstat($this->requestBody);
|
||||
$this->contentLength = $stat['size'];
|
||||
rewind($this->requestBody);
|
||||
} else {
|
||||
$this->contentLength = $this->requestBody->getLength();
|
||||
$headers['content-type'] = 'multipart/form-data; boundary=' .
|
||||
$this->requestBody->getBoundary();
|
||||
$this->requestBody->rewind();
|
||||
}
|
||||
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed)
|
||||
|| 0 == $this->contentLength
|
||||
) {
|
||||
// No body: send a Content-Length header nonetheless (request #12900),
|
||||
// but do that only for methods that require a body (bug #14740)
|
||||
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
|
||||
$headers['content-length'] = 0;
|
||||
} else {
|
||||
unset($headers['content-length']);
|
||||
// if the method doesn't require a body and doesn't have a
|
||||
// body, don't send a Content-Type header. (request #16799)
|
||||
unset($headers['content-type']);
|
||||
}
|
||||
} else {
|
||||
if (empty($headers['content-type'])) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,567 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* Mapping of header names to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $headerMap = array(
|
||||
'accept-encoding' => CURLOPT_ENCODING,
|
||||
'cookie' => CURLOPT_COOKIE,
|
||||
'referer' => CURLOPT_REFERER,
|
||||
'user-agent' => CURLOPT_USERAGENT
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of SSL context options to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $sslContextMap = array(
|
||||
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
|
||||
'ssl_cafile' => CURLOPT_CAINFO,
|
||||
'ssl_capath' => CURLOPT_CAPATH,
|
||||
'ssl_local_cert' => CURLOPT_SSLCERT,
|
||||
'ssl_passphrase' => CURLOPT_SSLCERTPASSWD
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of CURLE_* constants to Exception subclasses and error codes
|
||||
* @var array
|
||||
*/
|
||||
protected static $errorMap = array(
|
||||
CURLE_UNSUPPORTED_PROTOCOL => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_COULDNT_RESOLVE_PROXY => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_COULDNT_RESOLVE_HOST => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_COULDNT_CONNECT => array('HTTP_Request2_ConnectionException'),
|
||||
// error returned from write callback
|
||||
CURLE_WRITE_ERROR => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_OPERATION_TIMEOUTED => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::TIMEOUT),
|
||||
CURLE_HTTP_RANGE_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_CONNECT_ERROR => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_LIBRARY_NOT_FOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_FUNCTION_NOT_FOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_ABORTED_BY_CALLBACK => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_TOO_MANY_REDIRECTS => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::TOO_MANY_REDIRECTS),
|
||||
CURLE_SSL_PEER_CERTIFICATE => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_GOT_NOTHING => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_ENGINE_NOTFOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_SSL_ENGINE_SETFAILED => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_SEND_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_RECV_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_CERTPROBLEM => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT),
|
||||
CURLE_SSL_CIPHER => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_SSL_CACERT => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_BAD_CONTENT_ENCODING => array('HTTP_Request2_MessageException'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Response being received
|
||||
* @var HTTP_Request2_Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Whether 'sentHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventSentHeaders = false;
|
||||
|
||||
/**
|
||||
* Whether 'receivedHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventReceivedHeaders = false;
|
||||
|
||||
/**
|
||||
* Position within request body
|
||||
* @var integer
|
||||
* @see callbackReadBody()
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Information about last transfer, as returned by curl_getinfo()
|
||||
* @var array
|
||||
*/
|
||||
protected $lastInfo;
|
||||
|
||||
/**
|
||||
* Creates a subclass of HTTP_Request2_Exception from curl error data
|
||||
*
|
||||
* @param resource $ch curl handle
|
||||
*
|
||||
* @return HTTP_Request2_Exception
|
||||
*/
|
||||
protected static function wrapCurlError($ch)
|
||||
{
|
||||
$nativeCode = curl_errno($ch);
|
||||
$message = 'Curl error: ' . curl_error($ch);
|
||||
if (!isset(self::$errorMap[$nativeCode])) {
|
||||
return new HTTP_Request2_Exception($message, 0, $nativeCode);
|
||||
} else {
|
||||
$class = self::$errorMap[$nativeCode][0];
|
||||
$code = empty(self::$errorMap[$nativeCode][1])
|
||||
? 0 : self::$errorMap[$nativeCode][1];
|
||||
return new $class($message, $code, $nativeCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'cURL extension not available', HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
$this->response = null;
|
||||
$this->position = 0;
|
||||
$this->eventSentHeaders = false;
|
||||
$this->eventReceivedHeaders = false;
|
||||
|
||||
try {
|
||||
if (false === curl_exec($ch = $this->createCurlHandle())) {
|
||||
$e = self::wrapCurlError($ch);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
if (isset($ch)) {
|
||||
$this->lastInfo = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
$response = $this->response;
|
||||
unset($this->request, $this->requestBody, $this->response);
|
||||
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($jar = $request->getCookieJar()) {
|
||||
$jar->addCookiesFromResponse($response, $request->getUrl());
|
||||
}
|
||||
|
||||
if (0 < $this->lastInfo['size_download']) {
|
||||
$request->setLastEvent('receivedBody', $response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about last transfer
|
||||
*
|
||||
* @return array associative array as returned by curl_getinfo()
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->lastInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cURL handle and populates it with data from the request
|
||||
*
|
||||
* @return resource a cURL handle, as created by curl_init()
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_NotImplementedException
|
||||
*/
|
||||
protected function createCurlHandle()
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, array(
|
||||
// setup write callbacks
|
||||
CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
|
||||
CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
|
||||
// buffer size
|
||||
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
|
||||
// connection timeout
|
||||
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
|
||||
// save full outgoing headers, in case someone is interested
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
// request url
|
||||
CURLOPT_URL => $this->request->getUrl()->getUrl()
|
||||
));
|
||||
|
||||
// set up redirects
|
||||
if (!$this->request->getConfig('follow_redirects')) {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
||||
} else {
|
||||
if (!@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true)) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Redirect support in curl is unavailable due to open_basedir or safe_mode setting',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
|
||||
// limit redirects to http(s), works in 5.2.10+
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
// works in 5.3.2+, http://bugs.php.net/bug.php?id=49571
|
||||
if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR')) {
|
||||
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
|
||||
}
|
||||
}
|
||||
|
||||
// set local IP via CURLOPT_INTERFACE (request #19515)
|
||||
if ($ip = $this->request->getConfig('local_ip')) {
|
||||
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
|
||||
}
|
||||
|
||||
// request timeout
|
||||
if ($timeout = $this->request->getConfig('timeout')) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
|
||||
// set HTTP version
|
||||
switch ($this->request->getConfig('protocol_version')) {
|
||||
case '1.0':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
break;
|
||||
case '1.1':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
|
||||
// set request method
|
||||
switch ($this->request->getMethod()) {
|
||||
case HTTP_Request2::METHOD_GET:
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_POST:
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_HEAD:
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_PUT:
|
||||
curl_setopt($ch, CURLOPT_UPLOAD, true);
|
||||
break;
|
||||
default:
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
|
||||
}
|
||||
|
||||
// set proxy, if needed
|
||||
if ($host = $this->request->getConfig('proxy_host')) {
|
||||
if (!($port = $this->request->getConfig('proxy_port'))) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Proxy port not provided', HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
|
||||
if ($user = $this->request->getConfig('proxy_user')) {
|
||||
curl_setopt(
|
||||
$ch, CURLOPT_PROXYUSERPWD,
|
||||
$user . ':' . $this->request->getConfig('proxy_password')
|
||||
);
|
||||
switch ($this->request->getConfig('proxy_auth_scheme')) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
if ($type = $this->request->getConfig('proxy_type')) {
|
||||
switch ($type) {
|
||||
case 'http':
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
break;
|
||||
case 'socks5':
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||
break;
|
||||
default:
|
||||
throw new HTTP_Request2_NotImplementedException(
|
||||
"Proxy type '{$type}' is not supported"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set authentication data
|
||||
if ($auth = $this->request->getAuth()) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
|
||||
switch ($auth['scheme']) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
|
||||
// set SSL options
|
||||
foreach ($this->request->getConfig() as $name => $value) {
|
||||
if ('ssl_verify_host' == $name && null !== $value) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
|
||||
} elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
|
||||
curl_setopt($ch, self::$sslContextMap[$name], $value);
|
||||
}
|
||||
}
|
||||
|
||||
$headers = $this->request->getHeaders();
|
||||
// make cURL automagically send proper header
|
||||
if (!isset($headers['accept-encoding'])) {
|
||||
$headers['accept-encoding'] = '';
|
||||
}
|
||||
|
||||
if (($jar = $this->request->getCookieJar())
|
||||
&& ($cookies = $jar->getMatching($this->request->getUrl(), true))
|
||||
) {
|
||||
$headers['cookie'] = (empty($headers['cookie'])? '': $headers['cookie'] . '; ') . $cookies;
|
||||
}
|
||||
|
||||
// set headers having special cURL keys
|
||||
foreach (self::$headerMap as $name => $option) {
|
||||
if (isset($headers[$name])) {
|
||||
curl_setopt($ch, $option, $headers[$name]);
|
||||
unset($headers[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->calculateRequestLength($headers);
|
||||
if (isset($headers['content-length']) || isset($headers['transfer-encoding'])) {
|
||||
$this->workaroundPhpBug47204($ch, $headers);
|
||||
}
|
||||
|
||||
// set headers not having special keys
|
||||
$headersFmt = array();
|
||||
foreach ($headers as $name => $value) {
|
||||
$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
|
||||
$headersFmt[] = $canonicalName . ': ' . $value;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
|
||||
|
||||
return $ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for PHP bug #47204 that prevents rewinding request body
|
||||
*
|
||||
* The workaround consists of reading the entire request body into memory
|
||||
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
|
||||
* file uploads, use Socket adapter instead.
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param array &$headers Request headers
|
||||
*/
|
||||
protected function workaroundPhpBug47204($ch, &$headers)
|
||||
{
|
||||
// no redirects, no digest auth -> probably no rewind needed
|
||||
if (!$this->request->getConfig('follow_redirects')
|
||||
&& (!($auth = $this->request->getAuth())
|
||||
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
|
||||
) {
|
||||
curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
|
||||
|
||||
} else {
|
||||
// rewind may be needed, read the whole body into memory
|
||||
if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->requestBody = $this->requestBody->__toString();
|
||||
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$fp = $this->requestBody;
|
||||
$this->requestBody = '';
|
||||
while (!feof($fp)) {
|
||||
$this->requestBody .= fread($fp, 16384);
|
||||
}
|
||||
}
|
||||
// curl hangs up if content-length is present
|
||||
unset($headers['content-length']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for reading the request body
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param resource $fd file descriptor (not used)
|
||||
* @param integer $length maximum length of data to return
|
||||
*
|
||||
* @return string part of the request body, up to $length bytes
|
||||
*/
|
||||
protected function callbackReadBody($ch, $fd, $length)
|
||||
{
|
||||
if (!$this->eventSentHeaders) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
$this->eventSentHeaders = true;
|
||||
}
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed)
|
||||
|| 0 == $this->contentLength || $this->position >= $this->contentLength
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
if (is_string($this->requestBody)) {
|
||||
$string = substr($this->requestBody, $this->position, $length);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$string = fread($this->requestBody, $length);
|
||||
} else {
|
||||
$string = $this->requestBody->read($length);
|
||||
}
|
||||
$this->request->setLastEvent('sentBodyPart', strlen($string));
|
||||
$this->position += strlen($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response headers
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param string $string response header (with trailing CRLF)
|
||||
*
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::parseHeaderLine()
|
||||
*/
|
||||
protected function callbackWriteHeader($ch, $string)
|
||||
{
|
||||
// we may receive a second set of headers if doing e.g. digest auth
|
||||
if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (!$this->eventSentHeaders
|
||||
|| $this->response->getStatus() >= 200
|
||||
) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
}
|
||||
$upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
|
||||
// if body wasn't read by a callback, send event with total body size
|
||||
if ($upload > $this->position) {
|
||||
$this->request->setLastEvent(
|
||||
'sentBodyPart', $upload - $this->position
|
||||
);
|
||||
$this->position = $upload;
|
||||
}
|
||||
if ($upload && (!$this->eventSentHeaders
|
||||
|| $this->response->getStatus() >= 200)
|
||||
) {
|
||||
$this->request->setLastEvent('sentBody', $upload);
|
||||
}
|
||||
$this->eventSentHeaders = true;
|
||||
// we'll need a new response object
|
||||
if ($this->eventReceivedHeaders) {
|
||||
$this->eventReceivedHeaders = false;
|
||||
$this->response = null;
|
||||
}
|
||||
}
|
||||
if (empty($this->response)) {
|
||||
$this->response = new HTTP_Request2_Response(
|
||||
$string, false, curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)
|
||||
);
|
||||
} else {
|
||||
$this->response->parseHeaderLine($string);
|
||||
if ('' == trim($string)) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (200 <= $this->response->getStatus()) {
|
||||
$this->request->setLastEvent('receivedHeaders', $this->response);
|
||||
}
|
||||
|
||||
if ($this->request->getConfig('follow_redirects') && $this->response->isRedirect()) {
|
||||
$redirectUrl = new Net_URL2($this->response->getHeader('location'));
|
||||
|
||||
// for versions lower than 5.2.10, check the redirection URL protocol
|
||||
if (!defined('CURLOPT_REDIR_PROTOCOLS') && $redirectUrl->isAbsolute()
|
||||
&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($jar = $this->request->getCookieJar()) {
|
||||
$jar->addCookiesFromResponse($this->response, $this->request->getUrl());
|
||||
if (!$redirectUrl->isAbsolute()) {
|
||||
$redirectUrl = $this->request->getUrl()->resolve($redirectUrl);
|
||||
}
|
||||
if ($cookies = $jar->getMatching($redirectUrl, true)) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->eventReceivedHeaders = true;
|
||||
}
|
||||
}
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response body
|
||||
*
|
||||
* @param resource $ch cURL handle (not used)
|
||||
* @param string $string part of the response body
|
||||
*
|
||||
* @return integer number of bytes saved
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @see HTTP_Request2_Response::appendBody()
|
||||
*/
|
||||
protected function callbackWriteBody($ch, $string)
|
||||
{
|
||||
// cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
|
||||
// response doesn't start with proper HTTP status line (see bug #15716)
|
||||
if (empty($this->response)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Malformed response: {$string}",
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
if ($this->request->getConfig('store_body')) {
|
||||
$this->response->appendBody($string);
|
||||
}
|
||||
$this->request->setLastEvent('receivedBodyPart', $string);
|
||||
return strlen($string);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* Can be used to test applications depending on HTTP_Request2 package without
|
||||
* actually performing any HTTP requests. This adapter will return responses
|
||||
* previously added via addResponse()
|
||||
* <code>
|
||||
* $mock = new HTTP_Request2_Adapter_Mock();
|
||||
* $mock->addResponse("HTTP/1.1 ... ");
|
||||
*
|
||||
* $request = new HTTP_Request2();
|
||||
* $request->setAdapter($mock);
|
||||
*
|
||||
* // This will return the response set above
|
||||
* $response = $req->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A queue of responses to be returned by sendRequest()
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
|
||||
/**
|
||||
* Returns the next response from the queue built by addResponse()
|
||||
*
|
||||
* Only responses without explicit URLs or with URLs equal to request URL
|
||||
* will be considered. If matching response is not found or the queue is
|
||||
* empty then default empty response with status 400 will be returned,
|
||||
* if an Exception object was added to the queue it will be thrown.
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
$requestUrl = (string)$request->getUrl();
|
||||
$response = null;
|
||||
foreach ($this->responses as $k => $v) {
|
||||
if (!$v[1] || $requestUrl == $v[1]) {
|
||||
$response = $v[0];
|
||||
array_splice($this->responses, $k, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$response) {
|
||||
return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n");
|
||||
|
||||
} elseif ($response instanceof HTTP_Request2_Response) {
|
||||
return $response;
|
||||
|
||||
} else {
|
||||
// rethrow the exception
|
||||
$class = get_class($response);
|
||||
$message = $response->getMessage();
|
||||
$code = $response->getCode();
|
||||
throw new $class($message, $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds response to the queue
|
||||
*
|
||||
* @param mixed $response either a string, a pointer to an open file,
|
||||
* an instance of HTTP_Request2_Response or Exception
|
||||
* @param string $url A request URL this response should be valid for
|
||||
* (see {@link http://pear.php.net/bugs/bug.php?id=19276})
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addResponse($response, $url = null)
|
||||
{
|
||||
if (is_string($response)) {
|
||||
$response = self::createResponseFromString($response);
|
||||
} elseif (is_resource($response)) {
|
||||
$response = self::createResponseFromFile($response);
|
||||
} elseif (!$response instanceof HTTP_Request2_Response &&
|
||||
!$response instanceof Exception
|
||||
) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid response');
|
||||
}
|
||||
$this->responses[] = array($response, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a string
|
||||
*
|
||||
* @param string $str string containing HTTP response message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromString($str)
|
||||
{
|
||||
$parts = preg_split('!(\r?\n){2}!m', $str, 2);
|
||||
$headerLines = explode("\n", $parts[0]);
|
||||
$response = new HTTP_Request2_Response(array_shift($headerLines));
|
||||
foreach ($headerLines as $headerLine) {
|
||||
$response->parseHeaderLine($headerLine);
|
||||
}
|
||||
$response->parseHeaderLine('');
|
||||
if (isset($parts[1])) {
|
||||
$response->appendBody($parts[1]);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a file
|
||||
*
|
||||
* @param resource $fp file pointer returned by fopen()
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromFile($fp)
|
||||
{
|
||||
$response = new HTTP_Request2_Response(fgets($fp));
|
||||
do {
|
||||
$headerLine = fgets($fp);
|
||||
$response->parseHeaderLine($headerLine);
|
||||
} while ('' != trim($headerLine));
|
||||
|
||||
while (!feof($fp)) {
|
||||
$response->appendBody(fread($fp, 8192));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,494 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Stores cookies and passes them between HTTP requests
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Class representing a HTTP request message */
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Stores cookies and passes them between HTTP requests
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_CookieJar implements Serializable
|
||||
{
|
||||
/**
|
||||
* Array of stored cookies
|
||||
*
|
||||
* The array is indexed by domain, path and cookie name
|
||||
* .example.com
|
||||
* /
|
||||
* some_cookie => cookie data
|
||||
* /subdir
|
||||
* other_cookie => cookie data
|
||||
* .example.org
|
||||
* ...
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Whether session cookies should be serialized when serializing the jar
|
||||
* @var bool
|
||||
*/
|
||||
protected $serializeSession = false;
|
||||
|
||||
/**
|
||||
* Whether Public Suffix List should be used for domain matching
|
||||
* @var bool
|
||||
*/
|
||||
protected $useList = true;
|
||||
|
||||
/**
|
||||
* Array with Public Suffix List data
|
||||
* @var array
|
||||
* @link http://publicsuffix.org/
|
||||
*/
|
||||
protected static $psl = array();
|
||||
|
||||
/**
|
||||
* Class constructor, sets various options
|
||||
*
|
||||
* @param bool $serializeSessionCookies Controls serializing session cookies,
|
||||
* see {@link serializeSessionCookies()}
|
||||
* @param bool $usePublicSuffixList Controls using Public Suffix List,
|
||||
* see {@link usePublicSuffixList()}
|
||||
*/
|
||||
public function __construct(
|
||||
$serializeSessionCookies = false, $usePublicSuffixList = true
|
||||
) {
|
||||
$this->serializeSessionCookies($serializeSessionCookies);
|
||||
$this->usePublicSuffixList($usePublicSuffixList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current time formatted in ISO-8601 at UTC timezone
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function now()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
return $dt->format(DateTime::ISO8601);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields
|
||||
*
|
||||
* The checks are as follows:
|
||||
* - cookie array should contain 'name' and 'value' fields;
|
||||
* - name and value should not contain disallowed symbols;
|
||||
* - 'expires' should be either empty parseable by DateTime;
|
||||
* - 'domain' and 'path' should be either not empty or an URL where
|
||||
* cookie was set should be provided.
|
||||
* - if $setter is provided, then document at that URL should be allowed
|
||||
* to set a cookie for that 'domain'. If $setter is not provided,
|
||||
* then no domain checks will be made.
|
||||
*
|
||||
* 'expires' field will be converted to ISO8601 format from COOKIE format,
|
||||
* 'domain' and 'path' will be set from setter URL if empty.
|
||||
*
|
||||
* @param array $cookie cookie data, as returned by
|
||||
* {@link HTTP_Request2_Response::getCookies()}
|
||||
* @param Net_URL2 $setter URL of the document that sent Set-Cookie header
|
||||
*
|
||||
* @return array Updated cookie array
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
protected function checkAndUpdateFields(array $cookie, Net_URL2 $setter = null)
|
||||
{
|
||||
if ($missing = array_diff(array('name', 'value'), array_keys($cookie))) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Cookie array should contain 'name' and 'value' fields",
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['name'])) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Invalid cookie name: '{$cookie['name']}'",
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['value'])) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Invalid cookie value: '{$cookie['value']}'",
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
$cookie += array('domain' => '', 'path' => '', 'expires' => null, 'secure' => false);
|
||||
|
||||
// Need ISO-8601 date @ UTC timezone
|
||||
if (!empty($cookie['expires'])
|
||||
&& !preg_match('/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+0000$/', $cookie['expires'])
|
||||
) {
|
||||
try {
|
||||
$dt = new DateTime($cookie['expires']);
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$cookie['expires'] = $dt->format(DateTime::ISO8601);
|
||||
} catch (Exception $e) {
|
||||
throw new HTTP_Request2_LogicException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($cookie['domain']) || empty($cookie['path'])) {
|
||||
if (!$setter) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Cookie misses domain and/or path component, cookie setter URL needed',
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
if (empty($cookie['domain'])) {
|
||||
if ($host = $setter->getHost()) {
|
||||
$cookie['domain'] = $host;
|
||||
} else {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Setter URL does not contain host part, can\'t set cookie domain',
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
}
|
||||
if (empty($cookie['path'])) {
|
||||
$path = $setter->getPath();
|
||||
$cookie['path'] = empty($path)? '/': substr($path, 0, strrpos($path, '/') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($setter && !$this->domainMatch($setter->getHost(), $cookie['domain'])) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Domain " . $setter->getHost() . " cannot set cookies for "
|
||||
. $cookie['domain']
|
||||
);
|
||||
}
|
||||
|
||||
return $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a cookie in the jar
|
||||
*
|
||||
* @param array $cookie cookie data, as returned by
|
||||
* {@link HTTP_Request2_Response::getCookies()}
|
||||
* @param Net_URL2 $setter URL of the document that sent Set-Cookie header
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function store(array $cookie, Net_URL2 $setter = null)
|
||||
{
|
||||
$cookie = $this->checkAndUpdateFields($cookie, $setter);
|
||||
|
||||
if (strlen($cookie['value'])
|
||||
&& (is_null($cookie['expires']) || $cookie['expires'] > $this->now())
|
||||
) {
|
||||
if (!isset($this->cookies[$cookie['domain']])) {
|
||||
$this->cookies[$cookie['domain']] = array();
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
|
||||
$this->cookies[$cookie['domain']][$cookie['path']] = array();
|
||||
}
|
||||
$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
|
||||
|
||||
} elseif (isset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']])) {
|
||||
unset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds cookies set in HTTP response to the jar
|
||||
*
|
||||
* @param HTTP_Request2_Response $response HTTP response message
|
||||
* @param Net_URL2 $setter original request URL, needed for
|
||||
* setting default domain/path
|
||||
*/
|
||||
public function addCookiesFromResponse(HTTP_Request2_Response $response, Net_URL2 $setter)
|
||||
{
|
||||
foreach ($response->getCookies() as $cookie) {
|
||||
$this->store($cookie, $setter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cookies matching a given request URL
|
||||
*
|
||||
* The following checks are made:
|
||||
* - cookie domain should match request host
|
||||
* - cookie path should be a prefix for request path
|
||||
* - 'secure' cookies will only be sent for HTTPS requests
|
||||
*
|
||||
* @param Net_URL2 $url Request url
|
||||
* @param bool $asString Whether to return cookies as string for "Cookie: " header
|
||||
*
|
||||
* @return array|string Matching cookies
|
||||
*/
|
||||
public function getMatching(Net_URL2 $url, $asString = false)
|
||||
{
|
||||
$host = $url->getHost();
|
||||
$path = $url->getPath();
|
||||
$secure = 0 == strcasecmp($url->getScheme(), 'https');
|
||||
|
||||
$matched = $ret = array();
|
||||
foreach (array_keys($this->cookies) as $domain) {
|
||||
if ($this->domainMatch($host, $domain)) {
|
||||
foreach (array_keys($this->cookies[$domain]) as $cPath) {
|
||||
if (0 === strpos($path, $cPath)) {
|
||||
foreach ($this->cookies[$domain][$cPath] as $name => $cookie) {
|
||||
if (!$cookie['secure'] || $secure) {
|
||||
$matched[$name][strlen($cookie['path'])] = $cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($matched as $cookies) {
|
||||
krsort($cookies);
|
||||
$ret = array_merge($ret, $cookies);
|
||||
}
|
||||
if (!$asString) {
|
||||
return $ret;
|
||||
} else {
|
||||
$str = '';
|
||||
foreach ($ret as $c) {
|
||||
$str .= (empty($str)? '': '; ') . $c['name'] . '=' . $c['value'];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cookies stored in a jar
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
$cookies = array();
|
||||
foreach (array_keys($this->cookies) as $domain) {
|
||||
foreach (array_keys($this->cookies[$domain]) as $path) {
|
||||
foreach ($this->cookies[$domain][$path] as $name => $cookie) {
|
||||
$cookies[] = $cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether session cookies should be serialized when serializing the jar
|
||||
*
|
||||
* @param boolean $serialize serialize?
|
||||
*/
|
||||
public function serializeSessionCookies($serialize)
|
||||
{
|
||||
$this->serializeSession = (bool)$serialize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Public Suffix List should be used for restricting cookie-setting
|
||||
*
|
||||
* Without PSL {@link domainMatch()} will only prevent setting cookies for
|
||||
* top-level domains like '.com' or '.org'. However, it will not prevent
|
||||
* setting a cookie for '.co.uk' even though only third-level registrations
|
||||
* are possible in .uk domain.
|
||||
*
|
||||
* With the List it is possible to find the highest level at which a domain
|
||||
* may be registered for a particular top-level domain and consequently
|
||||
* prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by
|
||||
* Firefox, Chrome and Opera browsers to restrict cookie setting.
|
||||
*
|
||||
* Note that PSL is licensed differently to HTTP_Request2 package (refer to
|
||||
* the license information in public-suffix-list.php), so you can disable
|
||||
* its use if this is an issue for you.
|
||||
*
|
||||
* @param boolean $useList use the list?
|
||||
*
|
||||
* @link http://publicsuffix.org/learn/
|
||||
*/
|
||||
public function usePublicSuffixList($useList)
|
||||
{
|
||||
$this->useList = (bool)$useList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation of object
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see Serializable::serialize()
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
$cookies = $this->getAll();
|
||||
if (!$this->serializeSession) {
|
||||
for ($i = count($cookies) - 1; $i >= 0; $i--) {
|
||||
if (empty($cookies[$i]['expires'])) {
|
||||
unset($cookies[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return serialize(array(
|
||||
'cookies' => $cookies,
|
||||
'serializeSession' => $this->serializeSession,
|
||||
'useList' => $this->useList
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object from serialized string
|
||||
*
|
||||
* @param string $serialized string representation
|
||||
*
|
||||
* @see Serializable::unserialize()
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$data = unserialize($serialized);
|
||||
$now = $this->now();
|
||||
$this->serializeSessionCookies($data['serializeSession']);
|
||||
$this->usePublicSuffixList($data['useList']);
|
||||
foreach ($data['cookies'] as $cookie) {
|
||||
if (!empty($cookie['expires']) && $cookie['expires'] <= $now) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']])) {
|
||||
$this->cookies[$cookie['domain']] = array();
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
|
||||
$this->cookies[$cookie['domain']][$cookie['path']] = array();
|
||||
}
|
||||
$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a cookie domain matches a request host.
|
||||
*
|
||||
* The method is used by {@link store()} to check for whether a document
|
||||
* at given URL can set a cookie with a given domain attribute and by
|
||||
* {@link getMatching()} to find cookies matching the request URL.
|
||||
*
|
||||
* @param string $requestHost request host
|
||||
* @param string $cookieDomain cookie domain
|
||||
*
|
||||
* @return bool match success
|
||||
*/
|
||||
public function domainMatch($requestHost, $cookieDomain)
|
||||
{
|
||||
if ($requestHost == $cookieDomain) {
|
||||
return true;
|
||||
}
|
||||
// IP address, we require exact match
|
||||
if (preg_match('/^(?:\d{1,3}\.){3}\d{1,3}$/', $requestHost)) {
|
||||
return false;
|
||||
}
|
||||
if ('.' != $cookieDomain[0]) {
|
||||
$cookieDomain = '.' . $cookieDomain;
|
||||
}
|
||||
// prevents setting cookies for '.com' and similar domains
|
||||
if (!$this->useList && substr_count($cookieDomain, '.') < 2
|
||||
|| $this->useList && !self::getRegisteredDomain($cookieDomain)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return substr('.' . $requestHost, -strlen($cookieDomain)) == $cookieDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes subdomains to get the registered domain (the first after top-level)
|
||||
*
|
||||
* The method will check Public Suffix List to find out where top-level
|
||||
* domain ends and registered domain starts. It will remove domain parts
|
||||
* to the left of registered one.
|
||||
*
|
||||
* @param string $domain domain name
|
||||
*
|
||||
* @return string|bool registered domain, will return false if $domain is
|
||||
* either invalid or a TLD itself
|
||||
*/
|
||||
public static function getRegisteredDomain($domain)
|
||||
{
|
||||
$domainParts = explode('.', ltrim($domain, '.'));
|
||||
|
||||
// load the list if needed
|
||||
if (empty(self::$psl)) {
|
||||
$path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
|
||||
if (0 === strpos($path, '@' . 'data_dir@')) {
|
||||
$path = realpath(
|
||||
dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
|
||||
. DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
|
||||
);
|
||||
}
|
||||
self::$psl = include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php';
|
||||
}
|
||||
|
||||
if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
|
||||
// known TLD, invalid domain name
|
||||
return false;
|
||||
}
|
||||
|
||||
// unknown TLD
|
||||
if (!strpos($result, '.')) {
|
||||
// fallback to checking that domain "has at least two dots"
|
||||
if (2 > ($count = count($domainParts))) {
|
||||
return false;
|
||||
}
|
||||
return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive helper method for {@link getRegisteredDomain()}
|
||||
*
|
||||
* @param array $domainParts remaining domain parts
|
||||
* @param mixed $listNode node in {@link HTTP_Request2_CookieJar::$psl} to check
|
||||
*
|
||||
* @return string|null concatenated domain parts, null in case of error
|
||||
*/
|
||||
protected static function checkDomainsList(array $domainParts, $listNode)
|
||||
{
|
||||
$sub = array_pop($domainParts);
|
||||
$result = null;
|
||||
|
||||
if (!is_array($listNode) || is_null($sub)
|
||||
|| array_key_exists('!' . $sub, $listNode)
|
||||
) {
|
||||
return $sub;
|
||||
|
||||
} elseif (array_key_exists($sub, $listNode)) {
|
||||
$result = self::checkDomainsList($domainParts, $listNode[$sub]);
|
||||
|
||||
} elseif (array_key_exists('*', $listNode)) {
|
||||
$result = self::checkDomainsList($domainParts, $listNode['*']);
|
||||
|
||||
} else {
|
||||
return $sub;
|
||||
}
|
||||
|
||||
return (strlen($result) > 0) ? ($result . '.' . $sub) : null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception classes for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for exceptions in PEAR
|
||||
*/
|
||||
require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* Base exception class for HTTP_Request2 package
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
||||
*/
|
||||
class HTTP_Request2_Exception extends PEAR_Exception
|
||||
{
|
||||
/** An invalid argument was passed to a method */
|
||||
const INVALID_ARGUMENT = 1;
|
||||
/** Some required value was not available */
|
||||
const MISSING_VALUE = 2;
|
||||
/** Request cannot be processed due to errors in PHP configuration */
|
||||
const MISCONFIGURATION = 3;
|
||||
/** Error reading the local file */
|
||||
const READ_ERROR = 4;
|
||||
|
||||
/** Server returned a response that does not conform to HTTP protocol */
|
||||
const MALFORMED_RESPONSE = 10;
|
||||
/** Failure decoding Content-Encoding or Transfer-Encoding of response */
|
||||
const DECODE_ERROR = 20;
|
||||
/** Operation timed out */
|
||||
const TIMEOUT = 30;
|
||||
/** Number of redirects exceeded 'max_redirects' configuration parameter */
|
||||
const TOO_MANY_REDIRECTS = 40;
|
||||
/** Redirect to a protocol other than http(s):// */
|
||||
const NON_HTTP_REDIRECT = 50;
|
||||
|
||||
/**
|
||||
* Native error code
|
||||
* @var int
|
||||
*/
|
||||
private $_nativeCode;
|
||||
|
||||
/**
|
||||
* Constructor, can set package error code and native error code
|
||||
*
|
||||
* @param string $message exception message
|
||||
* @param int $code package error code, one of class constants
|
||||
* @param int $nativeCode error code from underlying PHP extension
|
||||
*/
|
||||
public function __construct($message = null, $code = null, $nativeCode = null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->_nativeCode = $nativeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns error code produced by underlying PHP extension
|
||||
*
|
||||
* For Socket Adapter this may contain error number returned by
|
||||
* stream_socket_client(), for Curl Adapter this will contain error number
|
||||
* returned by curl_errno()
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getNativeCode()
|
||||
{
|
||||
return $this->_nativeCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown in case of missing features
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that represents error in the program logic
|
||||
*
|
||||
* This exception usually implies a programmer's error, like passing invalid
|
||||
* data to methods or trying to use PHP extensions that weren't installed or
|
||||
* enabled. Usually exceptions of this kind will be thrown before request even
|
||||
* starts.
|
||||
*
|
||||
* The exception will usually contain a package error code.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_LogicException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when connection to a web or proxy server fails
|
||||
*
|
||||
* The exception will not contain a package error code, but will contain
|
||||
* native error code, as returned by stream_socket_client() or curl_errno().
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when sending or receiving HTTP message fails
|
||||
*
|
||||
* The exception may contain both package error code and native error code.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_MessageException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for building multipart/form-data request body
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @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
|
||||
*
|
||||
* The class helps to reduce memory consumption by streaming large file uploads
|
||||
* from disk, it also allows monitoring of upload progress (see request #7630)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://tools.ietf.org/html/rfc1867
|
||||
*/
|
||||
class HTTP_Request2_MultipartBody
|
||||
{
|
||||
/**
|
||||
* MIME boundary
|
||||
* @var string
|
||||
*/
|
||||
private $_boundary;
|
||||
|
||||
/**
|
||||
* Form parameters added via {@link HTTP_Request2::addPostParameter()}
|
||||
* @var array
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* File uploads added via {@link HTTP_Request2::addUpload()}
|
||||
* @var array
|
||||
*/
|
||||
private $_uploads = array();
|
||||
|
||||
/**
|
||||
* Header for parts with parameters
|
||||
* @var string
|
||||
*/
|
||||
private $_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Header for parts with uploads
|
||||
* @var string
|
||||
*/
|
||||
private $_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Current position in parameter and upload arrays
|
||||
*
|
||||
* First number is index of "current" part, second number is position within
|
||||
* "current" part
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_pos = array(0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Sets the arrays with POST data.
|
||||
*
|
||||
* @param array $params values of form fields set via
|
||||
* {@link HTTP_Request2::addPostParameter()}
|
||||
* @param array $uploads file uploads set via
|
||||
* {@link HTTP_Request2::addUpload()}
|
||||
* @param bool $useBrackets whether to append brackets to array variable names
|
||||
*/
|
||||
public function __construct(array $params, array $uploads, $useBrackets = true)
|
||||
{
|
||||
$this->_params = self::_flattenArray('', $params, $useBrackets);
|
||||
foreach ($uploads as $fieldName => $f) {
|
||||
if (!is_array($f['fp'])) {
|
||||
$this->_uploads[] = $f + array('name' => $fieldName);
|
||||
} else {
|
||||
for ($i = 0; $i < count($f['fp']); $i++) {
|
||||
$upload = array(
|
||||
'name' => ($useBrackets? $fieldName . '[' . $i . ']': $fieldName)
|
||||
);
|
||||
foreach (array('fp', 'filename', 'size', 'type') as $key) {
|
||||
$upload[$key] = $f[$key][$i];
|
||||
}
|
||||
$this->_uploads[] = $upload;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the body to use in Content-Length header
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
$boundaryLength = strlen($this->getBoundary());
|
||||
$headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength;
|
||||
$headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength;
|
||||
$length = $boundaryLength + 6;
|
||||
foreach ($this->_params as $p) {
|
||||
$length += $headerParamLength + strlen($p[0]) + strlen($p[1]) + 2;
|
||||
}
|
||||
foreach ($this->_uploads as $u) {
|
||||
$length += $headerUploadLength + strlen($u['name']) + strlen($u['type']) +
|
||||
strlen($u['filename']) + $u['size'] + 2;
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boundary to use in Content-Type header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary()
|
||||
{
|
||||
if (empty($this->_boundary)) {
|
||||
$this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime());
|
||||
}
|
||||
return $this->_boundary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next chunk of request body
|
||||
*
|
||||
* @param integer $length Number of bytes to read
|
||||
*
|
||||
* @return string Up to $length bytes of data, empty string if at end
|
||||
* @throws HTTP_Request2_LogicException
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$ret = '';
|
||||
$boundary = $this->getBoundary();
|
||||
$paramCount = count($this->_params);
|
||||
$uploadCount = count($this->_uploads);
|
||||
while ($length > 0 && $this->_pos[0] <= $paramCount + $uploadCount) {
|
||||
$oldLength = $length;
|
||||
if ($this->_pos[0] < $paramCount) {
|
||||
$param = sprintf(
|
||||
$this->_headerParam, $boundary, $this->_params[$this->_pos[0]][0]
|
||||
) . $this->_params[$this->_pos[0]][1] . "\r\n";
|
||||
$ret .= substr($param, $this->_pos[1], $length);
|
||||
$length -= min(strlen($param) - $this->_pos[1], $length);
|
||||
|
||||
} elseif ($this->_pos[0] < $paramCount + $uploadCount) {
|
||||
$pos = $this->_pos[0] - $paramCount;
|
||||
$header = sprintf(
|
||||
$this->_headerUpload, $boundary, $this->_uploads[$pos]['name'],
|
||||
$this->_uploads[$pos]['filename'], $this->_uploads[$pos]['type']
|
||||
);
|
||||
if ($this->_pos[1] < strlen($header)) {
|
||||
$ret .= substr($header, $this->_pos[1], $length);
|
||||
$length -= min(strlen($header) - $this->_pos[1], $length);
|
||||
}
|
||||
$filePos = max(0, $this->_pos[1] - strlen($header));
|
||||
if ($filePos < $this->_uploads[$pos]['size']) {
|
||||
while ($length > 0 && !feof($this->_uploads[$pos]['fp'])) {
|
||||
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) {
|
||||
$start = $this->_pos[1] + ($oldLength - $length) -
|
||||
strlen($header) - $this->_uploads[$pos]['size'];
|
||||
$ret .= substr("\r\n", $start, $length);
|
||||
$length -= min(2 - $start, $length);
|
||||
}
|
||||
|
||||
} else {
|
||||
$closing = '--' . $boundary . "--\r\n";
|
||||
$ret .= substr($closing, $this->_pos[1], $length);
|
||||
$length -= min(strlen($closing) - $this->_pos[1], $length);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$this->_pos = array($this->_pos[0] + 1, 0);
|
||||
} else {
|
||||
$this->_pos[1] += $oldLength;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position to the start of the body
|
||||
*
|
||||
* This allows reusing the same body in another request
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_pos = array(0, 0);
|
||||
foreach ($this->_uploads as $u) {
|
||||
rewind($u['fp']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body as string
|
||||
*
|
||||
* Note that it reads all file uploads into memory so it is a good idea not
|
||||
* to use this method with large file uploads and rely on read() instead.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$this->rewind();
|
||||
return $this->read($this->getLength());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to change the (probably multidimensional) associative array
|
||||
* into the simple one.
|
||||
*
|
||||
* @param string $name name for item
|
||||
* @param mixed $values item's values
|
||||
* @param bool $useBrackets whether to append [] to array variables' names
|
||||
*
|
||||
* @return array array with the following items: array('item name', 'item value');
|
||||
*/
|
||||
private static function _flattenArray($name, $values, $useBrackets)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
return array(array($name, $values));
|
||||
} else {
|
||||
$ret = array();
|
||||
foreach ($values as $k => $v) {
|
||||
if (empty($name)) {
|
||||
$newName = $k;
|
||||
} elseif ($useBrackets) {
|
||||
$newName = $name . '[' . $k . ']';
|
||||
} else {
|
||||
$newName = $name;
|
||||
}
|
||||
$ret = array_merge($ret, self::_flattenArray($newName, $v, $useBrackets));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* An observer useful for debugging / testing.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* A debug observer useful for debugging / testing.
|
||||
*
|
||||
* This observer logs to a log target data corresponding to the various request
|
||||
* and response events, it logs by default to php://output but can be configured
|
||||
* to log to a file or via the PEAR Log package.
|
||||
*
|
||||
* A simple example:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* $observer = new HTTP_Request2_Observer_Log();
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* A more complex example with PEAR Log:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
* require_once 'Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* // we want to log with PEAR log
|
||||
* $observer = new HTTP_Request2_Observer_Log(Log::factory('console'));
|
||||
*
|
||||
* // we only want to log received headers
|
||||
* $observer->events = array('receivedHeaders');
|
||||
*
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Observer_Log implements SplObserver
|
||||
{
|
||||
// properties {{{
|
||||
|
||||
/**
|
||||
* The log target, it can be a a resource or a PEAR Log instance.
|
||||
*
|
||||
* @var resource|Log $target
|
||||
*/
|
||||
protected $target = null;
|
||||
|
||||
/**
|
||||
* The events to log.
|
||||
*
|
||||
* @var array $events
|
||||
*/
|
||||
public $events = array(
|
||||
'connect',
|
||||
'sentHeaders',
|
||||
'sentBody',
|
||||
'receivedHeaders',
|
||||
'receivedBody',
|
||||
'disconnect',
|
||||
);
|
||||
|
||||
// }}}
|
||||
// __construct() {{{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $target Can be a file path (default: php://output), a resource,
|
||||
* or an instance of the PEAR Log class.
|
||||
* @param array $events Array of events to listen to (default: all events)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target = 'php://output', array $events = array())
|
||||
{
|
||||
if (!empty($events)) {
|
||||
$this->events = $events;
|
||||
}
|
||||
if (is_resource($target) || $target instanceof Log) {
|
||||
$this->target = $target;
|
||||
} elseif (false === ($this->target = @fopen($target, 'ab'))) {
|
||||
throw new HTTP_Request2_Exception("Unable to open '{$target}'");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// update() {{{
|
||||
|
||||
/**
|
||||
* Called when the request notifies us of an event.
|
||||
*
|
||||
* @param HTTP_Request2 $subject The HTTP_Request2 instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
$event = $subject->getLastEvent();
|
||||
if (!in_array($event['name'], $this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['name']) {
|
||||
case 'connect':
|
||||
$this->log('* Connected to ' . $event['data']);
|
||||
break;
|
||||
case 'sentHeaders':
|
||||
$headers = explode("\r\n", $event['data']);
|
||||
array_pop($headers);
|
||||
foreach ($headers as $header) {
|
||||
$this->log('> ' . $header);
|
||||
}
|
||||
break;
|
||||
case 'sentBody':
|
||||
$this->log('> ' . $event['data'] . ' byte(s) sent');
|
||||
break;
|
||||
case 'receivedHeaders':
|
||||
$this->log(sprintf(
|
||||
'< HTTP/%s %s %s', $event['data']->getVersion(),
|
||||
$event['data']->getStatus(), $event['data']->getReasonPhrase()
|
||||
));
|
||||
$headers = $event['data']->getHeader();
|
||||
foreach ($headers as $key => $val) {
|
||||
$this->log('< ' . $key . ': ' . $val);
|
||||
}
|
||||
$this->log('< ');
|
||||
break;
|
||||
case 'receivedBody':
|
||||
$this->log($event['data']->getBody());
|
||||
break;
|
||||
case 'disconnect':
|
||||
$this->log('* Disconnected');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// log() {{{
|
||||
|
||||
/**
|
||||
* Logs the given message to the configured target.
|
||||
*
|
||||
* @param string $message Message to display
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if ($this->target instanceof Log) {
|
||||
$this->target->debug($message);
|
||||
} elseif (is_resource($this->target)) {
|
||||
fwrite($this->target, $message . "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,631 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* The class is designed to be used in "streaming" scenario, building the
|
||||
* response as it is being received:
|
||||
* <code>
|
||||
* $statusLine = read_status_line();
|
||||
* $response = new HTTP_Request2_Response($statusLine);
|
||||
* do {
|
||||
* $headerLine = read_header_line();
|
||||
* $response->parseHeaderLine($headerLine);
|
||||
* } while ($headerLine != '');
|
||||
*
|
||||
* while ($chunk = read_body()) {
|
||||
* $response->appendBody($chunk);
|
||||
* }
|
||||
*
|
||||
* var_dump($response->getHeader(), $response->getCookies(), $response->getBody());
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6
|
||||
*/
|
||||
class HTTP_Request2_Response
|
||||
{
|
||||
/**
|
||||
* HTTP protocol version (e.g. 1.0, 1.1)
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
* @var integer
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
* @var string
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $reasonPhrase;
|
||||
|
||||
/**
|
||||
* Effective URL (may be different from original request URL in case of redirects)
|
||||
* @var string
|
||||
*/
|
||||
protected $effectiveUrl;
|
||||
|
||||
/**
|
||||
* Associative array of response headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Cookies set in the response
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Name of last header processed by parseHederLine()
|
||||
*
|
||||
* Used to handle the headers that span multiple lines
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastHeader = null;
|
||||
|
||||
/**
|
||||
* Response body
|
||||
* @var string
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Whether the body is still encoded by Content-Encoding
|
||||
*
|
||||
* cURL provides the decoded body to the callback; if we are reading from
|
||||
* socket the body is still gzipped / deflated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $bodyEncoded;
|
||||
|
||||
/**
|
||||
* Associative array of HTTP status code / reason phrase.
|
||||
*
|
||||
* @var array
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-10
|
||||
*/
|
||||
protected static $phrases = array(
|
||||
|
||||
// 1xx: Informational - Request received, continuing process
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
// 2xx: Success - The action was successfully received, understood and
|
||||
// accepted
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
// 3xx: Redirection - Further action must be taken in order to complete
|
||||
// the request
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found', // 1.1
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
// 4xx: Client Error - The request contains bad syntax or cannot be
|
||||
// fulfilled
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
|
||||
// 5xx: Server Error - The server failed to fulfill an apparently
|
||||
// valid request
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the default reason phrase for the given code or all reason phrases
|
||||
*
|
||||
* @param int $code Response code
|
||||
*
|
||||
* @return string|array|null Default reason phrase for $code if $code is given
|
||||
* (null if no phrase is available), array of all
|
||||
* reason phrases if $code is null
|
||||
* @link http://pear.php.net/bugs/18716
|
||||
*/
|
||||
public static function getDefaultReasonPhrase($code = null)
|
||||
{
|
||||
if (null === $code) {
|
||||
return self::$phrases;
|
||||
} else {
|
||||
return isset(self::$phrases[$code]) ? self::$phrases[$code] : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, parses the response status line
|
||||
*
|
||||
* @param string $statusLine Response status line (e.g. "HTTP/1.1 200 OK")
|
||||
* @param bool $bodyEncoded Whether body is still encoded by Content-Encoding
|
||||
* @param string $effectiveUrl Effective URL of the response
|
||||
*
|
||||
* @throws HTTP_Request2_MessageException if status line is invalid according to spec
|
||||
*/
|
||||
public function __construct($statusLine, $bodyEncoded = true, $effectiveUrl = null)
|
||||
{
|
||||
if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Malformed response: {$statusLine}",
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
$this->version = $m[1];
|
||||
$this->code = intval($m[2]);
|
||||
$this->reasonPhrase = !empty($m[3]) ? trim($m[3]) : self::getDefaultReasonPhrase($this->code);
|
||||
$this->bodyEncoded = (bool)$bodyEncoded;
|
||||
$this->effectiveUrl = (string)$effectiveUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the line from HTTP response filling $headers array
|
||||
*
|
||||
* The method should be called after reading the line from socket or receiving
|
||||
* it into cURL callback. Passing an empty string here indicates the end of
|
||||
* response headers and triggers additional processing, so be sure to pass an
|
||||
* empty string in the end.
|
||||
*
|
||||
* @param string $headerLine Line from HTTP response
|
||||
*/
|
||||
public function parseHeaderLine($headerLine)
|
||||
{
|
||||
$headerLine = trim($headerLine, "\r\n");
|
||||
|
||||
if ('' == $headerLine) {
|
||||
// empty string signals the end of headers, process the received ones
|
||||
if (!empty($this->headers['set-cookie'])) {
|
||||
$cookies = is_array($this->headers['set-cookie'])?
|
||||
$this->headers['set-cookie']:
|
||||
array($this->headers['set-cookie']);
|
||||
foreach ($cookies as $cookieString) {
|
||||
$this->parseCookie($cookieString);
|
||||
}
|
||||
unset($this->headers['set-cookie']);
|
||||
}
|
||||
foreach (array_keys($this->headers) as $k) {
|
||||
if (is_array($this->headers[$k])) {
|
||||
$this->headers[$k] = implode(', ', $this->headers[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (preg_match('!^([^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+):(.+)$!', $headerLine, $m)) {
|
||||
// string of the form header-name: header value
|
||||
$name = strtolower($m[1]);
|
||||
$value = trim($m[2]);
|
||||
if (empty($this->headers[$name])) {
|
||||
$this->headers[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($this->headers[$name])) {
|
||||
$this->headers[$name] = array($this->headers[$name]);
|
||||
}
|
||||
$this->headers[$name][] = $value;
|
||||
}
|
||||
$this->lastHeader = $name;
|
||||
|
||||
} elseif (preg_match('!^\s+(.+)$!', $headerLine, $m) && $this->lastHeader) {
|
||||
// continuation of a previous header
|
||||
if (!is_array($this->headers[$this->lastHeader])) {
|
||||
$this->headers[$this->lastHeader] .= ' ' . trim($m[1]);
|
||||
} else {
|
||||
$key = count($this->headers[$this->lastHeader]) - 1;
|
||||
$this->headers[$this->lastHeader][$key] .= ' ' . trim($m[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Set-Cookie header to fill $cookies array
|
||||
*
|
||||
* @param string $cookieString value of Set-Cookie header
|
||||
*
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
protected function parseCookie($cookieString)
|
||||
{
|
||||
$cookie = array(
|
||||
'expires' => null,
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
'secure' => false
|
||||
);
|
||||
|
||||
if (!strpos($cookieString, ';')) {
|
||||
// Only a name=value pair
|
||||
$pos = strpos($cookieString, '=');
|
||||
$cookie['name'] = trim(substr($cookieString, 0, $pos));
|
||||
$cookie['value'] = trim(substr($cookieString, $pos + 1));
|
||||
|
||||
} else {
|
||||
// Some optional parameters are supplied
|
||||
$elements = explode(';', $cookieString);
|
||||
$pos = strpos($elements[0], '=');
|
||||
$cookie['name'] = trim(substr($elements[0], 0, $pos));
|
||||
$cookie['value'] = trim(substr($elements[0], $pos + 1));
|
||||
|
||||
for ($i = 1; $i < count($elements); $i++) {
|
||||
if (false === strpos($elements[$i], '=')) {
|
||||
$elName = trim($elements[$i]);
|
||||
$elValue = null;
|
||||
} else {
|
||||
list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
|
||||
}
|
||||
$elName = strtolower($elName);
|
||||
if ('secure' == $elName) {
|
||||
$cookie['secure'] = true;
|
||||
} elseif ('expires' == $elName) {
|
||||
$cookie['expires'] = str_replace('"', '', $elValue);
|
||||
} elseif ('path' == $elName || 'domain' == $elName) {
|
||||
$cookie[$elName] = urldecode($elValue);
|
||||
} else {
|
||||
$cookie[$elName] = $elValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cookies[] = $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string to the response body
|
||||
*
|
||||
* @param string $bodyChunk part of response body
|
||||
*/
|
||||
public function appendBody($bodyChunk)
|
||||
{
|
||||
$this->body .= $bodyChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective URL of the response
|
||||
*
|
||||
* This may be different from the request URL if redirects were followed.
|
||||
*
|
||||
* @return string
|
||||
* @link http://pear.php.net/bugs/bug.php?id=18412
|
||||
*/
|
||||
public function getEffectiveUrl()
|
||||
{
|
||||
return $this->effectiveUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reason phrase
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether response is a redirect that can be automatically handled by HTTP_Request2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return in_array($this->code, array(300, 301, 302, 303, 307))
|
||||
&& isset($this->headers['location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the named header or all response headers
|
||||
*
|
||||
* @param string $headerName Name of header to return
|
||||
*
|
||||
* @return string|array Value of $headerName header (null if header is
|
||||
* not present), array of all response headers if
|
||||
* $headerName is null
|
||||
*/
|
||||
public function getHeader($headerName = null)
|
||||
{
|
||||
if (null === $headerName) {
|
||||
return $this->headers;
|
||||
} else {
|
||||
$headerName = strtolower($headerName);
|
||||
return isset($this->headers[$headerName])? $this->headers[$headerName]: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cookies set in response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCookies()
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the response
|
||||
*
|
||||
* @return string
|
||||
* @throws HTTP_Request2_Exception if body cannot be decoded
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (0 == strlen($this->body) || !$this->bodyEncoded
|
||||
|| !in_array(strtolower($this->getHeader('content-encoding')), array('gzip', 'deflate'))
|
||||
) {
|
||||
return $this->body;
|
||||
|
||||
} else {
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
|
||||
try {
|
||||
switch (strtolower($this->getHeader('content-encoding'))) {
|
||||
case 'gzip':
|
||||
$decoded = self::decodeGzip($this->body);
|
||||
break;
|
||||
case 'deflate':
|
||||
$decoded = self::decodeDeflate($this->body);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP version of the response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by gzip
|
||||
*
|
||||
* The real decoding work is done by gzinflate() built-in function, this
|
||||
* method only parses the header and checks data for compliance with
|
||||
* RFC 1952
|
||||
*
|
||||
* @param string $data gzip-encoded data
|
||||
*
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
*/
|
||||
public static function decodeGzip($data)
|
||||
{
|
||||
$length = strlen($data);
|
||||
// If it doesn't look like gzip-encoded data, don't bother
|
||||
if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
|
||||
return $data;
|
||||
}
|
||||
if (!function_exists('gzinflate')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Unable to decode body: gzip extension not available',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
$method = ord(substr($data, 2, 1));
|
||||
if (8 != $method) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: unknown compression method',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$flags = ord(substr($data, 3, 1));
|
||||
if ($flags & 224) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: reserved bits are set',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
// header is 10 bytes minimum. may be longer, though.
|
||||
$headerLength = 10;
|
||||
// extra fields, need to skip 'em
|
||||
if ($flags & 4) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$extraLength = unpack('v', substr($data, 10, 2));
|
||||
if ($length - $headerLength - 2 - $extraLength[1] < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $extraLength[1] + 2;
|
||||
}
|
||||
// file name, need to skip that
|
||||
if ($flags & 8) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$filenameLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $filenameLength + 1;
|
||||
}
|
||||
// comment, need to skip that also
|
||||
if ($flags & 16) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$commentLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $commentLength + 1;
|
||||
}
|
||||
// have a CRC for header. let's check
|
||||
if ($flags & 2) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$crcReal = 0xffff & crc32(substr($data, 0, $headerLength));
|
||||
$crcStored = unpack('v', substr($data, $headerLength, 2));
|
||||
if ($crcReal != $crcStored[1]) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Header CRC check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += 2;
|
||||
}
|
||||
// unpacked data CRC and size at the end of encoded data
|
||||
$tmp = unpack('V2', substr($data, -8));
|
||||
$dataCrc = $tmp[1];
|
||||
$dataSize = $tmp[2];
|
||||
|
||||
// finally, call the gzinflate() function
|
||||
// don't pass $dataSize to gzinflate, see bugs #13135, #14370
|
||||
$unpacked = gzinflate(substr($data, $headerLength, -8));
|
||||
if (false === $unpacked) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'gzinflate() call failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
} elseif ($dataSize != strlen($unpacked)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Data size check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
} elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
'Data CRC check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by deflate
|
||||
*
|
||||
* @param string $data deflate-encoded data
|
||||
*
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_LogicException
|
||||
*/
|
||||
public static function decodeDeflate($data)
|
||||
{
|
||||
if (!function_exists('gzuncompress')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Unable to decode body: gzip extension not available',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
// RFC 2616 defines 'deflate' encoding as zlib format from RFC 1950,
|
||||
// while many applications send raw deflate stream from RFC 1951.
|
||||
// We should check for presence of zlib header and use gzuncompress() or
|
||||
// gzinflate() as needed. See bug #15305
|
||||
$header = unpack('n', substr($data, 0, 2));
|
||||
return (0 == $header[1] % 31)? gzuncompress($data): gzinflate($data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* SOCKS5 proxy connection class
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Socket wrapper class used by Socket Adapter */
|
||||
require_once 'HTTP/Request2/SocketWrapper.php';
|
||||
|
||||
/**
|
||||
* SOCKS5 proxy connection class (used by Socket Adapter)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19332
|
||||
* @link http://tools.ietf.org/html/rfc1928
|
||||
*/
|
||||
class HTTP_Request2_SOCKS5 extends HTTP_Request2_SocketWrapper
|
||||
{
|
||||
/**
|
||||
* Constructor, tries to connect and authenticate to a SOCKS5 proxy
|
||||
*
|
||||
* @param string $address Proxy address, e.g. 'tcp://localhost:1080'
|
||||
* @param int $timeout Connection timeout (seconds)
|
||||
* @param array $contextOptions Stream context options
|
||||
* @param string $username Proxy user name
|
||||
* @param string $password Proxy password
|
||||
*
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function __construct(
|
||||
$address, $timeout = 10, array $contextOptions = array(),
|
||||
$username = null, $password = null
|
||||
) {
|
||||
parent::__construct($address, $timeout, $contextOptions);
|
||||
|
||||
if (strlen($username)) {
|
||||
$request = pack('C4', 5, 2, 0, 2);
|
||||
} else {
|
||||
$request = pack('C3', 5, 1, 0);
|
||||
}
|
||||
$this->write($request);
|
||||
$response = unpack('Cversion/Cmethod', $this->read(3));
|
||||
if (5 != $response['version']) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Invalid version received from SOCKS5 proxy: ' . $response['version'],
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
switch ($response['method']) {
|
||||
case 2:
|
||||
$this->performAuthentication($username, $password);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Connection rejected by proxy due to unsupported auth method"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs username/password authentication for SOCKS5
|
||||
*
|
||||
* @param string $username Proxy user name
|
||||
* @param string $password Proxy password
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @link http://tools.ietf.org/html/rfc1929
|
||||
*/
|
||||
protected function performAuthentication($username, $password)
|
||||
{
|
||||
$request = pack('C2', 1, strlen($username)) . $username
|
||||
. pack('C', strlen($password)) . $password;
|
||||
|
||||
$this->write($request);
|
||||
$response = unpack('Cvn/Cstatus', $this->read(3));
|
||||
if (1 != $response['vn'] || 0 != $response['status']) {
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
'Connection rejected by proxy due to invalid username and/or password'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a remote host via proxy
|
||||
*
|
||||
* @param string $remoteHost Remote host
|
||||
* @param int $remotePort Remote port
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function connect($remoteHost, $remotePort)
|
||||
{
|
||||
$request = pack('C5', 0x05, 0x01, 0x00, 0x03, strlen($remoteHost))
|
||||
. $remoteHost . pack('n', $remotePort);
|
||||
|
||||
$this->write($request);
|
||||
$response = unpack('Cversion/Creply/Creserved', $this->read(1024));
|
||||
if (5 != $response['version'] || 0 != $response['reserved']) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Invalid response received from SOCKS5 proxy',
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
} elseif (0 != $response['reply']) {
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Unable to connect to {$remoteHost}:{$remotePort} through SOCKS5 proxy",
|
||||
0, $response['reply']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,297 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Socket wrapper class used by Socket Adapter
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Exception classes for HTTP_Request2 package */
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Socket wrapper class used by Socket Adapter
|
||||
*
|
||||
* Needed to properly handle connection errors, global timeout support and
|
||||
* similar things. Loosely based on Net_Socket used by older HTTP_Request.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: 2.2.1
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19332
|
||||
* @link http://tools.ietf.org/html/rfc1928
|
||||
*/
|
||||
class HTTP_Request2_SocketWrapper
|
||||
{
|
||||
/**
|
||||
* PHP warning messages raised during stream_socket_client() call
|
||||
* @var array
|
||||
*/
|
||||
protected $connectionWarnings = array();
|
||||
|
||||
/**
|
||||
* Connected socket
|
||||
* @var resource
|
||||
*/
|
||||
protected $socket;
|
||||
|
||||
/**
|
||||
* Sum of start time and global timeout, exception will be thrown if request continues past this time
|
||||
* @var integer
|
||||
*/
|
||||
protected $deadline;
|
||||
|
||||
/**
|
||||
* Global timeout value, mostly for exception messages
|
||||
* @var integer
|
||||
*/
|
||||
protected $timeout;
|
||||
|
||||
/**
|
||||
* Class constructor, tries to establish connection
|
||||
*
|
||||
* @param string $address Address for stream_socket_client() call,
|
||||
* e.g. 'tcp://localhost:80'
|
||||
* @param int $timeout Connection timeout (seconds)
|
||||
* @param array $contextOptions Context options
|
||||
*
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
*/
|
||||
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();
|
||||
foreach ($contextOptions as $wrapper => $options) {
|
||||
foreach ($options as $name => $value) {
|
||||
if (!stream_context_set_option($context, $wrapper, $name, $value)) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Error setting '{$wrapper}' wrapper context option '{$name}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
set_error_handler(array($this, 'connectionWarningsHandler'));
|
||||
$this->socket = stream_socket_client(
|
||||
$address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context
|
||||
);
|
||||
restore_error_handler();
|
||||
// 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);
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Unable to connect to {$address}. Error: {$error}", 0, $errno
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor, disconnects socket
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
fclose($this->socket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fread(), handles global request timeout
|
||||
*
|
||||
* @param int $length Reads up to this number of bytes
|
||||
*
|
||||
* @return string Data read from socket
|
||||
* @throws HTTP_Request2_MessageException In case of timeout
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
$data = fread($this->socket, $length);
|
||||
$this->checkTimeout();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads until either the end of the socket or a newline, whichever comes first
|
||||
*
|
||||
* Strips the trailing newline from the returned data, handles global
|
||||
* request timeout. Method idea borrowed from Net_Socket PEAR package.
|
||||
*
|
||||
* @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)
|
||||
* @throws HTTP_Request2_MessageException In case of timeout
|
||||
*/
|
||||
public function readLine($bufferSize, $localTimeout = null)
|
||||
{
|
||||
$line = '';
|
||||
while (!feof($this->socket)) {
|
||||
if (null !== $localTimeout) {
|
||||
stream_set_timeout($this->socket, $localTimeout);
|
||||
} elseif ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
|
||||
$line .= @fgets($this->socket, $bufferSize);
|
||||
|
||||
if (null === $localTimeout) {
|
||||
$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") {
|
||||
return rtrim($line, "\r\n");
|
||||
}
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fwrite(), handles global request timeout
|
||||
*
|
||||
* @param string $data String to be written
|
||||
*
|
||||
* @return int
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function write($data)
|
||||
{
|
||||
if ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
$written = fwrite($this->socket, $data);
|
||||
$this->checkTimeout();
|
||||
// http://www.php.net/manual/en/function.fwrite.php#96951
|
||||
if ($written < strlen($data)) {
|
||||
throw new HTTP_Request2_MessageException('Error writing request');
|
||||
}
|
||||
return $written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for end-of-file on a socket
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function eof()
|
||||
{
|
||||
return feof($this->socket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request deadline
|
||||
*
|
||||
* @param int $deadline Exception will be thrown if request continues
|
||||
* past this time
|
||||
* @param int $timeout Original request timeout value, to use in
|
||||
* Exception message
|
||||
*/
|
||||
public function setDeadline($deadline, $timeout)
|
||||
{
|
||||
$this->deadline = $deadline;
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on encryption on a socket
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
*/
|
||||
public function enableCrypto()
|
||||
{
|
||||
$modes = array(
|
||||
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
||||
);
|
||||
|
||||
foreach ($modes as $mode) {
|
||||
if (stream_socket_enable_crypto($this->socket, true, $mode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
'Failed to enable secure connection when connecting through proxy'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an Exception if stream timed out
|
||||
*
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
protected function checkTimeout()
|
||||
{
|
||||
$info = stream_get_meta_data($this->socket);
|
||||
if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
|
||||
$reason = $this->deadline
|
||||
? "after {$this->timeout} second(s)"
|
||||
: 'due to default_socket_timeout php.ini setting';
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Request timed out {$reason}", HTTP_Request2_Exception::TIMEOUT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler to use during stream_socket_client() call
|
||||
*
|
||||
* One stream_socket_client() call may produce *multiple* PHP warnings
|
||||
* (especially OpenSSL-related), we keep them in an array to later use for
|
||||
* the message of HTTP_Request2_ConnectionException
|
||||
*
|
||||
* @param int $errno error level
|
||||
* @param string $errstr error message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function connectionWarningsHandler($errno, $errstr)
|
||||
{
|
||||
if ($errno & E_WARNING) {
|
||||
array_unshift($this->connectionWarnings, $errstr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,389 +0,0 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
/**
|
||||
* PEAR_Exception
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V. V. Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.3.3
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Base PEAR_Exception Class
|
||||
*
|
||||
* 1) Features:
|
||||
*
|
||||
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
|
||||
* - Definable triggers, shot when exceptions occur
|
||||
* - Pretty and informative error messages
|
||||
* - Added more context info available (like class, method or cause)
|
||||
* - cause can be a PEAR_Exception or an array of mixed
|
||||
* PEAR_Exceptions/PEAR_ErrorStack warnings
|
||||
* - callbacks for specific exception classes and their children
|
||||
*
|
||||
* 2) Ideas:
|
||||
*
|
||||
* - Maybe a way to define a 'template' for the output
|
||||
*
|
||||
* 3) Inherited properties from PHP Exception Class:
|
||||
*
|
||||
* protected $message
|
||||
* protected $code
|
||||
* protected $line
|
||||
* protected $file
|
||||
* private $trace
|
||||
*
|
||||
* 4) Inherited methods from PHP Exception Class:
|
||||
*
|
||||
* __clone
|
||||
* __construct
|
||||
* getMessage
|
||||
* getCode
|
||||
* getFile
|
||||
* getLine
|
||||
* getTraceSafe
|
||||
* getTraceSafeAsString
|
||||
* __toString
|
||||
*
|
||||
* 5) Usage example
|
||||
*
|
||||
* <code>
|
||||
* require_once 'PEAR/Exception.php';
|
||||
*
|
||||
* class Test {
|
||||
* function foo() {
|
||||
* throw new PEAR_Exception('Error Message', ERROR_CODE);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* function myLogger($pear_exception) {
|
||||
* echo $pear_exception->getMessage();
|
||||
* }
|
||||
* // each time a exception is thrown the 'myLogger' will be called
|
||||
* // (its use is completely optional)
|
||||
* PEAR_Exception::addObserver('myLogger');
|
||||
* $test = new Test;
|
||||
* try {
|
||||
* $test->foo();
|
||||
* } catch (PEAR_Exception $e) {
|
||||
* print $e;
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.5
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.3.3
|
||||
*
|
||||
*/
|
||||
class PEAR_Exception extends Exception
|
||||
{
|
||||
const OBSERVER_PRINT = -2;
|
||||
const OBSERVER_TRIGGER = -4;
|
||||
const OBSERVER_DIE = -8;
|
||||
protected $cause;
|
||||
private static $_observers = array();
|
||||
private static $_uniqueid = 0;
|
||||
private $_trace;
|
||||
|
||||
/**
|
||||
* Supported signatures:
|
||||
* - PEAR_Exception(string $message);
|
||||
* - PEAR_Exception(string $message, int $code);
|
||||
* - PEAR_Exception(string $message, Exception $cause);
|
||||
* - PEAR_Exception(string $message, Exception $cause, int $code);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
|
||||
* - PEAR_Exception(string $message, array $causes);
|
||||
* - PEAR_Exception(string $message, array $causes, int $code);
|
||||
* @param string exception message
|
||||
* @param int|Exception|PEAR_Error|array|null exception cause
|
||||
* @param int|null exception code or null
|
||||
*/
|
||||
public function __construct($message, $p2 = null, $p3 = null)
|
||||
{
|
||||
if (is_int($p2)) {
|
||||
$code = $p2;
|
||||
$this->cause = null;
|
||||
} elseif (is_object($p2) || is_array($p2)) {
|
||||
// using is_object allows both Exception and PEAR_Error
|
||||
if (is_object($p2) && !($p2 instanceof Exception)) {
|
||||
if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
|
||||
throw new PEAR_Exception('exception cause must be Exception, ' .
|
||||
'array, or PEAR_Error');
|
||||
}
|
||||
}
|
||||
$code = $p3;
|
||||
if (is_array($p2) && isset($p2['message'])) {
|
||||
// fix potential problem of passing in a single warning
|
||||
$p2 = array($p2);
|
||||
}
|
||||
$this->cause = $p2;
|
||||
} else {
|
||||
$code = null;
|
||||
$this->cause = null;
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
$this->signal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $callback - A valid php callback, see php func is_callable()
|
||||
* - A PEAR_Exception::OBSERVER_* constant
|
||||
* - An array(const PEAR_Exception::OBSERVER_*,
|
||||
* mixed $options)
|
||||
* @param string $label The name of the observer. Use this if you want
|
||||
* to remove it later with removeObserver()
|
||||
*/
|
||||
public static function addObserver($callback, $label = 'default')
|
||||
{
|
||||
self::$_observers[$label] = $callback;
|
||||
}
|
||||
|
||||
public static function removeObserver($label = 'default')
|
||||
{
|
||||
unset(self::$_observers[$label]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int unique identifier for an observer
|
||||
*/
|
||||
public static function getUniqueId()
|
||||
{
|
||||
return self::$_uniqueid++;
|
||||
}
|
||||
|
||||
private function signal()
|
||||
{
|
||||
foreach (self::$_observers as $func) {
|
||||
if (is_callable($func)) {
|
||||
call_user_func($func, $this);
|
||||
continue;
|
||||
}
|
||||
settype($func, 'array');
|
||||
switch ($func[0]) {
|
||||
case self::OBSERVER_PRINT :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
printf($f, $this->getMessage());
|
||||
break;
|
||||
case self::OBSERVER_TRIGGER :
|
||||
$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
|
||||
trigger_error($this->getMessage(), $f);
|
||||
break;
|
||||
case self::OBSERVER_DIE :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
die(printf($f, $this->getMessage()));
|
||||
break;
|
||||
default:
|
||||
trigger_error('invalid observer type', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return specific error information that can be used for more detailed
|
||||
* error messages or translation.
|
||||
*
|
||||
* This method may be overridden in child exception classes in order
|
||||
* to add functionality not present in PEAR_Exception and is a placeholder
|
||||
* to define API
|
||||
*
|
||||
* The returned array must be an associative array of parameter => value like so:
|
||||
* <pre>
|
||||
* array('name' => $name, 'context' => array(...))
|
||||
* </pre>
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorData()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception that caused this exception to be thrown
|
||||
* @access public
|
||||
* @return Exception|array The context of the exception
|
||||
*/
|
||||
public function getCause()
|
||||
{
|
||||
return $this->cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function must be public to call on caused exceptions
|
||||
* @param array
|
||||
*/
|
||||
public function getCauseMessage(&$causes)
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$cause = array('class' => get_class($this),
|
||||
'message' => $this->message,
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
if (isset($trace[0])) {
|
||||
if (isset($trace[0]['file'])) {
|
||||
$cause['file'] = $trace[0]['file'];
|
||||
$cause['line'] = $trace[0]['line'];
|
||||
}
|
||||
}
|
||||
$causes[] = $cause;
|
||||
if ($this->cause instanceof PEAR_Exception) {
|
||||
$this->cause->getCauseMessage($causes);
|
||||
} elseif ($this->cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => $this->cause->getFile(),
|
||||
'line' => $this->cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($this->cause)) {
|
||||
foreach ($this->cause as $cause) {
|
||||
if ($cause instanceof PEAR_Exception) {
|
||||
$cause->getCauseMessage($causes);
|
||||
} elseif ($cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => $cause->getFile(),
|
||||
'line' => $cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($cause) && isset($cause['message'])) {
|
||||
// PEAR_ErrorStack warning
|
||||
$causes[] = array(
|
||||
'class' => $cause['package'],
|
||||
'message' => $cause['message'],
|
||||
'file' => isset($cause['context']['file']) ?
|
||||
$cause['context']['file'] :
|
||||
'unknown',
|
||||
'line' => isset($cause['context']['line']) ?
|
||||
$cause['context']['line'] :
|
||||
'unknown',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTraceSafe()
|
||||
{
|
||||
if (!isset($this->_trace)) {
|
||||
$this->_trace = $this->getTrace();
|
||||
if (empty($this->_trace)) {
|
||||
$backtrace = debug_backtrace();
|
||||
$this->_trace = array($backtrace[count($backtrace)-1]);
|
||||
}
|
||||
}
|
||||
return $this->_trace;
|
||||
}
|
||||
|
||||
public function getErrorClass()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['class'];
|
||||
}
|
||||
|
||||
public function getErrorMethod()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['function'];
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
return $this->toHtml();
|
||||
}
|
||||
return $this->toText();
|
||||
}
|
||||
|
||||
public function toHtml()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$html = '<table style="border: 1px" cellspacing="0">' . "\n";
|
||||
foreach ($causes as $i => $cause) {
|
||||
$html .= '<tr><td colspan="3" style="background: #ff9999">'
|
||||
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
|
||||
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
|
||||
. 'on line <b>' . $cause['line'] . '</b>'
|
||||
. "</td></tr>\n";
|
||||
}
|
||||
$html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
|
||||
. '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
|
||||
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
|
||||
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
|
||||
|
||||
foreach ($trace as $k => $v) {
|
||||
$html .= '<tr><td style="text-align: center;">' . $k . '</td>'
|
||||
. '<td>';
|
||||
if (!empty($v['class'])) {
|
||||
$html .= $v['class'] . $v['type'];
|
||||
}
|
||||
$html .= $v['function'];
|
||||
$args = array();
|
||||
if (!empty($v['args'])) {
|
||||
foreach ($v['args'] as $arg) {
|
||||
if (is_null($arg)) $args[] = 'null';
|
||||
elseif (is_array($arg)) $args[] = 'Array';
|
||||
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
|
||||
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
|
||||
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
|
||||
else {
|
||||
$arg = (string)$arg;
|
||||
$str = htmlspecialchars(substr($arg, 0, 16));
|
||||
if (strlen($arg) > 16) $str .= '…';
|
||||
$args[] = "'" . $str . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '(' . implode(', ',$args) . ')'
|
||||
. '</td>'
|
||||
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
|
||||
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
|
||||
. '</td></tr>' . "\n";
|
||||
}
|
||||
$html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
|
||||
. '<td>{main}</td>'
|
||||
. '<td> </td></tr>' . "\n"
|
||||
. '</table>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function toText()
|
||||
{
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$causeMsg = '';
|
||||
foreach ($causes as $i => $cause) {
|
||||
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
|
||||
. $cause['message'] . ' in ' . $cause['file']
|
||||
. ' on line ' . $cause['line'] . "\n";
|
||||
}
|
||||
return $causeMsg . $this->getTraceAsString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This is only meant for PHP 5 to get rid of certain strict warning
|
||||
* that doesn't get hidden since it's in the shutdown function
|
||||
*/
|
||||
class PEAR5
|
||||
{
|
||||
/**
|
||||
* If you have a class that's mostly/entirely static, and you need static
|
||||
* properties, you can use this method to simulate them. Eg. in your method(s)
|
||||
* do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
|
||||
* You MUST use a reference, or they will not persist!
|
||||
*
|
||||
* @access public
|
||||
* @param string $class The calling classname, to prevent clashes
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
static function &getStaticProperty($class, $var)
|
||||
{
|
||||
static $properties;
|
||||
if (!isset($properties[$class])) {
|
||||
$properties[$class] = array();
|
||||
}
|
||||
|
||||
if (!array_key_exists($var, $properties[$class])) {
|
||||
$properties[$class][$var] = null;
|
||||
}
|
||||
|
||||
return $properties[$class][$var];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
class HTTP_Request extends HTTP_Request2
|
||||
{
|
||||
private $reponse = null;
|
||||
|
||||
public function addHeader($name, $value)
|
||||
{
|
||||
$this->setHeader($name, $value);
|
||||
}
|
||||
|
||||
public function sendRequest($saveBody = true)
|
||||
{
|
||||
$response = $this->send();
|
||||
$this->response = $response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getResponseCode() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseHeader() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getHeader();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseBody() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
public function getResponseCookies() {
|
||||
if($this->response)
|
||||
{
|
||||
return $this->response->getCookies();
|
||||
}
|
||||
}
|
||||
|
||||
public function addPostData($name, $value, $preencoded = false)
|
||||
{
|
||||
$this->addPostParameter($name, $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,861 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP request message
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Request2.php 298246 2010-04-21 10:41:16Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* A class representing an URL as per RFC 3986.
|
||||
*/
|
||||
require_once 'Net/URL2.php';
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request message
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-5
|
||||
*/
|
||||
class HTTP_Request2 implements SplSubject
|
||||
{
|
||||
/**#@+
|
||||
* Constants for HTTP request methods
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-5.1.1
|
||||
*/
|
||||
const METHOD_OPTIONS = 'OPTIONS';
|
||||
const METHOD_GET = 'GET';
|
||||
const METHOD_HEAD = 'HEAD';
|
||||
const METHOD_POST = 'POST';
|
||||
const METHOD_PUT = 'PUT';
|
||||
const METHOD_DELETE = 'DELETE';
|
||||
const METHOD_TRACE = 'TRACE';
|
||||
const METHOD_CONNECT = 'CONNECT';
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Constants for HTTP authentication schemes
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc2617
|
||||
*/
|
||||
const AUTH_BASIC = 'basic';
|
||||
const AUTH_DIGEST = 'digest';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Regular expression used to check for invalid symbols in RFC 2616 tokens
|
||||
* @link http://pear.php.net/bugs/bug.php?id=15630
|
||||
*/
|
||||
const REGEXP_INVALID_TOKEN = '![\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]!';
|
||||
|
||||
/**
|
||||
* Regular expression used to check for invalid symbols in cookie strings
|
||||
* @link http://pear.php.net/bugs/bug.php?id=15630
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
const REGEXP_INVALID_COOKIE = '/[\s,;]/';
|
||||
|
||||
/**
|
||||
* Fileinfo magic database resource
|
||||
* @var resource
|
||||
* @see detectMimeType()
|
||||
*/
|
||||
private static $_fileinfoDb;
|
||||
|
||||
/**
|
||||
* Observers attached to the request (instances of SplObserver)
|
||||
* @var array
|
||||
*/
|
||||
protected $observers = array();
|
||||
|
||||
/**
|
||||
* Request URL
|
||||
* @var Net_URL2
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Request method
|
||||
* @var string
|
||||
*/
|
||||
protected $method = self::METHOD_GET;
|
||||
|
||||
/**
|
||||
* Authentication data
|
||||
* @var array
|
||||
* @see getAuth()
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Request headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Configuration parameters
|
||||
* @var array
|
||||
* @see setConfig()
|
||||
*/
|
||||
protected $config = array(
|
||||
'adapter' => 'HTTP_Request2_Adapter_Socket',
|
||||
'connect_timeout' => 10,
|
||||
'timeout' => 0,
|
||||
'use_brackets' => true,
|
||||
'protocol_version' => '1.1',
|
||||
'buffer_size' => 16384,
|
||||
'store_body' => true,
|
||||
|
||||
'proxy_host' => '',
|
||||
'proxy_port' => '',
|
||||
'proxy_user' => '',
|
||||
'proxy_password' => '',
|
||||
'proxy_auth_scheme' => self::AUTH_BASIC,
|
||||
|
||||
'ssl_verify_peer' => true,
|
||||
'ssl_verify_host' => true,
|
||||
'ssl_cafile' => null,
|
||||
'ssl_capath' => null,
|
||||
'ssl_local_cert' => null,
|
||||
'ssl_passphrase' => null,
|
||||
|
||||
'digest_compat_ie' => false,
|
||||
|
||||
'follow_redirects' => false,
|
||||
'max_redirects' => 5,
|
||||
'strict_redirects' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Last event in request / response handling, intended for observers
|
||||
* @var array
|
||||
* @see getLastEvent()
|
||||
*/
|
||||
protected $lastEvent = array(
|
||||
'name' => 'start',
|
||||
'data' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource
|
||||
* @see setBody()
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Array of POST parameters
|
||||
* @var array
|
||||
*/
|
||||
protected $postParams = array();
|
||||
|
||||
/**
|
||||
* Array of file uploads (for multipart/form-data POST requests)
|
||||
* @var array
|
||||
*/
|
||||
protected $uploads = array();
|
||||
|
||||
/**
|
||||
* Adapter used to perform actual HTTP request
|
||||
* @var HTTP_Request2_Adapter
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Can set request URL, method and configuration array.
|
||||
*
|
||||
* Also sets a default value for User-Agent header.
|
||||
*
|
||||
* @param string|Net_Url2 Request URL
|
||||
* @param string Request method
|
||||
* @param array Configuration for this Request instance
|
||||
*/
|
||||
public function __construct($url = null, $method = self::METHOD_GET, array $config = array())
|
||||
{
|
||||
$this->setConfig($config);
|
||||
if (!empty($url)) {
|
||||
$this->setUrl($url);
|
||||
}
|
||||
if (!empty($method)) {
|
||||
$this->setMethod($method);
|
||||
}
|
||||
$this->setHeader('user-agent', 'HTTP_Request2/0.5.2 ' .
|
||||
'(http://pear.php.net/package/http_request2) ' .
|
||||
'PHP/' . phpversion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL for this request
|
||||
*
|
||||
* If the URL has userinfo part (username & password) these will be removed
|
||||
* and converted to auth data. If the URL does not have a path component,
|
||||
* that will be set to '/'.
|
||||
*
|
||||
* @param string|Net_URL2 Request URL
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
if (is_string($url)) {
|
||||
$url = new Net_URL2(
|
||||
$url, array(Net_URL2::OPTION_USE_BRACKETS => $this->config['use_brackets'])
|
||||
);
|
||||
}
|
||||
if (!$url instanceof Net_URL2) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid HTTP URL');
|
||||
}
|
||||
// URL contains username / password?
|
||||
if ($url->getUserinfo()) {
|
||||
$username = $url->getUser();
|
||||
$password = $url->getPassword();
|
||||
$this->setAuth(rawurldecode($username), $password? rawurldecode($password): '');
|
||||
$url->setUserinfo('');
|
||||
}
|
||||
if ('' == $url->getPath()) {
|
||||
$url->setPath('/');
|
||||
}
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request URL
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request method
|
||||
*
|
||||
* @param string
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception if the method name is invalid
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
// Method name should be a token: http://tools.ietf.org/html/rfc2616#section-5.1.1
|
||||
if (preg_match(self::REGEXP_INVALID_TOKEN, $method)) {
|
||||
throw new HTTP_Request2_Exception("Invalid request method '{$method}'");
|
||||
}
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration parameter(s)
|
||||
*
|
||||
* The following parameters are available:
|
||||
* <ul>
|
||||
* <li> 'adapter' - adapter to use (string)</li>
|
||||
* <li> 'connect_timeout' - Connection timeout in seconds (integer)</li>
|
||||
* <li> 'timeout' - Total number of seconds a request can take.
|
||||
* Use 0 for no limit, should be greater than
|
||||
* 'connect_timeout' if set (integer)</li>
|
||||
* <li> 'use_brackets' - Whether to append [] to array variable names (bool)</li>
|
||||
* <li> 'protocol_version' - HTTP Version to use, '1.0' or '1.1' (string)</li>
|
||||
* <li> 'buffer_size' - Buffer size to use for reading and writing (int)</li>
|
||||
* <li> 'store_body' - Whether to store response body in response object.
|
||||
* Set to false if receiving a huge response and
|
||||
* using an Observer to save it (boolean)</li>
|
||||
* <li> 'proxy_host' - Proxy server host (string)</li>
|
||||
* <li> 'proxy_port' - Proxy server port (integer)</li>
|
||||
* <li> 'proxy_user' - Proxy auth username (string)</li>
|
||||
* <li> 'proxy_password' - Proxy auth password (string)</li>
|
||||
* <li> 'proxy_auth_scheme' - Proxy auth scheme, one of HTTP_Request2::AUTH_* constants (string)</li>
|
||||
* <li> 'ssl_verify_peer' - Whether to verify peer's SSL certificate (bool)</li>
|
||||
* <li> 'ssl_verify_host' - Whether to check that Common Name in SSL
|
||||
* certificate matches host name (bool)</li>
|
||||
* <li> 'ssl_cafile' - Cerificate Authority file to verify the peer
|
||||
* with (use with 'ssl_verify_peer') (string)</li>
|
||||
* <li> 'ssl_capath' - Directory holding multiple Certificate
|
||||
* Authority files (string)</li>
|
||||
* <li> 'ssl_local_cert' - Name of a file containing local cerificate (string)</li>
|
||||
* <li> 'ssl_passphrase' - Passphrase with which local certificate
|
||||
* was encoded (string)</li>
|
||||
* <li> 'digest_compat_ie' - Whether to imitate behaviour of MSIE 5 and 6
|
||||
* in using URL without query string in digest
|
||||
* authentication (boolean)</li>
|
||||
* <li> 'follow_redirects' - Whether to automatically follow HTTP Redirects (boolean)</li>
|
||||
* <li> 'max_redirects' - Maximum number of redirects to follow (integer)</li>
|
||||
* <li> 'strict_redirects' - Whether to keep request method on redirects via status 301 and
|
||||
* 302 (true, needed for compatibility with RFC 2616)
|
||||
* or switch to GET (false, needed for compatibility with most
|
||||
* browsers) (boolean)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param string|array configuration parameter name or array
|
||||
* ('parameter name' => 'parameter value')
|
||||
* @param mixed parameter value if $nameOrConfig is not an array
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception If the parameter is unknown
|
||||
*/
|
||||
public function setConfig($nameOrConfig, $value = null)
|
||||
{
|
||||
if (is_array($nameOrConfig)) {
|
||||
foreach ($nameOrConfig as $name => $value) {
|
||||
$this->setConfig($name, $value);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!array_key_exists($nameOrConfig, $this->config)) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
"Unknown configuration parameter '{$nameOrConfig}'"
|
||||
);
|
||||
}
|
||||
$this->config[$nameOrConfig] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value(s) of the configuration parameter(s)
|
||||
*
|
||||
* @param string parameter name
|
||||
* @return mixed value of $name parameter, array of all configuration
|
||||
* parameters if $name is not given
|
||||
* @throws HTTP_Request2_Exception If the parameter is unknown
|
||||
*/
|
||||
public function getConfig($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
return $this->config;
|
||||
} elseif (!array_key_exists($name, $this->config)) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
"Unknown configuration parameter '{$name}'"
|
||||
);
|
||||
}
|
||||
return $this->config[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the autentification data
|
||||
*
|
||||
* @param string user name
|
||||
* @param string password
|
||||
* @param string authentication scheme
|
||||
* @return HTTP_Request2
|
||||
*/
|
||||
public function setAuth($user, $password = '', $scheme = self::AUTH_BASIC)
|
||||
{
|
||||
if (empty($user)) {
|
||||
$this->auth = null;
|
||||
} else {
|
||||
$this->auth = array(
|
||||
'user' => (string)$user,
|
||||
'password' => (string)$password,
|
||||
'scheme' => $scheme
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authentication data
|
||||
*
|
||||
* The array has the keys 'user', 'password' and 'scheme', where 'scheme'
|
||||
* is one of the HTTP_Request2::AUTH_* constants.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuth()
|
||||
{
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request header(s)
|
||||
*
|
||||
* The first parameter may be either a full header string 'header: value' or
|
||||
* header name. In the former case $value parameter is ignored, in the latter
|
||||
* the header's value will either be set to $value or the header will be
|
||||
* removed if $value is null. The first parameter can also be an array of
|
||||
* headers, in that case method will be called recursively.
|
||||
*
|
||||
* Note that headers are treated case insensitively as per RFC 2616.
|
||||
*
|
||||
* <code>
|
||||
* $req->setHeader('Foo: Bar'); // sets the value of 'Foo' header to 'Bar'
|
||||
* $req->setHeader('FoO', 'Baz'); // sets the value of 'Foo' header to 'Baz'
|
||||
* $req->setHeader(array('foo' => 'Quux')); // sets the value of 'Foo' header to 'Quux'
|
||||
* $req->setHeader('FOO'); // removes 'Foo' header from request
|
||||
* </code>
|
||||
*
|
||||
* @param string|array header name, header string ('Header: value')
|
||||
* or an array of headers
|
||||
* @param string|null header value, header will be removed if null
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setHeader($name, $value = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
foreach ($name as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$this->setHeader($k, $v);
|
||||
} else {
|
||||
$this->setHeader($v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (null === $value && strpos($name, ':')) {
|
||||
list($name, $value) = array_map('trim', explode(':', $name, 2));
|
||||
}
|
||||
// Header name should be a token: http://tools.ietf.org/html/rfc2616#section-4.2
|
||||
if (preg_match(self::REGEXP_INVALID_TOKEN, $name)) {
|
||||
throw new HTTP_Request2_Exception("Invalid header name '{$name}'");
|
||||
}
|
||||
// Header names are case insensitive anyway
|
||||
$name = strtolower($name);
|
||||
if (null === $value) {
|
||||
unset($this->headers[$name]);
|
||||
} else {
|
||||
$this->headers[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request headers
|
||||
*
|
||||
* The array is of the form ('header name' => 'header value'), header names
|
||||
* are lowercased
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a cookie to "Cookie:" header
|
||||
*
|
||||
* @param string cookie name
|
||||
* @param string cookie value
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addCookie($name, $value)
|
||||
{
|
||||
$cookie = $name . '=' . $value;
|
||||
if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
|
||||
throw new HTTP_Request2_Exception("Invalid cookie: '{$cookie}'");
|
||||
}
|
||||
$cookies = empty($this->headers['cookie'])? '': $this->headers['cookie'] . '; ';
|
||||
$this->setHeader('cookie', $cookies . $cookie);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request body
|
||||
*
|
||||
* @param string Either a string with the body or filename containing body
|
||||
* @param bool Whether first parameter is a filename
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setBody($body, $isFilename = false)
|
||||
{
|
||||
if (!$isFilename) {
|
||||
if (!$body instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->body = (string)$body;
|
||||
} else {
|
||||
$this->body = $body;
|
||||
}
|
||||
} else {
|
||||
if (!($fp = @fopen($body, 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$body}");
|
||||
}
|
||||
$this->body = $fp;
|
||||
if (empty($this->headers['content-type'])) {
|
||||
$this->setHeader('content-type', self::detectMimeType($body));
|
||||
}
|
||||
}
|
||||
$this->postParams = $this->uploads = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request body
|
||||
*
|
||||
* @return string|resource|HTTP_Request2_MultipartBody
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (self::METHOD_POST == $this->method &&
|
||||
(!empty($this->postParams) || !empty($this->uploads))
|
||||
) {
|
||||
if ('application/x-www-form-urlencoded' == $this->headers['content-type']) {
|
||||
$body = http_build_query($this->postParams, '', '&');
|
||||
if (!$this->getConfig('use_brackets')) {
|
||||
$body = preg_replace('/%5B\d+%5D=/', '=', $body);
|
||||
}
|
||||
// support RFC 3986 by not encoding '~' symbol (request #15368)
|
||||
return str_replace('%7E', '~', $body);
|
||||
|
||||
} elseif ('multipart/form-data' == $this->headers['content-type']) {
|
||||
require_once 'HTTP/Request2/MultipartBody.php';
|
||||
return new HTTP_Request2_MultipartBody(
|
||||
$this->postParams, $this->uploads, $this->getConfig('use_brackets')
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file to form-based file upload
|
||||
*
|
||||
* Used to emulate file upload via a HTML form. The method also sets
|
||||
* Content-Type of HTTP request to 'multipart/form-data'.
|
||||
*
|
||||
* If you just want to send the contents of a file as the body of HTTP
|
||||
* request you should use setBody() method.
|
||||
*
|
||||
* @param string name of file-upload field
|
||||
* @param mixed full name of local file
|
||||
* @param string filename to send in the request
|
||||
* @param string content-type of file being uploaded
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addUpload($fieldName, $filename, $sendFilename = null,
|
||||
$contentType = null)
|
||||
{
|
||||
if (!is_array($filename)) {
|
||||
if (!($fp = @fopen($filename, 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$filename}");
|
||||
}
|
||||
$this->uploads[$fieldName] = array(
|
||||
'fp' => $fp,
|
||||
'filename' => empty($sendFilename)? basename($filename): $sendFilename,
|
||||
'size' => filesize($filename),
|
||||
'type' => empty($contentType)? self::detectMimeType($filename): $contentType
|
||||
);
|
||||
} else {
|
||||
$fps = $names = $sizes = $types = array();
|
||||
foreach ($filename as $f) {
|
||||
if (!is_array($f)) {
|
||||
$f = array($f);
|
||||
}
|
||||
if (!($fp = @fopen($f[0], 'rb'))) {
|
||||
throw new HTTP_Request2_Exception("Cannot open file {$f[0]}");
|
||||
}
|
||||
$fps[] = $fp;
|
||||
$names[] = empty($f[1])? basename($f[0]): $f[1];
|
||||
$sizes[] = filesize($f[0]);
|
||||
$types[] = empty($f[2])? self::detectMimeType($f[0]): $f[2];
|
||||
}
|
||||
$this->uploads[$fieldName] = array(
|
||||
'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
|
||||
);
|
||||
}
|
||||
if (empty($this->headers['content-type']) ||
|
||||
'application/x-www-form-urlencoded' == $this->headers['content-type']
|
||||
) {
|
||||
$this->setHeader('content-type', 'multipart/form-data');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds POST parameter(s) to the request.
|
||||
*
|
||||
* @param string|array parameter name or array ('name' => 'value')
|
||||
* @param mixed parameter value (can be an array)
|
||||
* @return HTTP_Request2
|
||||
*/
|
||||
public function addPostParameter($name, $value = null)
|
||||
{
|
||||
if (!is_array($name)) {
|
||||
$this->postParams[$name] = $value;
|
||||
} else {
|
||||
foreach ($name as $k => $v) {
|
||||
$this->addPostParameter($k, $v);
|
||||
}
|
||||
}
|
||||
if (empty($this->headers['content-type'])) {
|
||||
$this->setHeader('content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches a new observer
|
||||
*
|
||||
* @param SplObserver
|
||||
*/
|
||||
public function attach(SplObserver $observer)
|
||||
{
|
||||
foreach ($this->observers as $attached) {
|
||||
if ($attached === $observer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->observers[] = $observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an existing observer
|
||||
*
|
||||
* @param SplObserver
|
||||
*/
|
||||
public function detach(SplObserver $observer)
|
||||
{
|
||||
foreach ($this->observers as $key => $attached) {
|
||||
if ($attached === $observer) {
|
||||
unset($this->observers[$key]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all observers
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
foreach ($this->observers as $observer) {
|
||||
$observer->update($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last event
|
||||
*
|
||||
* Adapters should use this method to set the current state of the request
|
||||
* and notify the observers.
|
||||
*
|
||||
* @param string event name
|
||||
* @param mixed event data
|
||||
*/
|
||||
public function setLastEvent($name, $data = null)
|
||||
{
|
||||
$this->lastEvent = array(
|
||||
'name' => $name,
|
||||
'data' => $data
|
||||
);
|
||||
$this->notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last event
|
||||
*
|
||||
* Observers should use this method to access the last change in request.
|
||||
* The following event names are possible:
|
||||
* <ul>
|
||||
* <li>'connect' - after connection to remote server,
|
||||
* data is the destination (string)</li>
|
||||
* <li>'disconnect' - after disconnection from server</li>
|
||||
* <li>'sentHeaders' - after sending the request headers,
|
||||
* data is the headers sent (string)</li>
|
||||
* <li>'sentBodyPart' - after sending a part of the request body,
|
||||
* data is the length of that part (int)</li>
|
||||
* <li>'receivedHeaders' - after receiving the response headers,
|
||||
* data is HTTP_Request2_Response object</li>
|
||||
* <li>'receivedBodyPart' - after receiving a part of the response
|
||||
* body, data is that part (string)</li>
|
||||
* <li>'receivedEncodedBodyPart' - as 'receivedBodyPart', but data is still
|
||||
* encoded by Content-Encoding</li>
|
||||
* <li>'receivedBody' - after receiving the complete response
|
||||
* body, data is HTTP_Request2_Response object</li>
|
||||
* </ul>
|
||||
* Different adapters may not send all the event types. Mock adapter does
|
||||
* not send any events to the observers.
|
||||
*
|
||||
* @return array The array has two keys: 'name' and 'data'
|
||||
*/
|
||||
public function getLastEvent()
|
||||
{
|
||||
return $this->lastEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the adapter used to actually perform the request
|
||||
*
|
||||
* You can pass either an instance of a class implementing HTTP_Request2_Adapter
|
||||
* or a class name. The method will only try to include a file if the class
|
||||
* name starts with HTTP_Request2_Adapter_, it will also try to prepend this
|
||||
* prefix to the class name if it doesn't contain any underscores, so that
|
||||
* <code>
|
||||
* $request->setAdapter('curl');
|
||||
* </code>
|
||||
* will work.
|
||||
*
|
||||
* @param string|HTTP_Request2_Adapter
|
||||
* @return HTTP_Request2
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
if (is_string($adapter)) {
|
||||
if (!class_exists($adapter, false)) {
|
||||
if (false === strpos($adapter, '_')) {
|
||||
$adapter = 'HTTP_Request2_Adapter_' . ucfirst($adapter);
|
||||
}
|
||||
if (preg_match('/^HTTP_Request2_Adapter_([a-zA-Z0-9]+)$/', $adapter)) {
|
||||
include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter) . '.php';
|
||||
}
|
||||
if (!class_exists($adapter, false)) {
|
||||
throw new HTTP_Request2_Exception("Class {$adapter} not found");
|
||||
}
|
||||
}
|
||||
$adapter = new $adapter;
|
||||
}
|
||||
if (!$adapter instanceof HTTP_Request2_Adapter) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a HTTP request adapter');
|
||||
}
|
||||
$this->adapter = $adapter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the request and returns the response
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @return HTTP_Request2_Response
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
// Sanity check for URL
|
||||
if (!$this->url instanceof Net_URL2) {
|
||||
throw new HTTP_Request2_Exception('No URL given');
|
||||
} elseif (!$this->url->isAbsolute()) {
|
||||
throw new HTTP_Request2_Exception('Absolute URL required');
|
||||
} elseif (!in_array(strtolower($this->url->getScheme()), array('https', 'http'))) {
|
||||
throw new HTTP_Request2_Exception('Not a HTTP URL');
|
||||
}
|
||||
if (empty($this->adapter)) {
|
||||
$this->setAdapter($this->getConfig('adapter'));
|
||||
}
|
||||
// magic_quotes_runtime may break file uploads and chunked response
|
||||
// processing; see bug #4543. Don't use ini_get() here; see bug #16440.
|
||||
if ($magicQuotes = get_magic_quotes_runtime()) {
|
||||
set_magic_quotes_runtime(false);
|
||||
}
|
||||
// force using single byte encoding if mbstring extension overloads
|
||||
// strlen() and substr(); see bug #1781, bug #10605
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('iso-8859-1');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->adapter->sendRequest($this);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
// cleanup in either case (poor man's "finally" clause)
|
||||
if ($magicQuotes) {
|
||||
set_magic_quotes_runtime(true);
|
||||
}
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
// rethrow the exception
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to detect MIME type of a file
|
||||
*
|
||||
* The method will try to use fileinfo extension if it is available,
|
||||
* deprecated mime_content_type() function in the other case. If neither
|
||||
* works, default 'application/octet-stream' MIME type is returned
|
||||
*
|
||||
* @param string filename
|
||||
* @return string file MIME type
|
||||
*/
|
||||
protected static function detectMimeType($filename)
|
||||
{
|
||||
// finfo extension from PECL available
|
||||
if (function_exists('finfo_open')) {
|
||||
if (!isset(self::$_fileinfoDb)) {
|
||||
self::$_fileinfoDb = @finfo_open(FILEINFO_MIME);
|
||||
}
|
||||
if (self::$_fileinfoDb) {
|
||||
$info = finfo_file(self::$_fileinfoDb, $filename);
|
||||
}
|
||||
}
|
||||
// (deprecated) mime_content_type function available
|
||||
if (empty($info) && function_exists('mime_content_type')) {
|
||||
return mime_content_type($filename);
|
||||
}
|
||||
return empty($info)? 'application/octet-stream': $info;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Adapter.php 291118 2009-11-21 17:58:23Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*/
|
||||
require_once 'HTTP/Request2/Response.php';
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* HTTP_Request2 class itself only defines methods for aggregating the request
|
||||
* data, all actual work of sending the request to the remote server and
|
||||
* receiving its response is performed by adapters.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
abstract class HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A list of methods that MUST NOT have a request body, per RFC 2616
|
||||
* @var array
|
||||
*/
|
||||
protected static $bodyDisallowed = array('TRACE');
|
||||
|
||||
/**
|
||||
* Methods having defined semantics for request body
|
||||
*
|
||||
* Content-Length header (indicating that the body follows, section 4.3 of
|
||||
* RFC 2616) will be sent for these methods even if no body was added
|
||||
*
|
||||
* @var array
|
||||
* @link http://pear.php.net/bugs/bug.php?id=12900
|
||||
* @link http://pear.php.net/bugs/bug.php?id=14740
|
||||
*/
|
||||
protected static $bodyRequired = array('POST', 'PUT');
|
||||
|
||||
/**
|
||||
* Request being sent
|
||||
* @var HTTP_Request2
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource|HTTP_Request2_MultipartBody
|
||||
* @see HTTP_Request2::getBody()
|
||||
*/
|
||||
protected $requestBody;
|
||||
|
||||
/**
|
||||
* Length of the request body
|
||||
* @var integer
|
||||
*/
|
||||
protected $contentLength;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
abstract public function sendRequest(HTTP_Request2 $request);
|
||||
|
||||
/**
|
||||
* Calculates length of the request body, adds proper headers
|
||||
*
|
||||
* @param array associative array of request headers, this method will
|
||||
* add proper 'Content-Length' and 'Content-Type' headers
|
||||
* to this array (or remove them if not needed)
|
||||
*/
|
||||
protected function calculateRequestLength(&$headers)
|
||||
{
|
||||
$this->requestBody = $this->request->getBody();
|
||||
|
||||
if (is_string($this->requestBody)) {
|
||||
$this->contentLength = strlen($this->requestBody);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$stat = fstat($this->requestBody);
|
||||
$this->contentLength = $stat['size'];
|
||||
rewind($this->requestBody);
|
||||
} else {
|
||||
$this->contentLength = $this->requestBody->getLength();
|
||||
$headers['content-type'] = 'multipart/form-data; boundary=' .
|
||||
$this->requestBody->getBoundary();
|
||||
$this->requestBody->rewind();
|
||||
}
|
||||
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
|
||||
0 == $this->contentLength
|
||||
) {
|
||||
// No body: send a Content-Length header nonetheless (request #12900),
|
||||
// but do that only for methods that require a body (bug #14740)
|
||||
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
|
||||
$headers['content-length'] = 0;
|
||||
} else {
|
||||
unset($headers['content-length']);
|
||||
// if the method doesn't require a body and doesn't have a
|
||||
// body, don't send a Content-Type header. (request #16799)
|
||||
unset($headers['content-type']);
|
||||
}
|
||||
} else {
|
||||
if (empty($headers['content-type'])) {
|
||||
$headers['content-type'] = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
$headers['content-length'] = $this->contentLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,461 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Curl.php 291118 2009-11-21 17:58:23Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* Mapping of header names to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $headerMap = array(
|
||||
'accept-encoding' => CURLOPT_ENCODING,
|
||||
'cookie' => CURLOPT_COOKIE,
|
||||
'referer' => CURLOPT_REFERER,
|
||||
'user-agent' => CURLOPT_USERAGENT
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of SSL context options to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $sslContextMap = array(
|
||||
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
|
||||
'ssl_cafile' => CURLOPT_CAINFO,
|
||||
'ssl_capath' => CURLOPT_CAPATH,
|
||||
'ssl_local_cert' => CURLOPT_SSLCERT,
|
||||
'ssl_passphrase' => CURLOPT_SSLCERTPASSWD
|
||||
);
|
||||
|
||||
/**
|
||||
* Response being received
|
||||
* @var HTTP_Request2_Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Whether 'sentHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventSentHeaders = false;
|
||||
|
||||
/**
|
||||
* Whether 'receivedHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventReceivedHeaders = false;
|
||||
|
||||
/**
|
||||
* Position within request body
|
||||
* @var integer
|
||||
* @see callbackReadBody()
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Information about last transfer, as returned by curl_getinfo()
|
||||
* @var array
|
||||
*/
|
||||
protected $lastInfo;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new HTTP_Request2_Exception('cURL extension not available');
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
$this->response = null;
|
||||
$this->position = 0;
|
||||
$this->eventSentHeaders = false;
|
||||
$this->eventReceivedHeaders = false;
|
||||
|
||||
try {
|
||||
if (false === curl_exec($ch = $this->createCurlHandle())) {
|
||||
$errorMessage = 'Error sending request: #' . curl_errno($ch) .
|
||||
' ' . curl_error($ch);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
$this->lastInfo = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$response = $this->response;
|
||||
unset($this->request, $this->requestBody, $this->response);
|
||||
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
} elseif (!empty($errorMessage)) {
|
||||
throw new HTTP_Request2_Exception($errorMessage);
|
||||
}
|
||||
|
||||
if (0 < $this->lastInfo['size_download']) {
|
||||
$request->setLastEvent('receivedBody', $response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about last transfer
|
||||
*
|
||||
* @return array associative array as returned by curl_getinfo()
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->lastInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cURL handle and populates it with data from the request
|
||||
*
|
||||
* @return resource a cURL handle, as created by curl_init()
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
protected function createCurlHandle()
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, array(
|
||||
// setup write callbacks
|
||||
CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
|
||||
CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
|
||||
// buffer size
|
||||
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
|
||||
// connection timeout
|
||||
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
|
||||
// save full outgoing headers, in case someone is interested
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
// request url
|
||||
CURLOPT_URL => $this->request->getUrl()->getUrl()
|
||||
));
|
||||
|
||||
// set up redirects
|
||||
if (!$this->request->getConfig('follow_redirects')) {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
|
||||
// limit redirects to http(s), works in 5.2.10+
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
// works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571
|
||||
if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) {
|
||||
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
|
||||
}
|
||||
}
|
||||
|
||||
// request timeout
|
||||
if ($timeout = $this->request->getConfig('timeout')) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
|
||||
// set HTTP version
|
||||
switch ($this->request->getConfig('protocol_version')) {
|
||||
case '1.0':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
break;
|
||||
case '1.1':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
|
||||
// set request method
|
||||
switch ($this->request->getMethod()) {
|
||||
case HTTP_Request2::METHOD_GET:
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_POST:
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_HEAD:
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
default:
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
|
||||
}
|
||||
|
||||
// set proxy, if needed
|
||||
if ($host = $this->request->getConfig('proxy_host')) {
|
||||
if (!($port = $this->request->getConfig('proxy_port'))) {
|
||||
throw new HTTP_Request2_Exception('Proxy port not provided');
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
|
||||
if ($user = $this->request->getConfig('proxy_user')) {
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' .
|
||||
$this->request->getConfig('proxy_password'));
|
||||
switch ($this->request->getConfig('proxy_auth_scheme')) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set authentication data
|
||||
if ($auth = $this->request->getAuth()) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
|
||||
switch ($auth['scheme']) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
|
||||
// set SSL options
|
||||
if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) {
|
||||
foreach ($this->request->getConfig() as $name => $value) {
|
||||
if ('ssl_verify_host' == $name && null !== $value) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
|
||||
} elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
|
||||
curl_setopt($ch, self::$sslContextMap[$name], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$headers = $this->request->getHeaders();
|
||||
// make cURL automagically send proper header
|
||||
if (!isset($headers['accept-encoding'])) {
|
||||
$headers['accept-encoding'] = '';
|
||||
}
|
||||
|
||||
// set headers having special cURL keys
|
||||
foreach (self::$headerMap as $name => $option) {
|
||||
if (isset($headers[$name])) {
|
||||
curl_setopt($ch, $option, $headers[$name]);
|
||||
unset($headers[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->calculateRequestLength($headers);
|
||||
if (isset($headers['content-length'])) {
|
||||
$this->workaroundPhpBug47204($ch, $headers);
|
||||
}
|
||||
|
||||
// set headers not having special keys
|
||||
$headersFmt = array();
|
||||
foreach ($headers as $name => $value) {
|
||||
$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
|
||||
$headersFmt[] = $canonicalName . ': ' . $value;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
|
||||
|
||||
return $ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for PHP bug #47204 that prevents rewinding request body
|
||||
*
|
||||
* The workaround consists of reading the entire request body into memory
|
||||
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
|
||||
* file uploads, use Socket adapter instead.
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param array Request headers
|
||||
*/
|
||||
protected function workaroundPhpBug47204($ch, &$headers)
|
||||
{
|
||||
// no redirects, no digest auth -> probably no rewind needed
|
||||
if (!$this->request->getConfig('follow_redirects')
|
||||
&& (!($auth = $this->request->getAuth())
|
||||
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
|
||||
) {
|
||||
curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
|
||||
|
||||
// rewind may be needed, read the whole body into memory
|
||||
} else {
|
||||
if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->requestBody = $this->requestBody->__toString();
|
||||
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$fp = $this->requestBody;
|
||||
$this->requestBody = '';
|
||||
while (!feof($fp)) {
|
||||
$this->requestBody .= fread($fp, 16384);
|
||||
}
|
||||
}
|
||||
// curl hangs up if content-length is present
|
||||
unset($headers['content-length']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for reading the request body
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param resource file descriptor (not used)
|
||||
* @param integer maximum length of data to return
|
||||
* @return string part of the request body, up to $length bytes
|
||||
*/
|
||||
protected function callbackReadBody($ch, $fd, $length)
|
||||
{
|
||||
if (!$this->eventSentHeaders) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
$this->eventSentHeaders = true;
|
||||
}
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
|
||||
0 == $this->contentLength || $this->position >= $this->contentLength
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
if (is_string($this->requestBody)) {
|
||||
$string = substr($this->requestBody, $this->position, $length);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$string = fread($this->requestBody, $length);
|
||||
} else {
|
||||
$string = $this->requestBody->read($length);
|
||||
}
|
||||
$this->request->setLastEvent('sentBodyPart', strlen($string));
|
||||
$this->position += strlen($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response headers
|
||||
*
|
||||
* @param resource cURL handle
|
||||
* @param string response header (with trailing CRLF)
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::parseHeaderLine()
|
||||
*/
|
||||
protected function callbackWriteHeader($ch, $string)
|
||||
{
|
||||
// we may receive a second set of headers if doing e.g. digest auth
|
||||
if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (!$this->eventSentHeaders ||
|
||||
$this->response->getStatus() >= 200
|
||||
) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
}
|
||||
$upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
|
||||
// if body wasn't read by a callback, send event with total body size
|
||||
if ($upload > $this->position) {
|
||||
$this->request->setLastEvent(
|
||||
'sentBodyPart', $upload - $this->position
|
||||
);
|
||||
$this->position = $upload;
|
||||
}
|
||||
$this->eventSentHeaders = true;
|
||||
// we'll need a new response object
|
||||
if ($this->eventReceivedHeaders) {
|
||||
$this->eventReceivedHeaders = false;
|
||||
$this->response = null;
|
||||
}
|
||||
}
|
||||
if (empty($this->response)) {
|
||||
$this->response = new HTTP_Request2_Response($string, false);
|
||||
} else {
|
||||
$this->response->parseHeaderLine($string);
|
||||
if ('' == trim($string)) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (200 <= $this->response->getStatus()) {
|
||||
$this->request->setLastEvent('receivedHeaders', $this->response);
|
||||
}
|
||||
// for versions lower than 5.2.10, check the redirection URL protocol
|
||||
if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS')
|
||||
&& $this->response->isRedirect()
|
||||
) {
|
||||
$redirectUrl = new Net_URL2($this->response->getHeader('location'));
|
||||
if ($redirectUrl->isAbsolute()
|
||||
&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
$this->eventReceivedHeaders = true;
|
||||
}
|
||||
}
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response body
|
||||
*
|
||||
* @param resource cURL handle (not used)
|
||||
* @param string part of the response body
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::appendBody()
|
||||
*/
|
||||
protected function callbackWriteBody($ch, $string)
|
||||
{
|
||||
// cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
|
||||
// response doesn't start with proper HTTP status line (see bug #15716)
|
||||
if (empty($this->response)) {
|
||||
throw new HTTP_Request2_Exception("Malformed response: {$string}");
|
||||
}
|
||||
if ($this->request->getConfig('store_body')) {
|
||||
$this->response->appendBody($string);
|
||||
}
|
||||
$this->request->setLastEvent('receivedBodyPart', $string);
|
||||
return strlen($string);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Mock.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* Can be used to test applications depending on HTTP_Request2 package without
|
||||
* actually performing any HTTP requests. This adapter will return responses
|
||||
* previously added via addResponse()
|
||||
* <code>
|
||||
* $mock = new HTTP_Request2_Adapter_Mock();
|
||||
* $mock->addResponse("HTTP/1.1 ... ");
|
||||
*
|
||||
* $request = new HTTP_Request2();
|
||||
* $request->setAdapter($mock);
|
||||
*
|
||||
* // This will return the response set above
|
||||
* $response = $req->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A queue of responses to be returned by sendRequest()
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
|
||||
/**
|
||||
* Returns the next response from the queue built by addResponse()
|
||||
*
|
||||
* If the queue is empty it will return default empty response with status 400,
|
||||
* if an Exception object was added to the queue it will be thrown.
|
||||
*
|
||||
* @param HTTP_Request2
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (count($this->responses) > 0) {
|
||||
$response = array_shift($this->responses);
|
||||
if ($response instanceof HTTP_Request2_Response) {
|
||||
return $response;
|
||||
} else {
|
||||
// rethrow the exception
|
||||
$class = get_class($response);
|
||||
$message = $response->getMessage();
|
||||
$code = $response->getCode();
|
||||
throw new $class($message, $code);
|
||||
}
|
||||
} else {
|
||||
return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds response to the queue
|
||||
*
|
||||
* @param mixed either a string, a pointer to an open file,
|
||||
* an instance of HTTP_Request2_Response or Exception
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addResponse($response)
|
||||
{
|
||||
if (is_string($response)) {
|
||||
$response = self::createResponseFromString($response);
|
||||
} elseif (is_resource($response)) {
|
||||
$response = self::createResponseFromFile($response);
|
||||
} elseif (!$response instanceof HTTP_Request2_Response &&
|
||||
!$response instanceof Exception
|
||||
) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid response');
|
||||
}
|
||||
$this->responses[] = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a string
|
||||
*
|
||||
* @param string
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromString($str)
|
||||
{
|
||||
$parts = preg_split('!(\r?\n){2}!m', $str, 2);
|
||||
$headerLines = explode("\n", $parts[0]);
|
||||
$response = new HTTP_Request2_Response(array_shift($headerLines));
|
||||
foreach ($headerLines as $headerLine) {
|
||||
$response->parseHeaderLine($headerLine);
|
||||
}
|
||||
$response->parseHeaderLine('');
|
||||
if (isset($parts[1])) {
|
||||
$response->appendBody($parts[1]);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a file
|
||||
*
|
||||
* @param resource file pointer returned by fopen()
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromFile($fp)
|
||||
{
|
||||
$response = new HTTP_Request2_Response(fgets($fp));
|
||||
do {
|
||||
$headerLine = fgets($fp);
|
||||
$response->parseHeaderLine($headerLine);
|
||||
} while ('' != trim($headerLine));
|
||||
|
||||
while (!feof($fp)) {
|
||||
$response->appendBody(fread($fp, 8192));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Exception.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for exceptions in PEAR
|
||||
*/
|
||||
require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*
|
||||
* Such a class is required by the Exception RFC:
|
||||
* http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @version Release: 0.5.2
|
||||
*/
|
||||
class HTTP_Request2_Exception extends PEAR_Exception
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,274 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for building multipart/form-data request body
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: MultipartBody.php 290192 2009-11-03 21:29:32Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for building multipart/form-data request body
|
||||
*
|
||||
* The class helps to reduce memory consumption by streaming large file uploads
|
||||
* from disk, it also allows monitoring of upload progress (see request #7630)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc1867
|
||||
*/
|
||||
class HTTP_Request2_MultipartBody
|
||||
{
|
||||
/**
|
||||
* MIME boundary
|
||||
* @var string
|
||||
*/
|
||||
private $_boundary;
|
||||
|
||||
/**
|
||||
* Form parameters added via {@link HTTP_Request2::addPostParameter()}
|
||||
* @var array
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* File uploads added via {@link HTTP_Request2::addUpload()}
|
||||
* @var array
|
||||
*/
|
||||
private $_uploads = array();
|
||||
|
||||
/**
|
||||
* Header for parts with parameters
|
||||
* @var string
|
||||
*/
|
||||
private $_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Header for parts with uploads
|
||||
* @var string
|
||||
*/
|
||||
private $_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Current position in parameter and upload arrays
|
||||
*
|
||||
* First number is index of "current" part, second number is position within
|
||||
* "current" part
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_pos = array(0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Sets the arrays with POST data.
|
||||
*
|
||||
* @param array values of form fields set via {@link HTTP_Request2::addPostParameter()}
|
||||
* @param array file uploads set via {@link HTTP_Request2::addUpload()}
|
||||
* @param bool whether to append brackets to array variable names
|
||||
*/
|
||||
public function __construct(array $params, array $uploads, $useBrackets = true)
|
||||
{
|
||||
$this->_params = self::_flattenArray('', $params, $useBrackets);
|
||||
foreach ($uploads as $fieldName => $f) {
|
||||
if (!is_array($f['fp'])) {
|
||||
$this->_uploads[] = $f + array('name' => $fieldName);
|
||||
} else {
|
||||
for ($i = 0; $i < count($f['fp']); $i++) {
|
||||
$upload = array(
|
||||
'name' => ($useBrackets? $fieldName . '[' . $i . ']': $fieldName)
|
||||
);
|
||||
foreach (array('fp', 'filename', 'size', 'type') as $key) {
|
||||
$upload[$key] = $f[$key][$i];
|
||||
}
|
||||
$this->_uploads[] = $upload;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the body to use in Content-Length header
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
$boundaryLength = strlen($this->getBoundary());
|
||||
$headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength;
|
||||
$headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength;
|
||||
$length = $boundaryLength + 6;
|
||||
foreach ($this->_params as $p) {
|
||||
$length += $headerParamLength + strlen($p[0]) + strlen($p[1]) + 2;
|
||||
}
|
||||
foreach ($this->_uploads as $u) {
|
||||
$length += $headerUploadLength + strlen($u['name']) + strlen($u['type']) +
|
||||
strlen($u['filename']) + $u['size'] + 2;
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boundary to use in Content-Type header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary()
|
||||
{
|
||||
if (empty($this->_boundary)) {
|
||||
$this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime());
|
||||
}
|
||||
return $this->_boundary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next chunk of request body
|
||||
*
|
||||
* @param integer Amount of bytes to read
|
||||
* @return string Up to $length bytes of data, empty string if at end
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$ret = '';
|
||||
$boundary = $this->getBoundary();
|
||||
$paramCount = count($this->_params);
|
||||
$uploadCount = count($this->_uploads);
|
||||
while ($length > 0 && $this->_pos[0] <= $paramCount + $uploadCount) {
|
||||
$oldLength = $length;
|
||||
if ($this->_pos[0] < $paramCount) {
|
||||
$param = sprintf($this->_headerParam, $boundary,
|
||||
$this->_params[$this->_pos[0]][0]) .
|
||||
$this->_params[$this->_pos[0]][1] . "\r\n";
|
||||
$ret .= substr($param, $this->_pos[1], $length);
|
||||
$length -= min(strlen($param) - $this->_pos[1], $length);
|
||||
|
||||
} elseif ($this->_pos[0] < $paramCount + $uploadCount) {
|
||||
$pos = $this->_pos[0] - $paramCount;
|
||||
$header = sprintf($this->_headerUpload, $boundary,
|
||||
$this->_uploads[$pos]['name'],
|
||||
$this->_uploads[$pos]['filename'],
|
||||
$this->_uploads[$pos]['type']);
|
||||
if ($this->_pos[1] < strlen($header)) {
|
||||
$ret .= substr($header, $this->_pos[1], $length);
|
||||
$length -= min(strlen($header) - $this->_pos[1], $length);
|
||||
}
|
||||
$filePos = max(0, $this->_pos[1] - strlen($header));
|
||||
if ($length > 0 && $filePos < $this->_uploads[$pos]['size']) {
|
||||
$ret .= fread($this->_uploads[$pos]['fp'], $length);
|
||||
$length -= min($length, $this->_uploads[$pos]['size'] - $filePos);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$start = $this->_pos[1] + ($oldLength - $length) -
|
||||
strlen($header) - $this->_uploads[$pos]['size'];
|
||||
$ret .= substr("\r\n", $start, $length);
|
||||
$length -= min(2 - $start, $length);
|
||||
}
|
||||
|
||||
} else {
|
||||
$closing = '--' . $boundary . "--\r\n";
|
||||
$ret .= substr($closing, $this->_pos[1], $length);
|
||||
$length -= min(strlen($closing) - $this->_pos[1], $length);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$this->_pos = array($this->_pos[0] + 1, 0);
|
||||
} else {
|
||||
$this->_pos[1] += $oldLength;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position to the start of the body
|
||||
*
|
||||
* This allows reusing the same body in another request
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_pos = array(0, 0);
|
||||
foreach ($this->_uploads as $u) {
|
||||
rewind($u['fp']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body as string
|
||||
*
|
||||
* Note that it reads all file uploads into memory so it is a good idea not
|
||||
* to use this method with large file uploads and rely on read() instead.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$this->rewind();
|
||||
return $this->read($this->getLength());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to change the (probably multidimensional) associative array
|
||||
* into the simple one.
|
||||
*
|
||||
* @param string name for item
|
||||
* @param mixed item's values
|
||||
* @param bool whether to append [] to array variables' names
|
||||
* @return array array with the following items: array('item name', 'item value');
|
||||
*/
|
||||
private static function _flattenArray($name, $values, $useBrackets)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
return array(array($name, $values));
|
||||
} else {
|
||||
$ret = array();
|
||||
foreach ($values as $k => $v) {
|
||||
if (empty($name)) {
|
||||
$newName = $k;
|
||||
} elseif ($useBrackets) {
|
||||
$newName = $name . '[' . $k . ']';
|
||||
} else {
|
||||
$newName = $name;
|
||||
}
|
||||
$ret = array_merge($ret, self::_flattenArray($newName, $v, $useBrackets));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* An observer useful for debugging / testing.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Log.php 293416 2010-01-11 18:06:15Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* A debug observer useful for debugging / testing.
|
||||
*
|
||||
* This observer logs to a log target data corresponding to the various request
|
||||
* and response events, it logs by default to php://output but can be configured
|
||||
* to log to a file or via the PEAR Log package.
|
||||
*
|
||||
* A simple example:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* $observer = new HTTP_Request2_Observer_Log();
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* A more complex example with PEAR Log:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
* require_once 'Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* // we want to log with PEAR log
|
||||
* $observer = new HTTP_Request2_Observer_Log(Log::factory('console'));
|
||||
*
|
||||
* // we only want to log received headers
|
||||
* $observer->events = array('receivedHeaders');
|
||||
*
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 0.5.2
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Observer_Log implements SplObserver
|
||||
{
|
||||
// properties {{{
|
||||
|
||||
/**
|
||||
* The log target, it can be a a resource or a PEAR Log instance.
|
||||
*
|
||||
* @var resource|Log $target
|
||||
*/
|
||||
protected $target = null;
|
||||
|
||||
/**
|
||||
* The events to log.
|
||||
*
|
||||
* @var array $events
|
||||
*/
|
||||
public $events = array(
|
||||
'connect',
|
||||
'sentHeaders',
|
||||
'sentBodyPart',
|
||||
'receivedHeaders',
|
||||
'receivedBody',
|
||||
'disconnect',
|
||||
);
|
||||
|
||||
// }}}
|
||||
// __construct() {{{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $target Can be a file path (default: php://output), a resource,
|
||||
* or an instance of the PEAR Log class.
|
||||
* @param array $events Array of events to listen to (default: all events)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target = 'php://output', array $events = array())
|
||||
{
|
||||
if (!empty($events)) {
|
||||
$this->events = $events;
|
||||
}
|
||||
if (is_resource($target) || $target instanceof Log) {
|
||||
$this->target = $target;
|
||||
} elseif (false === ($this->target = @fopen($target, 'ab'))) {
|
||||
throw new HTTP_Request2_Exception("Unable to open '{$target}'");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// update() {{{
|
||||
|
||||
/**
|
||||
* Called when the request notifies us of an event.
|
||||
*
|
||||
* @param HTTP_Request2 $subject The HTTP_Request2 instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
$event = $subject->getLastEvent();
|
||||
if (!in_array($event['name'], $this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['name']) {
|
||||
case 'connect':
|
||||
$this->log('* Connected to ' . $event['data']);
|
||||
break;
|
||||
case 'sentHeaders':
|
||||
$headers = explode("\r\n", $event['data']);
|
||||
array_pop($headers);
|
||||
foreach ($headers as $header) {
|
||||
$this->log('> ' . $header);
|
||||
}
|
||||
break;
|
||||
case 'sentBodyPart':
|
||||
$this->log('> ' . $event['data'] . ' byte(s) sent');
|
||||
break;
|
||||
case 'receivedHeaders':
|
||||
$this->log(sprintf('< HTTP/%s %s %s',
|
||||
$event['data']->getVersion(),
|
||||
$event['data']->getStatus(),
|
||||
$event['data']->getReasonPhrase()));
|
||||
$headers = $event['data']->getHeader();
|
||||
foreach ($headers as $key => $val) {
|
||||
$this->log('< ' . $key . ': ' . $val);
|
||||
}
|
||||
$this->log('< ');
|
||||
break;
|
||||
case 'receivedBody':
|
||||
$this->log($event['data']->getBody());
|
||||
break;
|
||||
case 'disconnect':
|
||||
$this->log('* Disconnected');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// log() {{{
|
||||
|
||||
/**
|
||||
* Logs the given message to the configured target.
|
||||
*
|
||||
* @param string $message Message to display
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if ($this->target instanceof Log) {
|
||||
$this->target->debug($message);
|
||||
} elseif (is_resource($this->target)) {
|
||||
fwrite($this->target, $message . "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,559 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2008, 2009, 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:
|
||||
*
|
||||
* * 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
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version SVN: $Id: Response.php 290520 2009-11-11 20:09:42Z avb $
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* The class is designed to be used in "streaming" scenario, building the
|
||||
* response as it is being received:
|
||||
* <code>
|
||||
* $statusLine = read_status_line();
|
||||
* $response = new HTTP_Request2_Response($statusLine);
|
||||
* do {
|
||||
* $headerLine = read_header_line();
|
||||
* $response->parseHeaderLine($headerLine);
|
||||
* } while ($headerLine != '');
|
||||
*
|
||||
* while ($chunk = read_body()) {
|
||||
* $response->appendBody($chunk);
|
||||
* }
|
||||
*
|
||||
* var_dump($response->getHeader(), $response->getCookies(), $response->getBody());
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 0.5.2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6
|
||||
*/
|
||||
class HTTP_Request2_Response
|
||||
{
|
||||
/**
|
||||
* HTTP protocol version (e.g. 1.0, 1.1)
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
* @var integer
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
* @var string
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $reasonPhrase;
|
||||
|
||||
/**
|
||||
* Associative array of response headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Cookies set in the response
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Name of last header processed by parseHederLine()
|
||||
*
|
||||
* Used to handle the headers that span multiple lines
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastHeader = null;
|
||||
|
||||
/**
|
||||
* Response body
|
||||
* @var string
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Whether the body is still encoded by Content-Encoding
|
||||
*
|
||||
* cURL provides the decoded body to the callback; if we are reading from
|
||||
* socket the body is still gzipped / deflated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $bodyEncoded;
|
||||
|
||||
/**
|
||||
* Associative array of HTTP status code / reason phrase.
|
||||
*
|
||||
* @var array
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-10
|
||||
*/
|
||||
protected static $phrases = array(
|
||||
|
||||
// 1xx: Informational - Request received, continuing process
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
// 2xx: Success - The action was successfully received, understood and
|
||||
// accepted
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
// 3xx: Redirection - Further action must be taken in order to complete
|
||||
// the request
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found', // 1.1
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
// 4xx: Client Error - The request contains bad syntax or cannot be
|
||||
// fulfilled
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
|
||||
// 5xx: Server Error - The server failed to fulfill an apparently
|
||||
// valid request
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor, parses the response status line
|
||||
*
|
||||
* @param string Response status line (e.g. "HTTP/1.1 200 OK")
|
||||
* @param bool Whether body is still encoded by Content-Encoding
|
||||
* @throws HTTP_Request2_Exception if status line is invalid according to spec
|
||||
*/
|
||||
public function __construct($statusLine, $bodyEncoded = true)
|
||||
{
|
||||
if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) {
|
||||
throw new HTTP_Request2_Exception("Malformed response: {$statusLine}");
|
||||
}
|
||||
$this->version = $m[1];
|
||||
$this->code = intval($m[2]);
|
||||
if (!empty($m[3])) {
|
||||
$this->reasonPhrase = trim($m[3]);
|
||||
} elseif (!empty(self::$phrases[$this->code])) {
|
||||
$this->reasonPhrase = self::$phrases[$this->code];
|
||||
}
|
||||
$this->bodyEncoded = (bool)$bodyEncoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the line from HTTP response filling $headers array
|
||||
*
|
||||
* The method should be called after reading the line from socket or receiving
|
||||
* it into cURL callback. Passing an empty string here indicates the end of
|
||||
* response headers and triggers additional processing, so be sure to pass an
|
||||
* empty string in the end.
|
||||
*
|
||||
* @param string Line from HTTP response
|
||||
*/
|
||||
public function parseHeaderLine($headerLine)
|
||||
{
|
||||
$headerLine = trim($headerLine, "\r\n");
|
||||
|
||||
// empty string signals the end of headers, process the received ones
|
||||
if ('' == $headerLine) {
|
||||
if (!empty($this->headers['set-cookie'])) {
|
||||
$cookies = is_array($this->headers['set-cookie'])?
|
||||
$this->headers['set-cookie']:
|
||||
array($this->headers['set-cookie']);
|
||||
foreach ($cookies as $cookieString) {
|
||||
$this->parseCookie($cookieString);
|
||||
}
|
||||
unset($this->headers['set-cookie']);
|
||||
}
|
||||
foreach (array_keys($this->headers) as $k) {
|
||||
if (is_array($this->headers[$k])) {
|
||||
$this->headers[$k] = implode(', ', $this->headers[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// string of the form header-name: header value
|
||||
} elseif (preg_match('!^([^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+):(.+)$!', $headerLine, $m)) {
|
||||
$name = strtolower($m[1]);
|
||||
$value = trim($m[2]);
|
||||
if (empty($this->headers[$name])) {
|
||||
$this->headers[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($this->headers[$name])) {
|
||||
$this->headers[$name] = array($this->headers[$name]);
|
||||
}
|
||||
$this->headers[$name][] = $value;
|
||||
}
|
||||
$this->lastHeader = $name;
|
||||
|
||||
// continuation of a previous header
|
||||
} elseif (preg_match('!^\s+(.+)$!', $headerLine, $m) && $this->lastHeader) {
|
||||
if (!is_array($this->headers[$this->lastHeader])) {
|
||||
$this->headers[$this->lastHeader] .= ' ' . trim($m[1]);
|
||||
} else {
|
||||
$key = count($this->headers[$this->lastHeader]) - 1;
|
||||
$this->headers[$this->lastHeader][$key] .= ' ' . trim($m[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Set-Cookie header to fill $cookies array
|
||||
*
|
||||
* @param string value of Set-Cookie header
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
protected function parseCookie($cookieString)
|
||||
{
|
||||
$cookie = array(
|
||||
'expires' => null,
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
'secure' => false
|
||||
);
|
||||
|
||||
// Only a name=value pair
|
||||
if (!strpos($cookieString, ';')) {
|
||||
$pos = strpos($cookieString, '=');
|
||||
$cookie['name'] = trim(substr($cookieString, 0, $pos));
|
||||
$cookie['value'] = trim(substr($cookieString, $pos + 1));
|
||||
|
||||
// Some optional parameters are supplied
|
||||
} else {
|
||||
$elements = explode(';', $cookieString);
|
||||
$pos = strpos($elements[0], '=');
|
||||
$cookie['name'] = trim(substr($elements[0], 0, $pos));
|
||||
$cookie['value'] = trim(substr($elements[0], $pos + 1));
|
||||
|
||||
for ($i = 1; $i < count($elements); $i++) {
|
||||
if (false === strpos($elements[$i], '=')) {
|
||||
$elName = trim($elements[$i]);
|
||||
$elValue = null;
|
||||
} else {
|
||||
list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
|
||||
}
|
||||
$elName = strtolower($elName);
|
||||
if ('secure' == $elName) {
|
||||
$cookie['secure'] = true;
|
||||
} elseif ('expires' == $elName) {
|
||||
$cookie['expires'] = str_replace('"', '', $elValue);
|
||||
} elseif ('path' == $elName || 'domain' == $elName) {
|
||||
$cookie[$elName] = urldecode($elValue);
|
||||
} else {
|
||||
$cookie[$elName] = $elValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cookies[] = $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string to the response body
|
||||
* @param string
|
||||
*/
|
||||
public function appendBody($bodyChunk)
|
||||
{
|
||||
$this->body .= $bodyChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reason phrase
|
||||
* @return string
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether response is a redirect that can be automatically handled by HTTP_Request2
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return in_array($this->code, array(300, 301, 302, 303, 307))
|
||||
&& isset($this->headers['location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the named header or all response headers
|
||||
*
|
||||
* @param string Name of header to return
|
||||
* @return string|array Value of $headerName header (null if header is
|
||||
* not present), array of all response headers if
|
||||
* $headerName is null
|
||||
*/
|
||||
public function getHeader($headerName = null)
|
||||
{
|
||||
if (null === $headerName) {
|
||||
return $this->headers;
|
||||
} else {
|
||||
$headerName = strtolower($headerName);
|
||||
return isset($this->headers[$headerName])? $this->headers[$headerName]: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cookies set in response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCookies()
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the response
|
||||
*
|
||||
* @return string
|
||||
* @throws HTTP_Request2_Exception if body cannot be decoded
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (!$this->bodyEncoded ||
|
||||
!in_array(strtolower($this->getHeader('content-encoding')), array('gzip', 'deflate'))
|
||||
) {
|
||||
return $this->body;
|
||||
|
||||
} else {
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('iso-8859-1');
|
||||
}
|
||||
|
||||
try {
|
||||
switch (strtolower($this->getHeader('content-encoding'))) {
|
||||
case 'gzip':
|
||||
$decoded = self::decodeGzip($this->body);
|
||||
break;
|
||||
case 'deflate':
|
||||
$decoded = self::decodeDeflate($this->body);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP version of the response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by gzip
|
||||
*
|
||||
* The real decoding work is done by gzinflate() built-in function, this
|
||||
* method only parses the header and checks data for compliance with
|
||||
* RFC 1952
|
||||
*
|
||||
* @param string gzip-encoded data
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_Exception
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
*/
|
||||
public static function decodeGzip($data)
|
||||
{
|
||||
$length = strlen($data);
|
||||
// If it doesn't look like gzip-encoded data, don't bother
|
||||
if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
|
||||
return $data;
|
||||
}
|
||||
if (!function_exists('gzinflate')) {
|
||||
throw new HTTP_Request2_Exception('Unable to decode body: gzip extension not available');
|
||||
}
|
||||
$method = ord(substr($data, 2, 1));
|
||||
if (8 != $method) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: unknown compression method');
|
||||
}
|
||||
$flags = ord(substr($data, 3, 1));
|
||||
if ($flags & 224) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: reserved bits are set');
|
||||
}
|
||||
|
||||
// header is 10 bytes minimum. may be longer, though.
|
||||
$headerLength = 10;
|
||||
// extra fields, need to skip 'em
|
||||
if ($flags & 4) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$extraLength = unpack('v', substr($data, 10, 2));
|
||||
if ($length - $headerLength - 2 - $extraLength[1] < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $extraLength[1] + 2;
|
||||
}
|
||||
// file name, need to skip that
|
||||
if ($flags & 8) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$filenameLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $filenameLength + 1;
|
||||
}
|
||||
// comment, need to skip that also
|
||||
if ($flags & 16) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$commentLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$headerLength += $commentLength + 1;
|
||||
}
|
||||
// have a CRC for header. let's check
|
||||
if ($flags & 2) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_Exception('Error parsing gzip header: data too short');
|
||||
}
|
||||
$crcReal = 0xffff & crc32(substr($data, 0, $headerLength));
|
||||
$crcStored = unpack('v', substr($data, $headerLength, 2));
|
||||
if ($crcReal != $crcStored[1]) {
|
||||
throw new HTTP_Request2_Exception('Header CRC check failed');
|
||||
}
|
||||
$headerLength += 2;
|
||||
}
|
||||
// unpacked data CRC and size at the end of encoded data
|
||||
$tmp = unpack('V2', substr($data, -8));
|
||||
$dataCrc = $tmp[1];
|
||||
$dataSize = $tmp[2];
|
||||
|
||||
// finally, call the gzinflate() function
|
||||
// don't pass $dataSize to gzinflate, see bugs #13135, #14370
|
||||
$unpacked = gzinflate(substr($data, $headerLength, -8));
|
||||
if (false === $unpacked) {
|
||||
throw new HTTP_Request2_Exception('gzinflate() call failed');
|
||||
} elseif ($dataSize != strlen($unpacked)) {
|
||||
throw new HTTP_Request2_Exception('Data size check failed');
|
||||
} elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
|
||||
throw new HTTP_Request2_Exception('Data CRC check failed');
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by deflate
|
||||
*
|
||||
* @param string deflate-encoded data
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function decodeDeflate($data)
|
||||
{
|
||||
if (!function_exists('gzuncompress')) {
|
||||
throw new HTTP_Request2_Exception('Unable to decode body: gzip extension not available');
|
||||
}
|
||||
// RFC 2616 defines 'deflate' encoding as zlib format from RFC 1950,
|
||||
// while many applications send raw deflate stream from RFC 1951.
|
||||
// We should check for presence of zlib header and use gzuncompress() or
|
||||
// gzinflate() as needed. See bug #15305
|
||||
$header = unpack('n', substr($data, 0, 2));
|
||||
return (0 == $header[1] % 31)? gzuncompress($data): gzinflate($data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,894 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Net_URL2, a class representing a URL as per RFC 3986.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2007-2009, Peytz & Co. A/S
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
* * Neither the name of the Net_URL2 nor the names of its 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 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 Networking
|
||||
* @package Net_URL2
|
||||
* @author Christian Schmidt <schmidt@php.net>
|
||||
* @copyright 2007-2009 Peytz & Co. A/S
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: URL2.php 290036 2009-10-28 19:52:49Z schmidt $
|
||||
* @link http://www.rfc-editor.org/rfc/rfc3986.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a URL as per RFC 3986.
|
||||
*
|
||||
* @category Networking
|
||||
* @package Net_URL2
|
||||
* @author Christian Schmidt <schmidt@php.net>
|
||||
* @copyright 2007-2009 Peytz & Co. A/S
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Net_URL2
|
||||
*/
|
||||
class Net_URL2
|
||||
{
|
||||
/**
|
||||
* Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
|
||||
* is true.
|
||||
*/
|
||||
const OPTION_STRICT = 'strict';
|
||||
|
||||
/**
|
||||
* Represent arrays in query using PHP's [] notation. Default is true.
|
||||
*/
|
||||
const OPTION_USE_BRACKETS = 'use_brackets';
|
||||
|
||||
/**
|
||||
* URL-encode query variable keys. Default is true.
|
||||
*/
|
||||
const OPTION_ENCODE_KEYS = 'encode_keys';
|
||||
|
||||
/**
|
||||
* Query variable separators when parsing the query string. Every character
|
||||
* is considered a separator. Default is "&".
|
||||
*/
|
||||
const OPTION_SEPARATOR_INPUT = 'input_separator';
|
||||
|
||||
/**
|
||||
* Query variable separator used when generating the query string. Default
|
||||
* is "&".
|
||||
*/
|
||||
const OPTION_SEPARATOR_OUTPUT = 'output_separator';
|
||||
|
||||
/**
|
||||
* Default options corresponds to how PHP handles $_GET.
|
||||
*/
|
||||
private $_options = array(
|
||||
self::OPTION_STRICT => true,
|
||||
self::OPTION_USE_BRACKETS => true,
|
||||
self::OPTION_ENCODE_KEYS => true,
|
||||
self::OPTION_SEPARATOR_INPUT => '&',
|
||||
self::OPTION_SEPARATOR_OUTPUT => '&',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_scheme = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_userinfo = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_host = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_port = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_path = '';
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_query = false;
|
||||
|
||||
/**
|
||||
* @var string|bool
|
||||
*/
|
||||
private $_fragment = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $url an absolute or relative URL
|
||||
* @param array $options an array of OPTION_xxx constants
|
||||
*/
|
||||
public function __construct($url, array $options = array())
|
||||
{
|
||||
foreach ($options as $optionName => $value) {
|
||||
if (array_key_exists($optionName, $this->_options)) {
|
||||
$this->_options[$optionName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// The regular expression is copied verbatim from RFC 3986, appendix B.
|
||||
// The expression does not validate the URL but matches any string.
|
||||
preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!',
|
||||
$url,
|
||||
$matches);
|
||||
|
||||
// "path" is always present (possibly as an empty string); the rest
|
||||
// are optional.
|
||||
$this->_scheme = !empty($matches[1]) ? $matches[2] : false;
|
||||
$this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
|
||||
$this->_path = $matches[5];
|
||||
$this->_query = !empty($matches[6]) ? $matches[7] : false;
|
||||
$this->_fragment = !empty($matches[8]) ? $matches[9] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Setter.
|
||||
*
|
||||
* This method will magically set the value of a private variable ($var)
|
||||
* with the value passed as the args
|
||||
*
|
||||
* @param string $var The private variable to set.
|
||||
* @param mixed $arg An argument of any type.
|
||||
* @return void
|
||||
*/
|
||||
public function __set($var, $arg)
|
||||
{
|
||||
$method = 'set' . $var;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Getter.
|
||||
*
|
||||
* This is the magic get method to retrieve the private variable
|
||||
* that was set by either __set() or it's setter...
|
||||
*
|
||||
* @param string $var The property name to retrieve.
|
||||
* @return mixed $this->$var Either a boolean false if the
|
||||
* property is not set or the value
|
||||
* of the private property.
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
$method = 'get' . $var;
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scheme, e.g. "http" or "urn", or false if there is no
|
||||
* scheme specified, i.e. if this is a relative URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scheme, e.g. "http" or "urn". Specify false if there is no
|
||||
* scheme specified, i.e. if this is a relative URL.
|
||||
*
|
||||
* @param string|bool $scheme e.g. "http" or "urn", or false if there is no
|
||||
* scheme specified, i.e. if this is a relative
|
||||
* URL
|
||||
*
|
||||
* @return void
|
||||
* @see getScheme()
|
||||
*/
|
||||
public function setScheme($scheme)
|
||||
{
|
||||
$this->_scheme = $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user part of the userinfo part (the part preceding the first
|
||||
* ":"), or false if there is no userinfo part.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->_userinfo !== false
|
||||
? preg_replace('@:.*$@', '', $this->_userinfo)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password part of the userinfo part (the part after the first
|
||||
* ":"), or false if there is no userinfo part (i.e. the URL does not
|
||||
* contain "@" in front of the hostname) or the userinfo part does not
|
||||
* contain ":".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_userinfo !== false
|
||||
? substr(strstr($this->_userinfo, ':'), 1)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the userinfo part, or false if there is none, i.e. if the
|
||||
* authority part does not contain "@".
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getUserinfo()
|
||||
{
|
||||
return $this->_userinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the userinfo part. If two arguments are passed, they are combined
|
||||
* in the userinfo part as username ":" password.
|
||||
*
|
||||
* @param string|bool $userinfo userinfo or username
|
||||
* @param string|bool $password optional password, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUserinfo($userinfo, $password = false)
|
||||
{
|
||||
$this->_userinfo = $userinfo;
|
||||
if ($password !== false) {
|
||||
$this->_userinfo .= ':' . $password;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host part, or false if there is no authority part, e.g.
|
||||
* relative URLs.
|
||||
*
|
||||
* @return string|bool a hostname, an IP address, or false
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host part. Specify false if there is no authority part, e.g.
|
||||
* relative URLs.
|
||||
*
|
||||
* @param string|bool $host a hostname, an IP address, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->_host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number, or false if there is no port number specified,
|
||||
* i.e. if the default port is to be used.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->_port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port number. Specify false if there is no port number specified,
|
||||
* i.e. if the default port is to be used.
|
||||
*
|
||||
* @param string|bool $port a port number, or false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->_port = $port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
|
||||
* false if there is no authority.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getAuthority()
|
||||
{
|
||||
if (!$this->_host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$authority = '';
|
||||
|
||||
if ($this->_userinfo !== false) {
|
||||
$authority .= $this->_userinfo . '@';
|
||||
}
|
||||
|
||||
$authority .= $this->_host;
|
||||
|
||||
if ($this->_port !== false) {
|
||||
$authority .= ':' . $this->_port;
|
||||
}
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
|
||||
* false if there is no authority.
|
||||
*
|
||||
* @param string|false $authority a hostname or an IP addresse, possibly
|
||||
* with userinfo prefixed and port number
|
||||
* appended, e.g. "foo:bar@example.org:81".
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAuthority($authority)
|
||||
{
|
||||
$this->_userinfo = false;
|
||||
$this->_host = false;
|
||||
$this->_port = false;
|
||||
if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
|
||||
if ($reg[1]) {
|
||||
$this->_userinfo = $reg[2];
|
||||
}
|
||||
|
||||
$this->_host = $reg[3];
|
||||
if (isset($reg[5])) {
|
||||
$this->_port = $reg[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path part (possibly an empty string).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path part (possibly an empty string).
|
||||
*
|
||||
* @param string $path a path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string (excluding the leading "?"), or false if "?"
|
||||
* is not present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
* @see self::getQueryVariables()
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query string (excluding the leading "?"). Specify false if "?"
|
||||
* is not present in the URL.
|
||||
*
|
||||
* @param string|bool $query a query string, e.g. "foo=1&bar=2"
|
||||
*
|
||||
* @return void
|
||||
* @see self::setQueryVariables()
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->_query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fragment name, or false if "#" is not present in the URL.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getFragment()
|
||||
{
|
||||
return $this->_fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the fragment name. Specify false if "#" is not present in the URL.
|
||||
*
|
||||
* @param string|bool $fragment a fragment excluding the leading "#", or
|
||||
* false
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFragment($fragment)
|
||||
{
|
||||
$this->_fragment = $fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string like an array as the variables would appear in
|
||||
* $_GET in a PHP script. If the URL does not contain a "?", an empty array
|
||||
* is returned.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryVariables()
|
||||
{
|
||||
$pattern = '/[' .
|
||||
preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
|
||||
']/';
|
||||
$parts = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$return = array();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
list($key, $value) = explode('=', $part, 2);
|
||||
} else {
|
||||
$key = $part;
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$key = rawurldecode($key);
|
||||
}
|
||||
$value = rawurldecode($value);
|
||||
|
||||
if ($this->getOption(self::OPTION_USE_BRACKETS) &&
|
||||
preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
|
||||
|
||||
$key = $matches[1];
|
||||
$idx = $matches[2];
|
||||
|
||||
// Ensure is an array
|
||||
if (empty($return[$key]) || !is_array($return[$key])) {
|
||||
$return[$key] = array();
|
||||
}
|
||||
|
||||
// Add data
|
||||
if ($idx === '') {
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key][$idx] = $value;
|
||||
}
|
||||
} elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
|
||||
&& !empty($return[$key])
|
||||
) {
|
||||
$return[$key] = (array) $return[$key];
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query string to the specified variable in the query string.
|
||||
*
|
||||
* @param array $array (name => value) array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setQueryVariables(array $array)
|
||||
{
|
||||
if (!$array) {
|
||||
$this->_query = false;
|
||||
} else {
|
||||
foreach ($array as $name => $value) {
|
||||
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
|
||||
$name = self::urlencode($name);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
|
||||
? sprintf('%s[%s]=%s', $name, $k, $v)
|
||||
: ($name . '=' . $v);
|
||||
}
|
||||
} elseif (!is_null($value)) {
|
||||
$parts[] = $name . '=' . self::urlencode($value);
|
||||
} else {
|
||||
$parts[] = $name;
|
||||
}
|
||||
}
|
||||
$this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
|
||||
$parts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified variable in the query string.
|
||||
*
|
||||
* @param string $name variable name
|
||||
* @param mixed $value variable value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setQueryVariable($name, $value)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
$array[$name] = $value;
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specifed variable from the query string.
|
||||
*
|
||||
* @param string $name a query string variable, e.g. "foo" in "?foo=1"
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetQueryVariable($name)
|
||||
{
|
||||
$array = $this->getQueryVariables();
|
||||
unset($array[$name]);
|
||||
$this->setQueryVariables($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getURL()
|
||||
{
|
||||
// See RFC 3986, section 5.3
|
||||
$url = "";
|
||||
|
||||
if ($this->_scheme !== false) {
|
||||
$url .= $this->_scheme . ':';
|
||||
}
|
||||
|
||||
$authority = $this->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$url .= '//' . $authority;
|
||||
}
|
||||
$url .= $this->_path;
|
||||
|
||||
if ($this->_query !== false) {
|
||||
$url .= '?' . $this->_query;
|
||||
}
|
||||
|
||||
if ($this->_fragment !== false) {
|
||||
$url .= '#' . $this->_fragment;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this URL.
|
||||
*
|
||||
* @return string
|
||||
* @see toString()
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized string representation of this URL. This is useful
|
||||
* for comparison of URLs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNormalizedURL()
|
||||
{
|
||||
$url = clone $this;
|
||||
$url->normalize();
|
||||
return $url->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized Net_URL2 instance.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function normalize()
|
||||
{
|
||||
// See RFC 3886, section 6
|
||||
|
||||
// Schemes are case-insensitive
|
||||
if ($this->_scheme) {
|
||||
$this->_scheme = strtolower($this->_scheme);
|
||||
}
|
||||
|
||||
// Hostnames are case-insensitive
|
||||
if ($this->_host) {
|
||||
$this->_host = strtolower($this->_host);
|
||||
}
|
||||
|
||||
// Remove default port number for known schemes (RFC 3986, section 6.2.3)
|
||||
if ($this->_port &&
|
||||
$this->_scheme &&
|
||||
$this->_port == getservbyname($this->_scheme, 'tcp')) {
|
||||
|
||||
$this->_port = false;
|
||||
}
|
||||
|
||||
// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
|
||||
foreach (array('_userinfo', '_host', '_path') as $part) {
|
||||
if ($this->$part) {
|
||||
$this->$part = preg_replace('/%[0-9a-f]{2}/ie',
|
||||
'strtoupper("\0")',
|
||||
$this->$part);
|
||||
}
|
||||
}
|
||||
|
||||
// Path segment normalization (RFC 3986, section 6.2.2.3)
|
||||
$this->_path = self::removeDotSegments($this->_path);
|
||||
|
||||
// Scheme based normalization (RFC 3986, section 6.2.3)
|
||||
if ($this->_host && !$this->_path) {
|
||||
$this->_path = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this instance represents an absolute URL.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAbsolute()
|
||||
{
|
||||
return (bool) $this->_scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Net_URL2 instance representing an absolute URL relative to
|
||||
* this URL.
|
||||
*
|
||||
* @param Net_URL2|string $reference relative URL
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public function resolve($reference)
|
||||
{
|
||||
if (!$reference instanceof Net_URL2) {
|
||||
$reference = new self($reference);
|
||||
}
|
||||
if (!$this->isAbsolute()) {
|
||||
throw new Exception('Base-URL must be absolute');
|
||||
}
|
||||
|
||||
// A non-strict parser may ignore a scheme in the reference if it is
|
||||
// identical to the base URI's scheme.
|
||||
if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) {
|
||||
$reference->_scheme = false;
|
||||
}
|
||||
|
||||
$target = new self('');
|
||||
if ($reference->_scheme !== false) {
|
||||
$target->_scheme = $reference->_scheme;
|
||||
$target->setAuthority($reference->getAuthority());
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
$authority = $reference->getAuthority();
|
||||
if ($authority !== false) {
|
||||
$target->setAuthority($authority);
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
if ($reference->_path == '') {
|
||||
$target->_path = $this->_path;
|
||||
if ($reference->_query !== false) {
|
||||
$target->_query = $reference->_query;
|
||||
} else {
|
||||
$target->_query = $this->_query;
|
||||
}
|
||||
} else {
|
||||
if (substr($reference->_path, 0, 1) == '/') {
|
||||
$target->_path = self::removeDotSegments($reference->_path);
|
||||
} else {
|
||||
// Merge paths (RFC 3986, section 5.2.3)
|
||||
if ($this->_host !== false && $this->_path == '') {
|
||||
$target->_path = '/' . $this->_path;
|
||||
} else {
|
||||
$i = strrpos($this->_path, '/');
|
||||
if ($i !== false) {
|
||||
$target->_path = substr($this->_path, 0, $i + 1);
|
||||
}
|
||||
$target->_path .= $reference->_path;
|
||||
}
|
||||
$target->_path = self::removeDotSegments($target->_path);
|
||||
}
|
||||
$target->_query = $reference->_query;
|
||||
}
|
||||
$target->setAuthority($this->getAuthority());
|
||||
}
|
||||
$target->_scheme = $this->_scheme;
|
||||
}
|
||||
|
||||
$target->_fragment = $reference->_fragment;
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes dots as described in RFC 3986, section 5.2.4, e.g.
|
||||
* "/foo/../bar/baz" => "/bar/baz"
|
||||
*
|
||||
* @param string $path a path
|
||||
*
|
||||
* @return string a path
|
||||
*/
|
||||
public static function removeDotSegments($path)
|
||||
{
|
||||
$output = '';
|
||||
|
||||
// Make sure not to be trapped in an infinite loop due to a bug in this
|
||||
// method
|
||||
$j = 0;
|
||||
while ($path && $j++ < 100) {
|
||||
if (substr($path, 0, 2) == './') {
|
||||
// Step 2.A
|
||||
$path = substr($path, 2);
|
||||
} elseif (substr($path, 0, 3) == '../') {
|
||||
// Step 2.A
|
||||
$path = substr($path, 3);
|
||||
} elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
|
||||
// Step 2.B
|
||||
$path = '/' . substr($path, 3);
|
||||
} elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
|
||||
// Step 2.C
|
||||
$path = '/' . substr($path, 4);
|
||||
$i = strrpos($output, '/');
|
||||
$output = $i === false ? '' : substr($output, 0, $i);
|
||||
} elseif ($path == '.' || $path == '..') {
|
||||
// Step 2.D
|
||||
$path = '';
|
||||
} else {
|
||||
// Step 2.E
|
||||
$i = strpos($path, '/');
|
||||
if ($i === 0) {
|
||||
$i = strpos($path, '/', 1);
|
||||
}
|
||||
if ($i === false) {
|
||||
$i = strlen($path);
|
||||
}
|
||||
$output .= substr($path, 0, $i);
|
||||
$path = substr($path, $i);
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percent-encodes all non-alphanumeric characters except these: _ . - ~
|
||||
* Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
|
||||
* 5.2.x and earlier.
|
||||
*
|
||||
* @param $raw the string to encode
|
||||
* @return string
|
||||
*/
|
||||
public static function urlencode($string)
|
||||
{
|
||||
$encoded = rawurlencode($string);
|
||||
// This is only necessary in PHP < 5.3.
|
||||
$encoded = str_replace('%7E', '~', $encoded);
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the canonical URL of the
|
||||
* currently executing PHP script.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCanonical()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['PHP_SELF']);
|
||||
$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
$url->_host = $_SERVER['SERVER_NAME'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
if ($url->_scheme == 'http' && $port != 80 ||
|
||||
$url->_scheme == 'https' && $port != 443) {
|
||||
|
||||
$url->_port = $port;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL used to retrieve the current request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRequestedURL()
|
||||
{
|
||||
return self::getRequested()->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Net_URL2 instance representing the URL used to retrieve the
|
||||
* current request.
|
||||
*
|
||||
* @return Net_URL2
|
||||
*/
|
||||
public static function getRequested()
|
||||
{
|
||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||
// ALERT - no current URL
|
||||
throw new Exception('Script was not called through a webserver');
|
||||
}
|
||||
|
||||
// Begin with a relative URL
|
||||
$url = new self($_SERVER['REQUEST_URI']);
|
||||
$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
// Set host and possibly port
|
||||
$url->setAuthority($_SERVER['HTTP_HOST']);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified option.
|
||||
*
|
||||
* @param string $optionName The name of the option to retrieve
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getOption($optionName)
|
||||
{
|
||||
return isset($this->_options[$optionName])
|
||||
? $this->_options[$optionName] : false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,391 +0,0 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
|
||||
/**
|
||||
* PEAR_Exception
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V. V. Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Exception.php 276383 2009-02-24 23:39:37Z dufuz $
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since File available since Release 1.3.3
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Base PEAR_Exception Class
|
||||
*
|
||||
* 1) Features:
|
||||
*
|
||||
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
|
||||
* - Definable triggers, shot when exceptions occur
|
||||
* - Pretty and informative error messages
|
||||
* - Added more context info available (like class, method or cause)
|
||||
* - cause can be a PEAR_Exception or an array of mixed
|
||||
* PEAR_Exceptions/PEAR_ErrorStack warnings
|
||||
* - callbacks for specific exception classes and their children
|
||||
*
|
||||
* 2) Ideas:
|
||||
*
|
||||
* - Maybe a way to define a 'template' for the output
|
||||
*
|
||||
* 3) Inherited properties from PHP Exception Class:
|
||||
*
|
||||
* protected $message
|
||||
* protected $code
|
||||
* protected $line
|
||||
* protected $file
|
||||
* private $trace
|
||||
*
|
||||
* 4) Inherited methods from PHP Exception Class:
|
||||
*
|
||||
* __clone
|
||||
* __construct
|
||||
* getMessage
|
||||
* getCode
|
||||
* getFile
|
||||
* getLine
|
||||
* getTraceSafe
|
||||
* getTraceSafeAsString
|
||||
* __toString
|
||||
*
|
||||
* 5) Usage example
|
||||
*
|
||||
* <code>
|
||||
* require_once 'PEAR/Exception.php';
|
||||
*
|
||||
* class Test {
|
||||
* function foo() {
|
||||
* throw new PEAR_Exception('Error Message', ERROR_CODE);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* function myLogger($pear_exception) {
|
||||
* echo $pear_exception->getMessage();
|
||||
* }
|
||||
* // each time a exception is thrown the 'myLogger' will be called
|
||||
* // (its use is completely optional)
|
||||
* PEAR_Exception::addObserver('myLogger');
|
||||
* $test = new Test;
|
||||
* try {
|
||||
* $test->foo();
|
||||
* } catch (PEAR_Exception $e) {
|
||||
* print $e;
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @category pear
|
||||
* @package PEAR
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
* @author Hans Lellelid <hans@velum.net>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @copyright 1997-2009 The Authors
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version Release: 1.9.0
|
||||
* @link http://pear.php.net/package/PEAR
|
||||
* @since Class available since Release 1.3.3
|
||||
*
|
||||
*/
|
||||
class PEAR_Exception extends Exception
|
||||
{
|
||||
const OBSERVER_PRINT = -2;
|
||||
const OBSERVER_TRIGGER = -4;
|
||||
const OBSERVER_DIE = -8;
|
||||
protected $cause;
|
||||
private static $_observers = array();
|
||||
private static $_uniqueid = 0;
|
||||
private $_trace;
|
||||
|
||||
/**
|
||||
* Supported signatures:
|
||||
* - PEAR_Exception(string $message);
|
||||
* - PEAR_Exception(string $message, int $code);
|
||||
* - PEAR_Exception(string $message, Exception $cause);
|
||||
* - PEAR_Exception(string $message, Exception $cause, int $code);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause);
|
||||
* - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
|
||||
* - PEAR_Exception(string $message, array $causes);
|
||||
* - PEAR_Exception(string $message, array $causes, int $code);
|
||||
* @param string exception message
|
||||
* @param int|Exception|PEAR_Error|array|null exception cause
|
||||
* @param int|null exception code or null
|
||||
*/
|
||||
public function __construct($message, $p2 = null, $p3 = null)
|
||||
{
|
||||
if (is_int($p2)) {
|
||||
$code = $p2;
|
||||
$this->cause = null;
|
||||
} elseif (is_object($p2) || is_array($p2)) {
|
||||
// using is_object allows both Exception and PEAR_Error
|
||||
if (is_object($p2) && !($p2 instanceof Exception)) {
|
||||
if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
|
||||
throw new PEAR_Exception('exception cause must be Exception, ' .
|
||||
'array, or PEAR_Error');
|
||||
}
|
||||
}
|
||||
$code = $p3;
|
||||
if (is_array($p2) && isset($p2['message'])) {
|
||||
// fix potential problem of passing in a single warning
|
||||
$p2 = array($p2);
|
||||
}
|
||||
$this->cause = $p2;
|
||||
} else {
|
||||
$code = null;
|
||||
$this->cause = null;
|
||||
}
|
||||
parent::__construct($message, $code);
|
||||
$this->signal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $callback - A valid php callback, see php func is_callable()
|
||||
* - A PEAR_Exception::OBSERVER_* constant
|
||||
* - An array(const PEAR_Exception::OBSERVER_*,
|
||||
* mixed $options)
|
||||
* @param string $label The name of the observer. Use this if you want
|
||||
* to remove it later with removeObserver()
|
||||
*/
|
||||
public static function addObserver($callback, $label = 'default')
|
||||
{
|
||||
self::$_observers[$label] = $callback;
|
||||
}
|
||||
|
||||
public static function removeObserver($label = 'default')
|
||||
{
|
||||
unset(self::$_observers[$label]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int unique identifier for an observer
|
||||
*/
|
||||
public static function getUniqueId()
|
||||
{
|
||||
return self::$_uniqueid++;
|
||||
}
|
||||
|
||||
private function signal()
|
||||
{
|
||||
foreach (self::$_observers as $func) {
|
||||
if (is_callable($func)) {
|
||||
call_user_func($func, $this);
|
||||
continue;
|
||||
}
|
||||
settype($func, 'array');
|
||||
switch ($func[0]) {
|
||||
case self::OBSERVER_PRINT :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
printf($f, $this->getMessage());
|
||||
break;
|
||||
case self::OBSERVER_TRIGGER :
|
||||
$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
|
||||
trigger_error($this->getMessage(), $f);
|
||||
break;
|
||||
case self::OBSERVER_DIE :
|
||||
$f = (isset($func[1])) ? $func[1] : '%s';
|
||||
die(printf($f, $this->getMessage()));
|
||||
break;
|
||||
default:
|
||||
trigger_error('invalid observer type', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return specific error information that can be used for more detailed
|
||||
* error messages or translation.
|
||||
*
|
||||
* This method may be overridden in child exception classes in order
|
||||
* to add functionality not present in PEAR_Exception and is a placeholder
|
||||
* to define API
|
||||
*
|
||||
* The returned array must be an associative array of parameter => value like so:
|
||||
* <pre>
|
||||
* array('name' => $name, 'context' => array(...))
|
||||
* </pre>
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorData()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception that caused this exception to be thrown
|
||||
* @access public
|
||||
* @return Exception|array The context of the exception
|
||||
*/
|
||||
public function getCause()
|
||||
{
|
||||
return $this->cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function must be public to call on caused exceptions
|
||||
* @param array
|
||||
*/
|
||||
public function getCauseMessage(&$causes)
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$cause = array('class' => get_class($this),
|
||||
'message' => $this->message,
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
if (isset($trace[0])) {
|
||||
if (isset($trace[0]['file'])) {
|
||||
$cause['file'] = $trace[0]['file'];
|
||||
$cause['line'] = $trace[0]['line'];
|
||||
}
|
||||
}
|
||||
$causes[] = $cause;
|
||||
if ($this->cause instanceof PEAR_Exception) {
|
||||
$this->cause->getCauseMessage($causes);
|
||||
} elseif ($this->cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => $this->cause->getFile(),
|
||||
'line' => $this->cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($this->cause),
|
||||
'message' => $this->cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($this->cause)) {
|
||||
foreach ($this->cause as $cause) {
|
||||
if ($cause instanceof PEAR_Exception) {
|
||||
$cause->getCauseMessage($causes);
|
||||
} elseif ($cause instanceof Exception) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => $cause->getFile(),
|
||||
'line' => $cause->getLine());
|
||||
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
|
||||
$causes[] = array('class' => get_class($cause),
|
||||
'message' => $cause->getMessage(),
|
||||
'file' => 'unknown',
|
||||
'line' => 'unknown');
|
||||
} elseif (is_array($cause) && isset($cause['message'])) {
|
||||
// PEAR_ErrorStack warning
|
||||
$causes[] = array(
|
||||
'class' => $cause['package'],
|
||||
'message' => $cause['message'],
|
||||
'file' => isset($cause['context']['file']) ?
|
||||
$cause['context']['file'] :
|
||||
'unknown',
|
||||
'line' => isset($cause['context']['line']) ?
|
||||
$cause['context']['line'] :
|
||||
'unknown',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTraceSafe()
|
||||
{
|
||||
if (!isset($this->_trace)) {
|
||||
$this->_trace = $this->getTrace();
|
||||
if (empty($this->_trace)) {
|
||||
$backtrace = debug_backtrace();
|
||||
$this->_trace = array($backtrace[count($backtrace)-1]);
|
||||
}
|
||||
}
|
||||
return $this->_trace;
|
||||
}
|
||||
|
||||
public function getErrorClass()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['class'];
|
||||
}
|
||||
|
||||
public function getErrorMethod()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
return $trace[0]['function'];
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
return $this->toHtml();
|
||||
}
|
||||
return $this->toText();
|
||||
}
|
||||
|
||||
public function toHtml()
|
||||
{
|
||||
$trace = $this->getTraceSafe();
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$html = '<table border="1" cellspacing="0">' . "\n";
|
||||
foreach ($causes as $i => $cause) {
|
||||
$html .= '<tr><td colspan="3" bgcolor="#ff9999">'
|
||||
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
|
||||
. htmlspecialchars($cause['message'], ENT_COMPAT | ENT_HTML401, 'UTF-8', false) . ' in <b>' . $cause['file'] . '</b> '
|
||||
. 'on line <b>' . $cause['line'] . '</b>'
|
||||
. "</td></tr>\n";
|
||||
}
|
||||
$html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
|
||||
. '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
|
||||
. '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
|
||||
. '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
|
||||
|
||||
foreach ($trace as $k => $v) {
|
||||
$html .= '<tr><td align="center">' . $k . '</td>'
|
||||
. '<td>';
|
||||
if (!empty($v['class'])) {
|
||||
$html .= $v['class'] . $v['type'];
|
||||
}
|
||||
$html .= $v['function'];
|
||||
$args = array();
|
||||
if (!empty($v['args'])) {
|
||||
foreach ($v['args'] as $arg) {
|
||||
if (is_null($arg)) $args[] = 'null';
|
||||
elseif (is_array($arg)) $args[] = 'Array';
|
||||
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
|
||||
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
|
||||
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
|
||||
else {
|
||||
$arg = (string)$arg;
|
||||
$str = htmlspecialchars(substr($arg, 0, 16), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
if (strlen($arg) > 16) $str .= '…';
|
||||
$args[] = "'" . $str . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= '(' . implode(', ',$args) . ')'
|
||||
. '</td>'
|
||||
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
|
||||
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
|
||||
. '</td></tr>' . "\n";
|
||||
}
|
||||
$html .= '<tr><td align="center">' . ($k+1) . '</td>'
|
||||
. '<td>{main}</td>'
|
||||
. '<td> </td></tr>' . "\n"
|
||||
. '</table>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function toText()
|
||||
{
|
||||
$causes = array();
|
||||
$this->getCauseMessage($causes);
|
||||
$causeMsg = '';
|
||||
foreach ($causes as $i => $cause) {
|
||||
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
|
||||
. $cause['message'] . ' in ' . $cause['file']
|
||||
. ' on line ' . $cause['line'] . "\n";
|
||||
}
|
||||
return $causeMsg . $this->getTraceAsString();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This is only meant for PHP 5 to get rid of certain strict warning
|
||||
* that doesn't get hidden since it's in the shutdown function
|
||||
*/
|
||||
class PEAR5
|
||||
{
|
||||
/**
|
||||
* If you have a class that's mostly/entirely static, and you need static
|
||||
* properties, you can use this method to simulate them. Eg. in your method(s)
|
||||
* do this: $myVar = &PEAR5::getStaticProperty('myclass', 'myVar');
|
||||
* You MUST use a reference, or they will not persist!
|
||||
*
|
||||
* @access public
|
||||
* @param string $class The calling classname, to prevent clashes
|
||||
* @param string $var The variable to retrieve.
|
||||
* @return mixed A reference to the variable. If not set it will be
|
||||
* auto initialised to NULL.
|
||||
*/
|
||||
static function &getStaticProperty($class, $var)
|
||||
{
|
||||
static $properties;
|
||||
if (!isset($properties[$class])) {
|
||||
$properties[$class] = array();
|
||||
}
|
||||
|
||||
if (!array_key_exists($var, $properties[$class])) {
|
||||
$properties[$class][$var] = null;
|
||||
}
|
||||
|
||||
return $properties[$class][$var];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Listener for HTTP_Request and HTTP_Response objects
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2002-2007, Richard Heyes
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* o 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.
|
||||
* o 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
|
||||
* @package HTTP_Request
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2002-2007 Richard Heyes
|
||||
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
||||
* @version CVS: $Id: Listener.php,v 1.3 2007/05/18 10:33:31 avb Exp $
|
||||
* @link http://pear.php.net/package/HTTP_Request/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Listener for HTTP_Request and HTTP_Response objects
|
||||
*
|
||||
* This class implements the Observer part of a Subject-Observer
|
||||
* design pattern.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version Release: 1.4.1
|
||||
*/
|
||||
class HTTP_Request_Listener
|
||||
{
|
||||
/**
|
||||
* A listener's identifier
|
||||
* @var string
|
||||
*/
|
||||
var $_id;
|
||||
|
||||
/**
|
||||
* Constructor, sets the object's identifier
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function HTTP_Request_Listener()
|
||||
{
|
||||
$this->_id = md5(uniqid('http_request_', 1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the listener's identifier
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when Listener is notified of an event
|
||||
*
|
||||
* @access public
|
||||
* @param object an object the listener is attached to
|
||||
* @param string Event name
|
||||
* @param mixed Additional data
|
||||
* @abstract
|
||||
*/
|
||||
function update(&$subject, $event, $data = null)
|
||||
{
|
||||
echo "Notified of event: '$event'\n";
|
||||
if (null !== $data) {
|
||||
echo "Additional data: ";
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,528 +0,0 @@
|
|||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Stig Bakken <ssb@php.net> |
|
||||
// | Chuck Hagenbuch <chuck@horde.org> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Socket.php,v 1.24 2005/02/03 20:40:16 chagenbu Exp $
|
||||
|
||||
require_once 'PEAR.php';
|
||||
|
||||
define('NET_SOCKET_READ', 1);
|
||||
define('NET_SOCKET_WRITE', 2);
|
||||
define('NET_SOCKET_ERROR', 3);
|
||||
|
||||
/**
|
||||
* Generalized Socket class.
|
||||
*
|
||||
* @version 1.1
|
||||
* @author Stig Bakken <ssb@php.net>
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
*/
|
||||
class Net_Socket extends PEAR {
|
||||
|
||||
/**
|
||||
* Socket file pointer.
|
||||
* @var resource $fp
|
||||
*/
|
||||
var $fp = null;
|
||||
|
||||
/**
|
||||
* Whether the socket is blocking. Defaults to true.
|
||||
* @var boolean $blocking
|
||||
*/
|
||||
var $blocking = true;
|
||||
|
||||
/**
|
||||
* Whether the socket is persistent. Defaults to false.
|
||||
* @var boolean $persistent
|
||||
*/
|
||||
var $persistent = false;
|
||||
|
||||
/**
|
||||
* The IP address to connect to.
|
||||
* @var string $addr
|
||||
*/
|
||||
var $addr = '';
|
||||
|
||||
/**
|
||||
* The port number to connect to.
|
||||
* @var integer $port
|
||||
*/
|
||||
var $port = 0;
|
||||
|
||||
/**
|
||||
* Number of seconds to wait on socket connections before assuming
|
||||
* there's no more data. Defaults to no timeout.
|
||||
* @var integer $timeout
|
||||
*/
|
||||
var $timeout = false;
|
||||
|
||||
/**
|
||||
* Number of bytes to read at a time in readLine() and
|
||||
* readAll(). Defaults to 2048.
|
||||
* @var integer $lineLength
|
||||
*/
|
||||
var $lineLength = 2048;
|
||||
|
||||
/**
|
||||
* Connect to the specified port. If called when the socket is
|
||||
* already connected, it disconnects and connects again.
|
||||
*
|
||||
* @param string $addr IP address or host name.
|
||||
* @param integer $port TCP port number.
|
||||
* @param boolean $persistent (optional) Whether the connection is
|
||||
* persistent (kept open between requests
|
||||
* by the web server).
|
||||
* @param integer $timeout (optional) How long to wait for data.
|
||||
* @param array $options See options for stream_context_create.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return boolean | PEAR_Error True on success or a PEAR_Error on failure.
|
||||
*/
|
||||
function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null)
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
@fclose($this->fp);
|
||||
$this->fp = null;
|
||||
}
|
||||
|
||||
if (!$addr) {
|
||||
return $this->raiseError('$addr cannot be empty');
|
||||
} elseif (strspn($addr, '.0123456789') == strlen($addr) ||
|
||||
strstr($addr, '/') !== false) {
|
||||
$this->addr = $addr;
|
||||
} else {
|
||||
$this->addr = @gethostbyname($addr);
|
||||
}
|
||||
|
||||
$this->port = $port % 65536;
|
||||
|
||||
if ($persistent !== null) {
|
||||
$this->persistent = $persistent;
|
||||
}
|
||||
|
||||
if ($timeout !== null) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
$openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen';
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
if ($options && function_exists('stream_context_create')) {
|
||||
if ($this->timeout) {
|
||||
$timeout = $this->timeout;
|
||||
} else {
|
||||
$timeout = 0;
|
||||
}
|
||||
$context = stream_context_create($options);
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context);
|
||||
} else {
|
||||
if ($this->timeout) {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout);
|
||||
} else {
|
||||
$fp = @$openfunc($this->addr, $this->port, $errno, $errstr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fp) {
|
||||
return $this->raiseError($errstr, $errno);
|
||||
}
|
||||
|
||||
$this->fp = $fp;
|
||||
|
||||
return $this->setBlocking($this->blocking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from the peer, closes the socket.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function disconnect()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
@fclose($this->fp);
|
||||
$this->fp = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the socket is in blocking mode.
|
||||
*
|
||||
* @access public
|
||||
* @return boolean The current blocking mode.
|
||||
*/
|
||||
function isBlocking()
|
||||
{
|
||||
return $this->blocking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the socket connection should be blocking or
|
||||
* not. A read call to a non-blocking socket will return immediately
|
||||
* if there is no data available, whereas it will block until there
|
||||
* is data for blocking sockets.
|
||||
*
|
||||
* @param boolean $mode True for blocking sockets, false for nonblocking.
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setBlocking($mode)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$this->blocking = $mode;
|
||||
socket_set_blocking($this->fp, $this->blocking);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout value on socket descriptor,
|
||||
* expressed in the sum of seconds and microseconds
|
||||
*
|
||||
* @param integer $seconds Seconds.
|
||||
* @param integer $microseconds Microseconds.
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function setTimeout($seconds, $microseconds)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return socket_set_timeout($this->fp, $seconds, $microseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about an existing socket resource.
|
||||
* Currently returns four entries in the result array:
|
||||
*
|
||||
* <p>
|
||||
* timed_out (bool) - The socket timed out waiting for data<br>
|
||||
* blocked (bool) - The socket was blocked<br>
|
||||
* eof (bool) - Indicates EOF event<br>
|
||||
* unread_bytes (int) - Number of bytes left in the socket buffer<br>
|
||||
* </p>
|
||||
*
|
||||
* @access public
|
||||
* @return mixed Array containing information about existing socket resource or an error object otherwise
|
||||
*/
|
||||
function getStatus()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return socket_get_status($this->fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specified line of data
|
||||
*
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function gets($size)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return @fgets($this->fp, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a specified amount of data. This is guaranteed to return,
|
||||
* and has the added benefit of getting everything in one fread()
|
||||
* chunk; if you know the size of the data you're getting
|
||||
* beforehand, this is definitely the way to go.
|
||||
*
|
||||
* @param integer $size The number of bytes to read from the socket.
|
||||
* @access public
|
||||
* @return $size bytes of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function read($size)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return @fread($this->fp, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a specified amount of data.
|
||||
*
|
||||
* @param string $data Data to write.
|
||||
* @param integer $blocksize Amount of data to write at once.
|
||||
* NULL means all at once.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed true on success or an error object otherwise
|
||||
*/
|
||||
function write($data, $blocksize = null)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
if (is_null($blocksize) && !OS_WINDOWS) {
|
||||
return fwrite($this->fp, $data);
|
||||
} else {
|
||||
if (is_null($blocksize)) {
|
||||
$blocksize = 1024;
|
||||
}
|
||||
|
||||
$pos = 0;
|
||||
$size = strlen($data);
|
||||
while ($pos < $size) {
|
||||
$written = @fwrite($this->fp, substr($data, $pos, $blocksize));
|
||||
if ($written === false) {
|
||||
return false;
|
||||
}
|
||||
$pos += $written;
|
||||
}
|
||||
|
||||
return $pos;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a line of data to the socket, followed by a trailing "\r\n".
|
||||
*
|
||||
* @access public
|
||||
* @return mixed fputs result, or an error
|
||||
*/
|
||||
function writeLine($data)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return fwrite($this->fp, $data . "\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for end-of-file on a socket descriptor.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function eof()
|
||||
{
|
||||
return (is_resource($this->fp) && feof($this->fp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 byte of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readByte()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
return ord(@fread($this->fp, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a word of data
|
||||
*
|
||||
* @access public
|
||||
* @return 1 word of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readWord()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 2);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an int of data
|
||||
*
|
||||
* @access public
|
||||
* @return integer 1 int of data from the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readInt()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 4);
|
||||
return (ord($buf[0]) + (ord($buf[1]) << 8) +
|
||||
(ord($buf[2]) << 16) + (ord($buf[3]) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a zero-terminated string of data
|
||||
*
|
||||
* @access public
|
||||
* @return string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readString()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$string = '';
|
||||
while (($char = @fread($this->fp, 1)) != "\x00") {
|
||||
$string .= $char;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an IP Address and returns it in a dot formated string
|
||||
*
|
||||
* @access public
|
||||
* @return Dot formated string, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readIPAddress()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$buf = @fread($this->fp, 4);
|
||||
return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]),
|
||||
ord($buf[2]), ord($buf[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read until either the end of the socket or a newline, whichever
|
||||
* comes first. Strips the trailing newline from the returned data.
|
||||
*
|
||||
* @access public
|
||||
* @return All available data up to a newline, without that
|
||||
* newline, or until the end of the socket, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readLine()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$line = '';
|
||||
$timeout = time() + $this->timeout;
|
||||
while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) {
|
||||
$line .= @fgets($this->fp, $this->lineLength);
|
||||
if (substr($line, -1) == "\n") {
|
||||
return rtrim($line, "\r\n");
|
||||
}
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read until the socket closes, or until there is no more data in
|
||||
* the inner PHP buffer. If the inner buffer is empty, in blocking
|
||||
* mode we wait for at least 1 byte of data. Therefore, in
|
||||
* blocking mode, if there is no data at all to be read, this
|
||||
* function will never exit (unless the socket is closed on the
|
||||
* remote end).
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return string All data until the socket closes, or a PEAR_Error if
|
||||
* not connected.
|
||||
*/
|
||||
function readAll()
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$data = '';
|
||||
while (!feof($this->fp)) {
|
||||
$data .= @fread($this->fp, $this->lineLength);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the equivalent of the select() system call on the socket
|
||||
* with a timeout specified by tv_sec and tv_usec.
|
||||
*
|
||||
* @param integer $state Which of read/write/error to check for.
|
||||
* @param integer $tv_sec Number of seconds for timeout.
|
||||
* @param integer $tv_usec Number of microseconds for timeout.
|
||||
*
|
||||
* @access public
|
||||
* @return False if select fails, integer describing which of read/write/error
|
||||
* are ready, or PEAR_Error if not connected.
|
||||
*/
|
||||
function select($state, $tv_sec, $tv_usec = 0)
|
||||
{
|
||||
if (!is_resource($this->fp)) {
|
||||
return $this->raiseError('not connected');
|
||||
}
|
||||
|
||||
$read = null;
|
||||
$write = null;
|
||||
$except = null;
|
||||
if ($state & NET_SOCKET_READ) {
|
||||
$read[] = $this->fp;
|
||||
}
|
||||
if ($state & NET_SOCKET_WRITE) {
|
||||
$write[] = $this->fp;
|
||||
}
|
||||
if ($state & NET_SOCKET_ERROR) {
|
||||
$except[] = $this->fp;
|
||||
}
|
||||
if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = 0;
|
||||
if (count($read)) {
|
||||
$result |= NET_SOCKET_READ;
|
||||
}
|
||||
if (count($write)) {
|
||||
$result |= NET_SOCKET_WRITE;
|
||||
}
|
||||
if (count($except)) {
|
||||
$result |= NET_SOCKET_ERROR;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,410 +0,0 @@
|
|||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2004, Richard Heyes |
|
||||
// | All rights reserved. |
|
||||
// | |
|
||||
// | Redistribution and use in source and binary forms, with or without |
|
||||
// | modification, are permitted provided that the following conditions |
|
||||
// | are met: |
|
||||
// | |
|
||||
// | o Redistributions of source code must retain the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer. |
|
||||
// | o 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.|
|
||||
// | o 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. |
|
||||
// | |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Author: Richard Heyes <richard at php net> |
|
||||
// +-----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: URL.php,v 1.36 2004/06/19 18:58:50 richard Exp $
|
||||
//
|
||||
// Net_URL Class
|
||||
|
||||
class Net_URL
|
||||
{
|
||||
/**
|
||||
* Full url
|
||||
* @var string
|
||||
*/
|
||||
var $url;
|
||||
|
||||
/**
|
||||
* Protocol
|
||||
* @var string
|
||||
*/
|
||||
var $protocol;
|
||||
|
||||
/**
|
||||
* Username
|
||||
* @var string
|
||||
*/
|
||||
var $username;
|
||||
|
||||
/**
|
||||
* Password
|
||||
* @var string
|
||||
*/
|
||||
var $password;
|
||||
|
||||
/**
|
||||
* Host
|
||||
* @var string
|
||||
*/
|
||||
var $host;
|
||||
|
||||
/**
|
||||
* Port
|
||||
* @var integer
|
||||
*/
|
||||
var $port;
|
||||
|
||||
/**
|
||||
* Path
|
||||
* @var string
|
||||
*/
|
||||
var $path;
|
||||
|
||||
/**
|
||||
* Query string
|
||||
* @var array
|
||||
*/
|
||||
var $querystring;
|
||||
|
||||
/**
|
||||
* Anchor
|
||||
* @var string
|
||||
*/
|
||||
var $anchor;
|
||||
|
||||
/**
|
||||
* Whether to use []
|
||||
* @var bool
|
||||
*/
|
||||
var $useBrackets;
|
||||
|
||||
/**
|
||||
* PHP4 Constructor
|
||||
*
|
||||
* @see __construct()
|
||||
*/
|
||||
function Net_URL($url = null, $useBrackets = true)
|
||||
{
|
||||
$this->__construct($url, $useBrackets);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP5 Constructor
|
||||
*
|
||||
* Parses the given url and stores the various parts
|
||||
* Defaults are used in certain cases
|
||||
*
|
||||
* @param string $url Optional URL
|
||||
* @param bool $useBrackets Whether to use square brackets when
|
||||
* multiple querystrings with the same name
|
||||
* exist
|
||||
*/
|
||||
function __construct($url = null, $useBrackets = true)
|
||||
{
|
||||
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
|
||||
|
||||
$this->useBrackets = $useBrackets;
|
||||
$this->url = $url;
|
||||
$this->user = '';
|
||||
$this->pass = '';
|
||||
$this->host = '';
|
||||
$this->port = 80;
|
||||
$this->path = '';
|
||||
$this->querystring = array();
|
||||
$this->anchor = '';
|
||||
|
||||
// Only use defaults if not an absolute URL given
|
||||
if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
|
||||
|
||||
$this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
|
||||
|
||||
/**
|
||||
* Figure out host/port
|
||||
*/
|
||||
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
|
||||
$host = $matches[1];
|
||||
if (!empty($matches[3])) {
|
||||
$port = $matches[3];
|
||||
} else {
|
||||
$port = $this->getStandardPort($this->protocol);
|
||||
}
|
||||
}
|
||||
|
||||
$this->user = '';
|
||||
$this->pass = '';
|
||||
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
|
||||
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
|
||||
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
|
||||
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
|
||||
$this->anchor = '';
|
||||
}
|
||||
|
||||
// Parse the url and store the various parts
|
||||
if (!empty($url)) {
|
||||
$urlinfo = parse_url($url);
|
||||
|
||||
// Default querystring
|
||||
$this->querystring = array();
|
||||
|
||||
foreach ($urlinfo as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'scheme':
|
||||
$this->protocol = $value;
|
||||
$this->port = $this->getStandardPort($value);
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
case 'pass':
|
||||
case 'host':
|
||||
case 'port':
|
||||
$this->$key = $value;
|
||||
break;
|
||||
|
||||
case 'path':
|
||||
if ($value{0} == '/') {
|
||||
$this->path = $value;
|
||||
} else {
|
||||
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
|
||||
$this->path = sprintf('%s/%s', $path, $value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'query':
|
||||
$this->querystring = $this->_parseRawQueryString($value);
|
||||
break;
|
||||
|
||||
case 'fragment':
|
||||
$this->anchor = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full url
|
||||
*
|
||||
* @return string Full url
|
||||
* @access public
|
||||
*/
|
||||
function getURL()
|
||||
{
|
||||
$querystring = $this->getQueryString();
|
||||
|
||||
$this->url = $this->protocol . '://'
|
||||
. $this->user . (!empty($this->pass) ? ':' : '')
|
||||
. $this->pass . (!empty($this->user) ? '@' : '')
|
||||
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
|
||||
. $this->path
|
||||
. (!empty($querystring) ? '?' . $querystring : '')
|
||||
. (!empty($this->anchor) ? '#' . $this->anchor : '');
|
||||
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a querystring item
|
||||
*
|
||||
* @param string $name Name of item
|
||||
* @param string $value Value of item
|
||||
* @param bool $preencoded Whether value is urlencoded or not, default = not
|
||||
* @access public
|
||||
*/
|
||||
function addQueryString($name, $value, $preencoded = false)
|
||||
{
|
||||
if ($preencoded) {
|
||||
$this->querystring[$name] = $value;
|
||||
} else {
|
||||
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a querystring item
|
||||
*
|
||||
* @param string $name Name of item
|
||||
* @access public
|
||||
*/
|
||||
function removeQueryString($name)
|
||||
{
|
||||
if (isset($this->querystring[$name])) {
|
||||
unset($this->querystring[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the querystring to literally what you supply
|
||||
*
|
||||
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
|
||||
* @access public
|
||||
*/
|
||||
function addRawQueryString($querystring)
|
||||
{
|
||||
$this->querystring = $this->_parseRawQueryString($querystring);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns flat querystring
|
||||
*
|
||||
* @return string Querystring
|
||||
* @access public
|
||||
*/
|
||||
function getQueryString()
|
||||
{
|
||||
if (!empty($this->querystring)) {
|
||||
foreach ($this->querystring as $name => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
|
||||
}
|
||||
} elseif (!is_null($value)) {
|
||||
$querystring[] = $name . '=' . $value;
|
||||
} else {
|
||||
$querystring[] = $name;
|
||||
}
|
||||
}
|
||||
$querystring = implode(ini_get('arg_separator.output'), $querystring);
|
||||
} else {
|
||||
$querystring = '';
|
||||
}
|
||||
|
||||
return $querystring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses raw querystring and returns an array of it
|
||||
*
|
||||
* @param string $querystring The querystring to parse
|
||||
* @return array An array of the querystring data
|
||||
* @access private
|
||||
*/
|
||||
function _parseRawQuerystring($querystring)
|
||||
{
|
||||
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$return = array();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
$value = substr($part, strpos($part, '=') + 1);
|
||||
$key = substr($part, 0, strpos($part, '='));
|
||||
} else {
|
||||
$value = null;
|
||||
$key = $part;
|
||||
}
|
||||
if (substr($key, -2) == '[]') {
|
||||
$key = substr($key, 0, -2);
|
||||
if (@!is_array($return[$key])) {
|
||||
$return[$key] = array();
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key][] = $value;
|
||||
}
|
||||
} elseif (!$this->useBrackets AND !empty($return[$key])) {
|
||||
$return[$key] = (array)$return[$key];
|
||||
$return[$key][] = $value;
|
||||
} else {
|
||||
$return[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves //, ../ and ./ from a path and returns
|
||||
* the result. Eg:
|
||||
*
|
||||
* /foo/bar/../boo.php => /foo/boo.php
|
||||
* /foo/bar/../../boo.php => /boo.php
|
||||
* /foo/bar/.././/boo.php => /foo/boo.php
|
||||
*
|
||||
* This method can also be called statically.
|
||||
*
|
||||
* @param string $url URL path to resolve
|
||||
* @return string The result
|
||||
*/
|
||||
function resolvePath($path)
|
||||
{
|
||||
$path = explode('/', str_replace('//', '/', $path));
|
||||
|
||||
for ($i=0; $i<count($path); $i++) {
|
||||
if ($path[$i] == '.') {
|
||||
unset($path[$i]);
|
||||
$path = array_values($path);
|
||||
$i--;
|
||||
|
||||
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
|
||||
unset($path[$i]);
|
||||
unset($path[$i-1]);
|
||||
$path = array_values($path);
|
||||
$i -= 2;
|
||||
|
||||
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
|
||||
unset($path[$i]);
|
||||
$path = array_values($path);
|
||||
$i--;
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('/', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the standard port number for a protocol
|
||||
*
|
||||
* @param string $scheme The protocol to lookup
|
||||
* @return integer Port number or NULL if no scheme matches
|
||||
*
|
||||
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
|
||||
*/
|
||||
function getStandardPort($scheme)
|
||||
{
|
||||
switch (strtolower($scheme)) {
|
||||
case 'http': return 80;
|
||||
case 'https': return 443;
|
||||
case 'ftp': return 21;
|
||||
case 'imap': return 143;
|
||||
case 'imaps': return 993;
|
||||
case 'pop3': return 110;
|
||||
case 'pop3s': return 995;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the URL to a particular protocol
|
||||
*
|
||||
* @param string $protocol Protocol to force the URL to
|
||||
* @param integer $port Optional port (standard port is used by default)
|
||||
*/
|
||||
function setProtocol($protocol, $port = null)
|
||||
{
|
||||
$this->protocol = $protocol;
|
||||
$this->port = is_null($port) ? $this->getStandardPort() : $port;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
1108
libs/PEAR/PEAR.php
1108
libs/PEAR/PEAR.php
File diff suppressed because it is too large
Load diff
34
vendor/composer/autoload_classmap.php
vendored
34
vendor/composer/autoload_classmap.php
vendored
|
|
@ -237,37 +237,6 @@ return array(
|
|||
'HTMLPurifier_VarParser_Flexible' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/VarParser/Flexible.php',
|
||||
'HTMLPurifier_VarParser_Native' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/VarParser/Native.php',
|
||||
'HTMLPurifier_Zipper' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Zipper.php',
|
||||
'HTTP_Request2' => $vendorDir . '/pear/http_request2/HTTP/Request2.php',
|
||||
'HTTP_Request2Test' => $vendorDir . '/pear/http_request2/tests/Request2Test.php',
|
||||
'HTTP_Request2_Adapter' => $vendorDir . '/pear/http_request2/HTTP/Request2/Adapter.php',
|
||||
'HTTP_Request2_Adapter_CommonNetworkTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/CommonNetworkTest.php',
|
||||
'HTTP_Request2_Adapter_Curl' => $vendorDir . '/pear/http_request2/HTTP/Request2/Adapter/Curl.php',
|
||||
'HTTP_Request2_Adapter_CurlTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/CurlTest.php',
|
||||
'HTTP_Request2_Adapter_Mock' => $vendorDir . '/pear/http_request2/HTTP/Request2/Adapter/Mock.php',
|
||||
'HTTP_Request2_Adapter_MockTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/MockTest.php',
|
||||
'HTTP_Request2_Adapter_Skip_CurlTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/SkippedTests.php',
|
||||
'HTTP_Request2_Adapter_Skip_SocketProxyTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/SkippedTests.php',
|
||||
'HTTP_Request2_Adapter_Skip_SocketTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/SkippedTests.php',
|
||||
'HTTP_Request2_Adapter_Socket' => $vendorDir . '/pear/http_request2/HTTP/Request2/Adapter/Socket.php',
|
||||
'HTTP_Request2_Adapter_SocketProxyTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/SocketProxyTest.php',
|
||||
'HTTP_Request2_Adapter_SocketTest' => $vendorDir . '/pear/http_request2/tests/Request2/Adapter/SocketTest.php',
|
||||
'HTTP_Request2_AllTests' => $vendorDir . '/pear/http_request2/tests/AllTests.php',
|
||||
'HTTP_Request2_ConnectionException' => $vendorDir . '/pear/http_request2/HTTP/Request2/Exception.php',
|
||||
'HTTP_Request2_CookieJar' => $vendorDir . '/pear/http_request2/HTTP/Request2/CookieJar.php',
|
||||
'HTTP_Request2_CookieJarTest' => $vendorDir . '/pear/http_request2/tests/Request2/CookieJarTest.php',
|
||||
'HTTP_Request2_Exception' => $vendorDir . '/pear/http_request2/HTTP/Request2/Exception.php',
|
||||
'HTTP_Request2_LogicException' => $vendorDir . '/pear/http_request2/HTTP/Request2/Exception.php',
|
||||
'HTTP_Request2_MessageException' => $vendorDir . '/pear/http_request2/HTTP/Request2/Exception.php',
|
||||
'HTTP_Request2_MockObserver' => $vendorDir . '/pear/http_request2/tests/ObserverTest.php',
|
||||
'HTTP_Request2_MultipartBody' => $vendorDir . '/pear/http_request2/HTTP/Request2/MultipartBody.php',
|
||||
'HTTP_Request2_MultipartBodyTest' => $vendorDir . '/pear/http_request2/tests/Request2/MultipartBodyTest.php',
|
||||
'HTTP_Request2_NotImplementedException' => $vendorDir . '/pear/http_request2/HTTP/Request2/Exception.php',
|
||||
'HTTP_Request2_ObserverTest' => $vendorDir . '/pear/http_request2/tests/ObserverTest.php',
|
||||
'HTTP_Request2_Observer_Log' => $vendorDir . '/pear/http_request2/HTTP/Request2/Observer/Log.php',
|
||||
'HTTP_Request2_Response' => $vendorDir . '/pear/http_request2/HTTP/Request2/Response.php',
|
||||
'HTTP_Request2_ResponseTest' => $vendorDir . '/pear/http_request2/tests/Request2/ResponseTest.php',
|
||||
'HTTP_Request2_SOCKS5' => $vendorDir . '/pear/http_request2/HTTP/Request2/SOCKS5.php',
|
||||
'HTTP_Request2_SocketWrapper' => $vendorDir . '/pear/http_request2/HTTP/Request2/SocketWrapper.php',
|
||||
'MatthiasMullie\\Minify\\CSS' => $vendorDir . '/matthiasmullie/minify/src/CSS.php',
|
||||
'MatthiasMullie\\Minify\\Exception' => $vendorDir . '/matthiasmullie/minify/src/Exception.php',
|
||||
'MatthiasMullie\\Minify\\JS' => $vendorDir . '/matthiasmullie/minify/src/JS.php',
|
||||
|
|
@ -276,9 +245,6 @@ return array(
|
|||
'Michelf\\Markdown' => $vendorDir . '/michelf/php-markdown/Michelf/Markdown.php',
|
||||
'Michelf\\MarkdownExtra' => $vendorDir . '/michelf/php-markdown/Michelf/MarkdownExtra.php',
|
||||
'Michelf\\MarkdownInterface' => $vendorDir . '/michelf/php-markdown/Michelf/MarkdownInterface.php',
|
||||
'Net_URL2' => $vendorDir . '/pear/net_url2/Net/URL2.php',
|
||||
'PEAR_Exception' => $vendorDir . '/pear/pear_exception/PEAR/Exception.php',
|
||||
'PEAR_ExceptionTest' => $vendorDir . '/pear/pear_exception/tests/PEAR/ExceptionTest.php',
|
||||
'Requests' => $vendorDir . '/rmccue/requests/library/Requests.php',
|
||||
'Requests_Auth' => $vendorDir . '/rmccue/requests/library/Requests/Auth.php',
|
||||
'Requests_Auth_Basic' => $vendorDir . '/rmccue/requests/library/Requests/Auth/Basic.php',
|
||||
|
|
|
|||
2
vendor/composer/autoload_namespaces.php
vendored
2
vendor/composer/autoload_namespaces.php
vendored
|
|
@ -8,8 +8,6 @@ $baseDir = dirname($vendorDir);
|
|||
return array(
|
||||
'Sunra\\PhpSimple\\HtmlDomParser' => array($vendorDir . '/sunra/php-simple-html-dom-parser/Src'),
|
||||
'Requests' => array($vendorDir . '/rmccue/requests/library'),
|
||||
'PEAR' => array($vendorDir . '/pear/pear_exception'),
|
||||
'Michelf' => array($vendorDir . '/michelf/php-markdown'),
|
||||
'HTTP_Request2' => array($vendorDir . '/pear/http_request2'),
|
||||
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
||||
);
|
||||
|
|
|
|||
4
vendor/composer/autoload_real.php
vendored
4
vendor/composer/autoload_real.php
vendored
|
|
@ -23,10 +23,6 @@ class ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de
|
|||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1e37ff09eb6590c7436f139ffd9070de', 'loadClassLoader'));
|
||||
|
||||
$includePaths = require __DIR__ . '/include_paths.php';
|
||||
array_push($includePaths, get_include_path());
|
||||
set_include_path(join(PATH_SEPARATOR, $includePaths));
|
||||
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
|
|
|
|||
10
vendor/composer/include_paths.php
vendored
10
vendor/composer/include_paths.php
vendored
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
// include_paths.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
$vendorDir . '/pear/pear_exception',
|
||||
);
|
||||
174
vendor/composer/installed.json
vendored
174
vendor/composer/installed.json
vendored
|
|
@ -352,180 +352,6 @@
|
|||
"minify"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pear/pear_exception",
|
||||
"version": "v1.0.0",
|
||||
"version_normalized": "1.0.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/PEAR_Exception.git",
|
||||
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
|
||||
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=4.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"time": "2015-02-10 20:07:52",
|
||||
"type": "class",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"PEAR": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"include-path": [
|
||||
"."
|
||||
],
|
||||
"license": [
|
||||
"BSD-2-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Helgi Thormar",
|
||||
"email": "dufuz@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Greg Beaver",
|
||||
"email": "cellog@php.net"
|
||||
}
|
||||
],
|
||||
"description": "The PEAR Exception base class.",
|
||||
"homepage": "https://github.com/pear/PEAR_Exception",
|
||||
"keywords": [
|
||||
"exception"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pear/net_url2",
|
||||
"version": "v2.2.0",
|
||||
"version_normalized": "2.2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/Net_URL2.git",
|
||||
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/Net_URL2/zipball/fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
|
||||
"reference": "fa9b1ecb3c3e640d4a54d58d681a4cb7524f209e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.1.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=3.3.0"
|
||||
},
|
||||
"time": "2015-04-18 17:36:57",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2.x-dev"
|
||||
}
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"Net/URL2.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Coallier",
|
||||
"email": "davidc@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Tom Klingenberg",
|
||||
"email": "tkli@php.net"
|
||||
},
|
||||
{
|
||||
"name": "Christian Schmidt",
|
||||
"email": "chmidt@php.net"
|
||||
}
|
||||
],
|
||||
"description": "Class for parsing and handling URL. Provides parsing of URLs into their constituent parts (scheme, host, path etc.), URL generation, and resolving of relative URLs.",
|
||||
"homepage": "https://github.com/pear/Net_URL2",
|
||||
"keywords": [
|
||||
"PEAR",
|
||||
"net",
|
||||
"networking",
|
||||
"rfc3986",
|
||||
"uri",
|
||||
"url"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pear/http_request2",
|
||||
"version": "v2.2.1",
|
||||
"version_normalized": "2.2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pear/HTTP_Request2.git",
|
||||
"reference": "d6c81670c504045248c1afdf896bb9a3288158de"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pear/HTTP_Request2/zipball/d6c81670c504045248c1afdf896bb9a3288158de",
|
||||
"reference": "d6c81670c504045248c1afdf896bb9a3288158de",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"pear/net_url2": ">=2.0.0",
|
||||
"pear/pear_exception": "*",
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-fileinfo": "Adds support for looking up mime-types using finfo.",
|
||||
"ext-zlib": "Allows handling gzip compressed responses.",
|
||||
"lib-curl": "Allows using cURL as a request backend.",
|
||||
"lib-openssl": "Allows handling SSL requests when not using cURL."
|
||||
},
|
||||
"time": "2014-01-16 17:27:21",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"HTTP_Request2": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alexey Borzov",
|
||||
"email": "avb@php.net",
|
||||
"role": "Developer HTML_Common2"
|
||||
}
|
||||
],
|
||||
"description": "Provides an easy way to perform HTTP requests.",
|
||||
"homepage": "http://pear.php.net/package/HTTP_Request2",
|
||||
"keywords": [
|
||||
"PEAR",
|
||||
"curl",
|
||||
"http",
|
||||
"request"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "swiftmailer/swiftmailer",
|
||||
"version": "v5.4.1",
|
||||
|
|
|
|||
1030
vendor/pear/http_request2/HTTP/Request2.php
vendored
1030
vendor/pear/http_request2/HTTP/Request2.php
vendored
File diff suppressed because it is too large
Load diff
137
vendor/pear/http_request2/HTTP/Request2/Adapter.php
vendored
137
vendor/pear/http_request2/HTTP/Request2/Adapter.php
vendored
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*/
|
||||
require_once 'HTTP/Request2/Response.php';
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*
|
||||
* HTTP_Request2 class itself only defines methods for aggregating the request
|
||||
* data, all actual work of sending the request to the remote server and
|
||||
* receiving its response is performed by adapters.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
abstract class HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A list of methods that MUST NOT have a request body, per RFC 2616
|
||||
* @var array
|
||||
*/
|
||||
protected static $bodyDisallowed = array('TRACE');
|
||||
|
||||
/**
|
||||
* Methods having defined semantics for request body
|
||||
*
|
||||
* Content-Length header (indicating that the body follows, section 4.3 of
|
||||
* RFC 2616) will be sent for these methods even if no body was added
|
||||
*
|
||||
* @var array
|
||||
* @link http://pear.php.net/bugs/bug.php?id=12900
|
||||
* @link http://pear.php.net/bugs/bug.php?id=14740
|
||||
*/
|
||||
protected static $bodyRequired = array('POST', 'PUT');
|
||||
|
||||
/**
|
||||
* Request being sent
|
||||
* @var HTTP_Request2
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Request body
|
||||
* @var string|resource|HTTP_Request2_MultipartBody
|
||||
* @see HTTP_Request2::getBody()
|
||||
*/
|
||||
protected $requestBody;
|
||||
|
||||
/**
|
||||
* Length of the request body
|
||||
* @var integer
|
||||
*/
|
||||
protected $contentLength;
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
abstract public function sendRequest(HTTP_Request2 $request);
|
||||
|
||||
/**
|
||||
* Calculates length of the request body, adds proper headers
|
||||
*
|
||||
* @param array &$headers associative array of request headers, this method
|
||||
* will add proper 'Content-Length' and 'Content-Type'
|
||||
* headers to this array (or remove them if not needed)
|
||||
*/
|
||||
protected function calculateRequestLength(&$headers)
|
||||
{
|
||||
$this->requestBody = $this->request->getBody();
|
||||
|
||||
if (is_string($this->requestBody)) {
|
||||
$this->contentLength = strlen($this->requestBody);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$stat = fstat($this->requestBody);
|
||||
$this->contentLength = $stat['size'];
|
||||
rewind($this->requestBody);
|
||||
} else {
|
||||
$this->contentLength = $this->requestBody->getLength();
|
||||
$headers['content-type'] = 'multipart/form-data; boundary=' .
|
||||
$this->requestBody->getBoundary();
|
||||
$this->requestBody->rewind();
|
||||
}
|
||||
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed)
|
||||
|| 0 == $this->contentLength
|
||||
) {
|
||||
// No body: send a Content-Length header nonetheless (request #12900),
|
||||
// but do that only for methods that require a body (bug #14740)
|
||||
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
|
||||
$headers['content-length'] = 0;
|
||||
} else {
|
||||
unset($headers['content-length']);
|
||||
// if the method doesn't require a body and doesn't have a
|
||||
// body, don't send a Content-Type header. (request #16799)
|
||||
unset($headers['content-type']);
|
||||
}
|
||||
} else {
|
||||
if (empty($headers['content-type'])) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,567 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Adapter for HTTP_Request2 wrapping around cURL extension
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Curl extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* Mapping of header names to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $headerMap = array(
|
||||
'accept-encoding' => CURLOPT_ENCODING,
|
||||
'cookie' => CURLOPT_COOKIE,
|
||||
'referer' => CURLOPT_REFERER,
|
||||
'user-agent' => CURLOPT_USERAGENT
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of SSL context options to cURL options
|
||||
* @var array
|
||||
*/
|
||||
protected static $sslContextMap = array(
|
||||
'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
|
||||
'ssl_cafile' => CURLOPT_CAINFO,
|
||||
'ssl_capath' => CURLOPT_CAPATH,
|
||||
'ssl_local_cert' => CURLOPT_SSLCERT,
|
||||
'ssl_passphrase' => CURLOPT_SSLCERTPASSWD
|
||||
);
|
||||
|
||||
/**
|
||||
* Mapping of CURLE_* constants to Exception subclasses and error codes
|
||||
* @var array
|
||||
*/
|
||||
protected static $errorMap = array(
|
||||
CURLE_UNSUPPORTED_PROTOCOL => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_COULDNT_RESOLVE_PROXY => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_COULDNT_RESOLVE_HOST => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_COULDNT_CONNECT => array('HTTP_Request2_ConnectionException'),
|
||||
// error returned from write callback
|
||||
CURLE_WRITE_ERROR => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_OPERATION_TIMEOUTED => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::TIMEOUT),
|
||||
CURLE_HTTP_RANGE_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_CONNECT_ERROR => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_LIBRARY_NOT_FOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_FUNCTION_NOT_FOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_ABORTED_BY_CALLBACK => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::NON_HTTP_REDIRECT),
|
||||
CURLE_TOO_MANY_REDIRECTS => array('HTTP_Request2_MessageException',
|
||||
HTTP_Request2_Exception::TOO_MANY_REDIRECTS),
|
||||
CURLE_SSL_PEER_CERTIFICATE => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_GOT_NOTHING => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_ENGINE_NOTFOUND => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_SSL_ENGINE_SETFAILED => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION),
|
||||
CURLE_SEND_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_RECV_ERROR => array('HTTP_Request2_MessageException'),
|
||||
CURLE_SSL_CERTPROBLEM => array('HTTP_Request2_LogicException',
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT),
|
||||
CURLE_SSL_CIPHER => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_SSL_CACERT => array('HTTP_Request2_ConnectionException'),
|
||||
CURLE_BAD_CONTENT_ENCODING => array('HTTP_Request2_MessageException'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Response being received
|
||||
* @var HTTP_Request2_Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Whether 'sentHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventSentHeaders = false;
|
||||
|
||||
/**
|
||||
* Whether 'receivedHeaders' event was sent to observers
|
||||
* @var boolean
|
||||
*/
|
||||
protected $eventReceivedHeaders = false;
|
||||
|
||||
/**
|
||||
* Position within request body
|
||||
* @var integer
|
||||
* @see callbackReadBody()
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Information about last transfer, as returned by curl_getinfo()
|
||||
* @var array
|
||||
*/
|
||||
protected $lastInfo;
|
||||
|
||||
/**
|
||||
* Creates a subclass of HTTP_Request2_Exception from curl error data
|
||||
*
|
||||
* @param resource $ch curl handle
|
||||
*
|
||||
* @return HTTP_Request2_Exception
|
||||
*/
|
||||
protected static function wrapCurlError($ch)
|
||||
{
|
||||
$nativeCode = curl_errno($ch);
|
||||
$message = 'Curl error: ' . curl_error($ch);
|
||||
if (!isset(self::$errorMap[$nativeCode])) {
|
||||
return new HTTP_Request2_Exception($message, 0, $nativeCode);
|
||||
} else {
|
||||
$class = self::$errorMap[$nativeCode][0];
|
||||
$code = empty(self::$errorMap[$nativeCode][1])
|
||||
? 0 : self::$errorMap[$nativeCode][1];
|
||||
return new $class($message, $code, $nativeCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends request to the remote server and returns its response
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'cURL extension not available', HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
|
||||
$this->request = $request;
|
||||
$this->response = null;
|
||||
$this->position = 0;
|
||||
$this->eventSentHeaders = false;
|
||||
$this->eventReceivedHeaders = false;
|
||||
|
||||
try {
|
||||
if (false === curl_exec($ch = $this->createCurlHandle())) {
|
||||
$e = self::wrapCurlError($ch);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
if (isset($ch)) {
|
||||
$this->lastInfo = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
$response = $this->response;
|
||||
unset($this->request, $this->requestBody, $this->response);
|
||||
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($jar = $request->getCookieJar()) {
|
||||
$jar->addCookiesFromResponse($response, $request->getUrl());
|
||||
}
|
||||
|
||||
if (0 < $this->lastInfo['size_download']) {
|
||||
$request->setLastEvent('receivedBody', $response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about last transfer
|
||||
*
|
||||
* @return array associative array as returned by curl_getinfo()
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->lastInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cURL handle and populates it with data from the request
|
||||
*
|
||||
* @return resource a cURL handle, as created by curl_init()
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_NotImplementedException
|
||||
*/
|
||||
protected function createCurlHandle()
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, array(
|
||||
// setup write callbacks
|
||||
CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
|
||||
CURLOPT_WRITEFUNCTION => array($this, 'callbackWriteBody'),
|
||||
// buffer size
|
||||
CURLOPT_BUFFERSIZE => $this->request->getConfig('buffer_size'),
|
||||
// connection timeout
|
||||
CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
|
||||
// save full outgoing headers, in case someone is interested
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
// request url
|
||||
CURLOPT_URL => $this->request->getUrl()->getUrl()
|
||||
));
|
||||
|
||||
// set up redirects
|
||||
if (!$this->request->getConfig('follow_redirects')) {
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
||||
} else {
|
||||
if (!@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true)) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Redirect support in curl is unavailable due to open_basedir or safe_mode setting',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
|
||||
// limit redirects to http(s), works in 5.2.10+
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
// works in 5.3.2+, http://bugs.php.net/bug.php?id=49571
|
||||
if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR')) {
|
||||
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
|
||||
}
|
||||
}
|
||||
|
||||
// set local IP via CURLOPT_INTERFACE (request #19515)
|
||||
if ($ip = $this->request->getConfig('local_ip')) {
|
||||
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
|
||||
}
|
||||
|
||||
// request timeout
|
||||
if ($timeout = $this->request->getConfig('timeout')) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
|
||||
// set HTTP version
|
||||
switch ($this->request->getConfig('protocol_version')) {
|
||||
case '1.0':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
break;
|
||||
case '1.1':
|
||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
|
||||
// set request method
|
||||
switch ($this->request->getMethod()) {
|
||||
case HTTP_Request2::METHOD_GET:
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_POST:
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_HEAD:
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case HTTP_Request2::METHOD_PUT:
|
||||
curl_setopt($ch, CURLOPT_UPLOAD, true);
|
||||
break;
|
||||
default:
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
|
||||
}
|
||||
|
||||
// set proxy, if needed
|
||||
if ($host = $this->request->getConfig('proxy_host')) {
|
||||
if (!($port = $this->request->getConfig('proxy_port'))) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Proxy port not provided', HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
|
||||
if ($user = $this->request->getConfig('proxy_user')) {
|
||||
curl_setopt(
|
||||
$ch, CURLOPT_PROXYUSERPWD,
|
||||
$user . ':' . $this->request->getConfig('proxy_password')
|
||||
);
|
||||
switch ($this->request->getConfig('proxy_auth_scheme')) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
if ($type = $this->request->getConfig('proxy_type')) {
|
||||
switch ($type) {
|
||||
case 'http':
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
break;
|
||||
case 'socks5':
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||
break;
|
||||
default:
|
||||
throw new HTTP_Request2_NotImplementedException(
|
||||
"Proxy type '{$type}' is not supported"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set authentication data
|
||||
if ($auth = $this->request->getAuth()) {
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
|
||||
switch ($auth['scheme']) {
|
||||
case HTTP_Request2::AUTH_BASIC:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
break;
|
||||
case HTTP_Request2::AUTH_DIGEST:
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
}
|
||||
}
|
||||
|
||||
// set SSL options
|
||||
foreach ($this->request->getConfig() as $name => $value) {
|
||||
if ('ssl_verify_host' == $name && null !== $value) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
|
||||
} elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
|
||||
curl_setopt($ch, self::$sslContextMap[$name], $value);
|
||||
}
|
||||
}
|
||||
|
||||
$headers = $this->request->getHeaders();
|
||||
// make cURL automagically send proper header
|
||||
if (!isset($headers['accept-encoding'])) {
|
||||
$headers['accept-encoding'] = '';
|
||||
}
|
||||
|
||||
if (($jar = $this->request->getCookieJar())
|
||||
&& ($cookies = $jar->getMatching($this->request->getUrl(), true))
|
||||
) {
|
||||
$headers['cookie'] = (empty($headers['cookie'])? '': $headers['cookie'] . '; ') . $cookies;
|
||||
}
|
||||
|
||||
// set headers having special cURL keys
|
||||
foreach (self::$headerMap as $name => $option) {
|
||||
if (isset($headers[$name])) {
|
||||
curl_setopt($ch, $option, $headers[$name]);
|
||||
unset($headers[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->calculateRequestLength($headers);
|
||||
if (isset($headers['content-length']) || isset($headers['transfer-encoding'])) {
|
||||
$this->workaroundPhpBug47204($ch, $headers);
|
||||
}
|
||||
|
||||
// set headers not having special keys
|
||||
$headersFmt = array();
|
||||
foreach ($headers as $name => $value) {
|
||||
$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
|
||||
$headersFmt[] = $canonicalName . ': ' . $value;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
|
||||
|
||||
return $ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for PHP bug #47204 that prevents rewinding request body
|
||||
*
|
||||
* The workaround consists of reading the entire request body into memory
|
||||
* and setting it as CURLOPT_POSTFIELDS, so it isn't recommended for large
|
||||
* file uploads, use Socket adapter instead.
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param array &$headers Request headers
|
||||
*/
|
||||
protected function workaroundPhpBug47204($ch, &$headers)
|
||||
{
|
||||
// no redirects, no digest auth -> probably no rewind needed
|
||||
if (!$this->request->getConfig('follow_redirects')
|
||||
&& (!($auth = $this->request->getAuth())
|
||||
|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
|
||||
) {
|
||||
curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
|
||||
|
||||
} else {
|
||||
// rewind may be needed, read the whole body into memory
|
||||
if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
|
||||
$this->requestBody = $this->requestBody->__toString();
|
||||
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$fp = $this->requestBody;
|
||||
$this->requestBody = '';
|
||||
while (!feof($fp)) {
|
||||
$this->requestBody .= fread($fp, 16384);
|
||||
}
|
||||
}
|
||||
// curl hangs up if content-length is present
|
||||
unset($headers['content-length']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for reading the request body
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param resource $fd file descriptor (not used)
|
||||
* @param integer $length maximum length of data to return
|
||||
*
|
||||
* @return string part of the request body, up to $length bytes
|
||||
*/
|
||||
protected function callbackReadBody($ch, $fd, $length)
|
||||
{
|
||||
if (!$this->eventSentHeaders) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
$this->eventSentHeaders = true;
|
||||
}
|
||||
if (in_array($this->request->getMethod(), self::$bodyDisallowed)
|
||||
|| 0 == $this->contentLength || $this->position >= $this->contentLength
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
if (is_string($this->requestBody)) {
|
||||
$string = substr($this->requestBody, $this->position, $length);
|
||||
} elseif (is_resource($this->requestBody)) {
|
||||
$string = fread($this->requestBody, $length);
|
||||
} else {
|
||||
$string = $this->requestBody->read($length);
|
||||
}
|
||||
$this->request->setLastEvent('sentBodyPart', strlen($string));
|
||||
$this->position += strlen($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response headers
|
||||
*
|
||||
* @param resource $ch cURL handle
|
||||
* @param string $string response header (with trailing CRLF)
|
||||
*
|
||||
* @return integer number of bytes saved
|
||||
* @see HTTP_Request2_Response::parseHeaderLine()
|
||||
*/
|
||||
protected function callbackWriteHeader($ch, $string)
|
||||
{
|
||||
// we may receive a second set of headers if doing e.g. digest auth
|
||||
if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (!$this->eventSentHeaders
|
||||
|| $this->response->getStatus() >= 200
|
||||
) {
|
||||
$this->request->setLastEvent(
|
||||
'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
|
||||
);
|
||||
}
|
||||
$upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
|
||||
// if body wasn't read by a callback, send event with total body size
|
||||
if ($upload > $this->position) {
|
||||
$this->request->setLastEvent(
|
||||
'sentBodyPart', $upload - $this->position
|
||||
);
|
||||
$this->position = $upload;
|
||||
}
|
||||
if ($upload && (!$this->eventSentHeaders
|
||||
|| $this->response->getStatus() >= 200)
|
||||
) {
|
||||
$this->request->setLastEvent('sentBody', $upload);
|
||||
}
|
||||
$this->eventSentHeaders = true;
|
||||
// we'll need a new response object
|
||||
if ($this->eventReceivedHeaders) {
|
||||
$this->eventReceivedHeaders = false;
|
||||
$this->response = null;
|
||||
}
|
||||
}
|
||||
if (empty($this->response)) {
|
||||
$this->response = new HTTP_Request2_Response(
|
||||
$string, false, curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)
|
||||
);
|
||||
} else {
|
||||
$this->response->parseHeaderLine($string);
|
||||
if ('' == trim($string)) {
|
||||
// don't bother with 100-Continue responses (bug #15785)
|
||||
if (200 <= $this->response->getStatus()) {
|
||||
$this->request->setLastEvent('receivedHeaders', $this->response);
|
||||
}
|
||||
|
||||
if ($this->request->getConfig('follow_redirects') && $this->response->isRedirect()) {
|
||||
$redirectUrl = new Net_URL2($this->response->getHeader('location'));
|
||||
|
||||
// for versions lower than 5.2.10, check the redirection URL protocol
|
||||
if (!defined('CURLOPT_REDIR_PROTOCOLS') && $redirectUrl->isAbsolute()
|
||||
&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($jar = $this->request->getCookieJar()) {
|
||||
$jar->addCookiesFromResponse($this->response, $this->request->getUrl());
|
||||
if (!$redirectUrl->isAbsolute()) {
|
||||
$redirectUrl = $this->request->getUrl()->resolve($redirectUrl);
|
||||
}
|
||||
if ($cookies = $jar->getMatching($redirectUrl, true)) {
|
||||
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->eventReceivedHeaders = true;
|
||||
}
|
||||
}
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function called by cURL for saving the response body
|
||||
*
|
||||
* @param resource $ch cURL handle (not used)
|
||||
* @param string $string part of the response body
|
||||
*
|
||||
* @return integer number of bytes saved
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @see HTTP_Request2_Response::appendBody()
|
||||
*/
|
||||
protected function callbackWriteBody($ch, $string)
|
||||
{
|
||||
// cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
|
||||
// response doesn't start with proper HTTP status line (see bug #15716)
|
||||
if (empty($this->response)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Malformed response: {$string}",
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
if ($this->request->getConfig('store_body')) {
|
||||
$this->response->appendBody($string);
|
||||
}
|
||||
$this->request->setLastEvent('receivedBodyPart', $string);
|
||||
return strlen($string);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for HTTP_Request2 adapters
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter.php';
|
||||
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*
|
||||
* Can be used to test applications depending on HTTP_Request2 package without
|
||||
* actually performing any HTTP requests. This adapter will return responses
|
||||
* previously added via addResponse()
|
||||
* <code>
|
||||
* $mock = new HTTP_Request2_Adapter_Mock();
|
||||
* $mock->addResponse("HTTP/1.1 ... ");
|
||||
*
|
||||
* $request = new HTTP_Request2();
|
||||
* $request->setAdapter($mock);
|
||||
*
|
||||
* // This will return the response set above
|
||||
* $response = $req->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Mock extends HTTP_Request2_Adapter
|
||||
{
|
||||
/**
|
||||
* A queue of responses to be returned by sendRequest()
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
|
||||
/**
|
||||
* Returns the next response from the queue built by addResponse()
|
||||
*
|
||||
* Only responses without explicit URLs or with URLs equal to request URL
|
||||
* will be considered. If matching response is not found or the queue is
|
||||
* empty then default empty response with status 400 will be returned,
|
||||
* if an Exception object was added to the queue it will be thrown.
|
||||
*
|
||||
* @param HTTP_Request2 $request HTTP request message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendRequest(HTTP_Request2 $request)
|
||||
{
|
||||
$requestUrl = (string)$request->getUrl();
|
||||
$response = null;
|
||||
foreach ($this->responses as $k => $v) {
|
||||
if (!$v[1] || $requestUrl == $v[1]) {
|
||||
$response = $v[0];
|
||||
array_splice($this->responses, $k, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$response) {
|
||||
return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n");
|
||||
|
||||
} elseif ($response instanceof HTTP_Request2_Response) {
|
||||
return $response;
|
||||
|
||||
} else {
|
||||
// rethrow the exception
|
||||
$class = get_class($response);
|
||||
$message = $response->getMessage();
|
||||
$code = $response->getCode();
|
||||
throw new $class($message, $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds response to the queue
|
||||
*
|
||||
* @param mixed $response either a string, a pointer to an open file,
|
||||
* an instance of HTTP_Request2_Response or Exception
|
||||
* @param string $url A request URL this response should be valid for
|
||||
* (see {@link http://pear.php.net/bugs/bug.php?id=19276})
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function addResponse($response, $url = null)
|
||||
{
|
||||
if (is_string($response)) {
|
||||
$response = self::createResponseFromString($response);
|
||||
} elseif (is_resource($response)) {
|
||||
$response = self::createResponseFromFile($response);
|
||||
} elseif (!$response instanceof HTTP_Request2_Response &&
|
||||
!$response instanceof Exception
|
||||
) {
|
||||
throw new HTTP_Request2_Exception('Parameter is not a valid response');
|
||||
}
|
||||
$this->responses[] = array($response, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a string
|
||||
*
|
||||
* @param string $str string containing HTTP response message
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromString($str)
|
||||
{
|
||||
$parts = preg_split('!(\r?\n){2}!m', $str, 2);
|
||||
$headerLines = explode("\n", $parts[0]);
|
||||
$response = new HTTP_Request2_Response(array_shift($headerLines));
|
||||
foreach ($headerLines as $headerLine) {
|
||||
$response->parseHeaderLine($headerLine);
|
||||
}
|
||||
$response->parseHeaderLine('');
|
||||
if (isset($parts[1])) {
|
||||
$response->appendBody($parts[1]);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTP_Request2_Response object from a file
|
||||
*
|
||||
* @param resource $fp file pointer returned by fopen()
|
||||
*
|
||||
* @return HTTP_Request2_Response
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public static function createResponseFromFile($fp)
|
||||
{
|
||||
$response = new HTTP_Request2_Response(fgets($fp));
|
||||
do {
|
||||
$headerLine = fgets($fp);
|
||||
$response->parseHeaderLine($headerLine);
|
||||
} while ('' != trim($headerLine));
|
||||
|
||||
while (!feof($fp)) {
|
||||
$response->appendBody(fread($fp, 8192));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,494 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Stores cookies and passes them between HTTP requests
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Class representing a HTTP request message */
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Stores cookies and passes them between HTTP requests
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_CookieJar implements Serializable
|
||||
{
|
||||
/**
|
||||
* Array of stored cookies
|
||||
*
|
||||
* The array is indexed by domain, path and cookie name
|
||||
* .example.com
|
||||
* /
|
||||
* some_cookie => cookie data
|
||||
* /subdir
|
||||
* other_cookie => cookie data
|
||||
* .example.org
|
||||
* ...
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Whether session cookies should be serialized when serializing the jar
|
||||
* @var bool
|
||||
*/
|
||||
protected $serializeSession = false;
|
||||
|
||||
/**
|
||||
* Whether Public Suffix List should be used for domain matching
|
||||
* @var bool
|
||||
*/
|
||||
protected $useList = true;
|
||||
|
||||
/**
|
||||
* Array with Public Suffix List data
|
||||
* @var array
|
||||
* @link http://publicsuffix.org/
|
||||
*/
|
||||
protected static $psl = array();
|
||||
|
||||
/**
|
||||
* Class constructor, sets various options
|
||||
*
|
||||
* @param bool $serializeSessionCookies Controls serializing session cookies,
|
||||
* see {@link serializeSessionCookies()}
|
||||
* @param bool $usePublicSuffixList Controls using Public Suffix List,
|
||||
* see {@link usePublicSuffixList()}
|
||||
*/
|
||||
public function __construct(
|
||||
$serializeSessionCookies = false, $usePublicSuffixList = true
|
||||
) {
|
||||
$this->serializeSessionCookies($serializeSessionCookies);
|
||||
$this->usePublicSuffixList($usePublicSuffixList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current time formatted in ISO-8601 at UTC timezone
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function now()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
return $dt->format(DateTime::ISO8601);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields
|
||||
*
|
||||
* The checks are as follows:
|
||||
* - cookie array should contain 'name' and 'value' fields;
|
||||
* - name and value should not contain disallowed symbols;
|
||||
* - 'expires' should be either empty parseable by DateTime;
|
||||
* - 'domain' and 'path' should be either not empty or an URL where
|
||||
* cookie was set should be provided.
|
||||
* - if $setter is provided, then document at that URL should be allowed
|
||||
* to set a cookie for that 'domain'. If $setter is not provided,
|
||||
* then no domain checks will be made.
|
||||
*
|
||||
* 'expires' field will be converted to ISO8601 format from COOKIE format,
|
||||
* 'domain' and 'path' will be set from setter URL if empty.
|
||||
*
|
||||
* @param array $cookie cookie data, as returned by
|
||||
* {@link HTTP_Request2_Response::getCookies()}
|
||||
* @param Net_URL2 $setter URL of the document that sent Set-Cookie header
|
||||
*
|
||||
* @return array Updated cookie array
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
protected function checkAndUpdateFields(array $cookie, Net_URL2 $setter = null)
|
||||
{
|
||||
if ($missing = array_diff(array('name', 'value'), array_keys($cookie))) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Cookie array should contain 'name' and 'value' fields",
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['name'])) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Invalid cookie name: '{$cookie['name']}'",
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['value'])) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Invalid cookie value: '{$cookie['value']}'",
|
||||
HTTP_Request2_Exception::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
$cookie += array('domain' => '', 'path' => '', 'expires' => null, 'secure' => false);
|
||||
|
||||
// Need ISO-8601 date @ UTC timezone
|
||||
if (!empty($cookie['expires'])
|
||||
&& !preg_match('/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+0000$/', $cookie['expires'])
|
||||
) {
|
||||
try {
|
||||
$dt = new DateTime($cookie['expires']);
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$cookie['expires'] = $dt->format(DateTime::ISO8601);
|
||||
} catch (Exception $e) {
|
||||
throw new HTTP_Request2_LogicException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($cookie['domain']) || empty($cookie['path'])) {
|
||||
if (!$setter) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Cookie misses domain and/or path component, cookie setter URL needed',
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
if (empty($cookie['domain'])) {
|
||||
if ($host = $setter->getHost()) {
|
||||
$cookie['domain'] = $host;
|
||||
} else {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Setter URL does not contain host part, can\'t set cookie domain',
|
||||
HTTP_Request2_Exception::MISSING_VALUE
|
||||
);
|
||||
}
|
||||
}
|
||||
if (empty($cookie['path'])) {
|
||||
$path = $setter->getPath();
|
||||
$cookie['path'] = empty($path)? '/': substr($path, 0, strrpos($path, '/') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($setter && !$this->domainMatch($setter->getHost(), $cookie['domain'])) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Domain " . $setter->getHost() . " cannot set cookies for "
|
||||
. $cookie['domain']
|
||||
);
|
||||
}
|
||||
|
||||
return $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a cookie in the jar
|
||||
*
|
||||
* @param array $cookie cookie data, as returned by
|
||||
* {@link HTTP_Request2_Response::getCookies()}
|
||||
* @param Net_URL2 $setter URL of the document that sent Set-Cookie header
|
||||
*
|
||||
* @throws HTTP_Request2_Exception
|
||||
*/
|
||||
public function store(array $cookie, Net_URL2 $setter = null)
|
||||
{
|
||||
$cookie = $this->checkAndUpdateFields($cookie, $setter);
|
||||
|
||||
if (strlen($cookie['value'])
|
||||
&& (is_null($cookie['expires']) || $cookie['expires'] > $this->now())
|
||||
) {
|
||||
if (!isset($this->cookies[$cookie['domain']])) {
|
||||
$this->cookies[$cookie['domain']] = array();
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
|
||||
$this->cookies[$cookie['domain']][$cookie['path']] = array();
|
||||
}
|
||||
$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
|
||||
|
||||
} elseif (isset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']])) {
|
||||
unset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds cookies set in HTTP response to the jar
|
||||
*
|
||||
* @param HTTP_Request2_Response $response HTTP response message
|
||||
* @param Net_URL2 $setter original request URL, needed for
|
||||
* setting default domain/path
|
||||
*/
|
||||
public function addCookiesFromResponse(HTTP_Request2_Response $response, Net_URL2 $setter)
|
||||
{
|
||||
foreach ($response->getCookies() as $cookie) {
|
||||
$this->store($cookie, $setter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cookies matching a given request URL
|
||||
*
|
||||
* The following checks are made:
|
||||
* - cookie domain should match request host
|
||||
* - cookie path should be a prefix for request path
|
||||
* - 'secure' cookies will only be sent for HTTPS requests
|
||||
*
|
||||
* @param Net_URL2 $url Request url
|
||||
* @param bool $asString Whether to return cookies as string for "Cookie: " header
|
||||
*
|
||||
* @return array|string Matching cookies
|
||||
*/
|
||||
public function getMatching(Net_URL2 $url, $asString = false)
|
||||
{
|
||||
$host = $url->getHost();
|
||||
$path = $url->getPath();
|
||||
$secure = 0 == strcasecmp($url->getScheme(), 'https');
|
||||
|
||||
$matched = $ret = array();
|
||||
foreach (array_keys($this->cookies) as $domain) {
|
||||
if ($this->domainMatch($host, $domain)) {
|
||||
foreach (array_keys($this->cookies[$domain]) as $cPath) {
|
||||
if (0 === strpos($path, $cPath)) {
|
||||
foreach ($this->cookies[$domain][$cPath] as $name => $cookie) {
|
||||
if (!$cookie['secure'] || $secure) {
|
||||
$matched[$name][strlen($cookie['path'])] = $cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($matched as $cookies) {
|
||||
krsort($cookies);
|
||||
$ret = array_merge($ret, $cookies);
|
||||
}
|
||||
if (!$asString) {
|
||||
return $ret;
|
||||
} else {
|
||||
$str = '';
|
||||
foreach ($ret as $c) {
|
||||
$str .= (empty($str)? '': '; ') . $c['name'] . '=' . $c['value'];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cookies stored in a jar
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
$cookies = array();
|
||||
foreach (array_keys($this->cookies) as $domain) {
|
||||
foreach (array_keys($this->cookies[$domain]) as $path) {
|
||||
foreach ($this->cookies[$domain][$path] as $name => $cookie) {
|
||||
$cookies[] = $cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether session cookies should be serialized when serializing the jar
|
||||
*
|
||||
* @param boolean $serialize serialize?
|
||||
*/
|
||||
public function serializeSessionCookies($serialize)
|
||||
{
|
||||
$this->serializeSession = (bool)$serialize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether Public Suffix List should be used for restricting cookie-setting
|
||||
*
|
||||
* Without PSL {@link domainMatch()} will only prevent setting cookies for
|
||||
* top-level domains like '.com' or '.org'. However, it will not prevent
|
||||
* setting a cookie for '.co.uk' even though only third-level registrations
|
||||
* are possible in .uk domain.
|
||||
*
|
||||
* With the List it is possible to find the highest level at which a domain
|
||||
* may be registered for a particular top-level domain and consequently
|
||||
* prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by
|
||||
* Firefox, Chrome and Opera browsers to restrict cookie setting.
|
||||
*
|
||||
* Note that PSL is licensed differently to HTTP_Request2 package (refer to
|
||||
* the license information in public-suffix-list.php), so you can disable
|
||||
* its use if this is an issue for you.
|
||||
*
|
||||
* @param boolean $useList use the list?
|
||||
*
|
||||
* @link http://publicsuffix.org/learn/
|
||||
*/
|
||||
public function usePublicSuffixList($useList)
|
||||
{
|
||||
$this->useList = (bool)$useList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation of object
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see Serializable::serialize()
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
$cookies = $this->getAll();
|
||||
if (!$this->serializeSession) {
|
||||
for ($i = count($cookies) - 1; $i >= 0; $i--) {
|
||||
if (empty($cookies[$i]['expires'])) {
|
||||
unset($cookies[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return serialize(array(
|
||||
'cookies' => $cookies,
|
||||
'serializeSession' => $this->serializeSession,
|
||||
'useList' => $this->useList
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object from serialized string
|
||||
*
|
||||
* @param string $serialized string representation
|
||||
*
|
||||
* @see Serializable::unserialize()
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$data = unserialize($serialized);
|
||||
$now = $this->now();
|
||||
$this->serializeSessionCookies($data['serializeSession']);
|
||||
$this->usePublicSuffixList($data['useList']);
|
||||
foreach ($data['cookies'] as $cookie) {
|
||||
if (!empty($cookie['expires']) && $cookie['expires'] <= $now) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']])) {
|
||||
$this->cookies[$cookie['domain']] = array();
|
||||
}
|
||||
if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
|
||||
$this->cookies[$cookie['domain']][$cookie['path']] = array();
|
||||
}
|
||||
$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a cookie domain matches a request host.
|
||||
*
|
||||
* The method is used by {@link store()} to check for whether a document
|
||||
* at given URL can set a cookie with a given domain attribute and by
|
||||
* {@link getMatching()} to find cookies matching the request URL.
|
||||
*
|
||||
* @param string $requestHost request host
|
||||
* @param string $cookieDomain cookie domain
|
||||
*
|
||||
* @return bool match success
|
||||
*/
|
||||
public function domainMatch($requestHost, $cookieDomain)
|
||||
{
|
||||
if ($requestHost == $cookieDomain) {
|
||||
return true;
|
||||
}
|
||||
// IP address, we require exact match
|
||||
if (preg_match('/^(?:\d{1,3}\.){3}\d{1,3}$/', $requestHost)) {
|
||||
return false;
|
||||
}
|
||||
if ('.' != $cookieDomain[0]) {
|
||||
$cookieDomain = '.' . $cookieDomain;
|
||||
}
|
||||
// prevents setting cookies for '.com' and similar domains
|
||||
if (!$this->useList && substr_count($cookieDomain, '.') < 2
|
||||
|| $this->useList && !self::getRegisteredDomain($cookieDomain)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return substr('.' . $requestHost, -strlen($cookieDomain)) == $cookieDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes subdomains to get the registered domain (the first after top-level)
|
||||
*
|
||||
* The method will check Public Suffix List to find out where top-level
|
||||
* domain ends and registered domain starts. It will remove domain parts
|
||||
* to the left of registered one.
|
||||
*
|
||||
* @param string $domain domain name
|
||||
*
|
||||
* @return string|bool registered domain, will return false if $domain is
|
||||
* either invalid or a TLD itself
|
||||
*/
|
||||
public static function getRegisteredDomain($domain)
|
||||
{
|
||||
$domainParts = explode('.', ltrim($domain, '.'));
|
||||
|
||||
// load the list if needed
|
||||
if (empty(self::$psl)) {
|
||||
$path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
|
||||
if (0 === strpos($path, '@' . 'data_dir@')) {
|
||||
$path = realpath(
|
||||
dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
|
||||
. DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
|
||||
);
|
||||
}
|
||||
self::$psl = include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php';
|
||||
}
|
||||
|
||||
if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
|
||||
// known TLD, invalid domain name
|
||||
return false;
|
||||
}
|
||||
|
||||
// unknown TLD
|
||||
if (!strpos($result, '.')) {
|
||||
// fallback to checking that domain "has at least two dots"
|
||||
if (2 > ($count = count($domainParts))) {
|
||||
return false;
|
||||
}
|
||||
return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive helper method for {@link getRegisteredDomain()}
|
||||
*
|
||||
* @param array $domainParts remaining domain parts
|
||||
* @param mixed $listNode node in {@link HTTP_Request2_CookieJar::$psl} to check
|
||||
*
|
||||
* @return string|null concatenated domain parts, null in case of error
|
||||
*/
|
||||
protected static function checkDomainsList(array $domainParts, $listNode)
|
||||
{
|
||||
$sub = array_pop($domainParts);
|
||||
$result = null;
|
||||
|
||||
if (!is_array($listNode) || is_null($sub)
|
||||
|| array_key_exists('!' . $sub, $listNode)
|
||||
) {
|
||||
return $sub;
|
||||
|
||||
} elseif (array_key_exists($sub, $listNode)) {
|
||||
$result = self::checkDomainsList($domainParts, $listNode[$sub]);
|
||||
|
||||
} elseif (array_key_exists('*', $listNode)) {
|
||||
$result = self::checkDomainsList($domainParts, $listNode['*']);
|
||||
|
||||
} else {
|
||||
return $sub;
|
||||
}
|
||||
|
||||
return (strlen($result) > 0) ? ($result . '.' . $sub) : null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception classes for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for exceptions in PEAR
|
||||
*/
|
||||
require_once 'PEAR/Exception.php';
|
||||
|
||||
/**
|
||||
* Base exception class for HTTP_Request2 package
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
|
||||
*/
|
||||
class HTTP_Request2_Exception extends PEAR_Exception
|
||||
{
|
||||
/** An invalid argument was passed to a method */
|
||||
const INVALID_ARGUMENT = 1;
|
||||
/** Some required value was not available */
|
||||
const MISSING_VALUE = 2;
|
||||
/** Request cannot be processed due to errors in PHP configuration */
|
||||
const MISCONFIGURATION = 3;
|
||||
/** Error reading the local file */
|
||||
const READ_ERROR = 4;
|
||||
|
||||
/** Server returned a response that does not conform to HTTP protocol */
|
||||
const MALFORMED_RESPONSE = 10;
|
||||
/** Failure decoding Content-Encoding or Transfer-Encoding of response */
|
||||
const DECODE_ERROR = 20;
|
||||
/** Operation timed out */
|
||||
const TIMEOUT = 30;
|
||||
/** Number of redirects exceeded 'max_redirects' configuration parameter */
|
||||
const TOO_MANY_REDIRECTS = 40;
|
||||
/** Redirect to a protocol other than http(s):// */
|
||||
const NON_HTTP_REDIRECT = 50;
|
||||
|
||||
/**
|
||||
* Native error code
|
||||
* @var int
|
||||
*/
|
||||
private $_nativeCode;
|
||||
|
||||
/**
|
||||
* Constructor, can set package error code and native error code
|
||||
*
|
||||
* @param string $message exception message
|
||||
* @param int $code package error code, one of class constants
|
||||
* @param int $nativeCode error code from underlying PHP extension
|
||||
*/
|
||||
public function __construct($message = null, $code = null, $nativeCode = null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->_nativeCode = $nativeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns error code produced by underlying PHP extension
|
||||
*
|
||||
* For Socket Adapter this may contain error number returned by
|
||||
* stream_socket_client(), for Curl Adapter this will contain error number
|
||||
* returned by curl_errno()
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getNativeCode()
|
||||
{
|
||||
return $this->_nativeCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown in case of missing features
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception that represents error in the program logic
|
||||
*
|
||||
* This exception usually implies a programmer's error, like passing invalid
|
||||
* data to methods or trying to use PHP extensions that weren't installed or
|
||||
* enabled. Usually exceptions of this kind will be thrown before request even
|
||||
* starts.
|
||||
*
|
||||
* The exception will usually contain a package error code.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_LogicException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when connection to a web or proxy server fails
|
||||
*
|
||||
* The exception will not contain a package error code, but will contain
|
||||
* native error code, as returned by stream_socket_client() or curl_errno().
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when sending or receiving HTTP message fails
|
||||
*
|
||||
* The exception may contain both package error code and native error code.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_MessageException extends HTTP_Request2_Exception
|
||||
{
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for building multipart/form-data request body
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @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
|
||||
*
|
||||
* The class helps to reduce memory consumption by streaming large file uploads
|
||||
* from disk, it also allows monitoring of upload progress (see request #7630)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://tools.ietf.org/html/rfc1867
|
||||
*/
|
||||
class HTTP_Request2_MultipartBody
|
||||
{
|
||||
/**
|
||||
* MIME boundary
|
||||
* @var string
|
||||
*/
|
||||
private $_boundary;
|
||||
|
||||
/**
|
||||
* Form parameters added via {@link HTTP_Request2::addPostParameter()}
|
||||
* @var array
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* File uploads added via {@link HTTP_Request2::addUpload()}
|
||||
* @var array
|
||||
*/
|
||||
private $_uploads = array();
|
||||
|
||||
/**
|
||||
* Header for parts with parameters
|
||||
* @var string
|
||||
*/
|
||||
private $_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Header for parts with uploads
|
||||
* @var string
|
||||
*/
|
||||
private $_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n";
|
||||
|
||||
/**
|
||||
* Current position in parameter and upload arrays
|
||||
*
|
||||
* First number is index of "current" part, second number is position within
|
||||
* "current" part
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_pos = array(0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Sets the arrays with POST data.
|
||||
*
|
||||
* @param array $params values of form fields set via
|
||||
* {@link HTTP_Request2::addPostParameter()}
|
||||
* @param array $uploads file uploads set via
|
||||
* {@link HTTP_Request2::addUpload()}
|
||||
* @param bool $useBrackets whether to append brackets to array variable names
|
||||
*/
|
||||
public function __construct(array $params, array $uploads, $useBrackets = true)
|
||||
{
|
||||
$this->_params = self::_flattenArray('', $params, $useBrackets);
|
||||
foreach ($uploads as $fieldName => $f) {
|
||||
if (!is_array($f['fp'])) {
|
||||
$this->_uploads[] = $f + array('name' => $fieldName);
|
||||
} else {
|
||||
for ($i = 0; $i < count($f['fp']); $i++) {
|
||||
$upload = array(
|
||||
'name' => ($useBrackets? $fieldName . '[' . $i . ']': $fieldName)
|
||||
);
|
||||
foreach (array('fp', 'filename', 'size', 'type') as $key) {
|
||||
$upload[$key] = $f[$key][$i];
|
||||
}
|
||||
$this->_uploads[] = $upload;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the body to use in Content-Length header
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
$boundaryLength = strlen($this->getBoundary());
|
||||
$headerParamLength = strlen($this->_headerParam) - 4 + $boundaryLength;
|
||||
$headerUploadLength = strlen($this->_headerUpload) - 8 + $boundaryLength;
|
||||
$length = $boundaryLength + 6;
|
||||
foreach ($this->_params as $p) {
|
||||
$length += $headerParamLength + strlen($p[0]) + strlen($p[1]) + 2;
|
||||
}
|
||||
foreach ($this->_uploads as $u) {
|
||||
$length += $headerUploadLength + strlen($u['name']) + strlen($u['type']) +
|
||||
strlen($u['filename']) + $u['size'] + 2;
|
||||
}
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boundary to use in Content-Type header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary()
|
||||
{
|
||||
if (empty($this->_boundary)) {
|
||||
$this->_boundary = '--' . md5('PEAR-HTTP_Request2-' . microtime());
|
||||
}
|
||||
return $this->_boundary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next chunk of request body
|
||||
*
|
||||
* @param integer $length Number of bytes to read
|
||||
*
|
||||
* @return string Up to $length bytes of data, empty string if at end
|
||||
* @throws HTTP_Request2_LogicException
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$ret = '';
|
||||
$boundary = $this->getBoundary();
|
||||
$paramCount = count($this->_params);
|
||||
$uploadCount = count($this->_uploads);
|
||||
while ($length > 0 && $this->_pos[0] <= $paramCount + $uploadCount) {
|
||||
$oldLength = $length;
|
||||
if ($this->_pos[0] < $paramCount) {
|
||||
$param = sprintf(
|
||||
$this->_headerParam, $boundary, $this->_params[$this->_pos[0]][0]
|
||||
) . $this->_params[$this->_pos[0]][1] . "\r\n";
|
||||
$ret .= substr($param, $this->_pos[1], $length);
|
||||
$length -= min(strlen($param) - $this->_pos[1], $length);
|
||||
|
||||
} elseif ($this->_pos[0] < $paramCount + $uploadCount) {
|
||||
$pos = $this->_pos[0] - $paramCount;
|
||||
$header = sprintf(
|
||||
$this->_headerUpload, $boundary, $this->_uploads[$pos]['name'],
|
||||
$this->_uploads[$pos]['filename'], $this->_uploads[$pos]['type']
|
||||
);
|
||||
if ($this->_pos[1] < strlen($header)) {
|
||||
$ret .= substr($header, $this->_pos[1], $length);
|
||||
$length -= min(strlen($header) - $this->_pos[1], $length);
|
||||
}
|
||||
$filePos = max(0, $this->_pos[1] - strlen($header));
|
||||
if ($filePos < $this->_uploads[$pos]['size']) {
|
||||
while ($length > 0 && !feof($this->_uploads[$pos]['fp'])) {
|
||||
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) {
|
||||
$start = $this->_pos[1] + ($oldLength - $length) -
|
||||
strlen($header) - $this->_uploads[$pos]['size'];
|
||||
$ret .= substr("\r\n", $start, $length);
|
||||
$length -= min(2 - $start, $length);
|
||||
}
|
||||
|
||||
} else {
|
||||
$closing = '--' . $boundary . "--\r\n";
|
||||
$ret .= substr($closing, $this->_pos[1], $length);
|
||||
$length -= min(strlen($closing) - $this->_pos[1], $length);
|
||||
}
|
||||
if ($length > 0) {
|
||||
$this->_pos = array($this->_pos[0] + 1, 0);
|
||||
} else {
|
||||
$this->_pos[1] += $oldLength;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current position to the start of the body
|
||||
*
|
||||
* This allows reusing the same body in another request
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_pos = array(0, 0);
|
||||
foreach ($this->_uploads as $u) {
|
||||
rewind($u['fp']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body as string
|
||||
*
|
||||
* Note that it reads all file uploads into memory so it is a good idea not
|
||||
* to use this method with large file uploads and rely on read() instead.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$this->rewind();
|
||||
return $this->read($this->getLength());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to change the (probably multidimensional) associative array
|
||||
* into the simple one.
|
||||
*
|
||||
* @param string $name name for item
|
||||
* @param mixed $values item's values
|
||||
* @param bool $useBrackets whether to append [] to array variables' names
|
||||
*
|
||||
* @return array array with the following items: array('item name', 'item value');
|
||||
*/
|
||||
private static function _flattenArray($name, $values, $useBrackets)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
return array(array($name, $values));
|
||||
} else {
|
||||
$ret = array();
|
||||
foreach ($values as $k => $v) {
|
||||
if (empty($name)) {
|
||||
$newName = $k;
|
||||
} elseif ($useBrackets) {
|
||||
$newName = $name . '[' . $k . ']';
|
||||
} else {
|
||||
$newName = $name;
|
||||
}
|
||||
$ret = array_merge($ret, self::_flattenArray($newName, $v, $useBrackets));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* An observer useful for debugging / testing.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* A debug observer useful for debugging / testing.
|
||||
*
|
||||
* This observer logs to a log target data corresponding to the various request
|
||||
* and response events, it logs by default to php://output but can be configured
|
||||
* to log to a file or via the PEAR Log package.
|
||||
*
|
||||
* A simple example:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* $observer = new HTTP_Request2_Observer_Log();
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* A more complex example with PEAR Log:
|
||||
* <code>
|
||||
* require_once 'HTTP/Request2.php';
|
||||
* require_once 'HTTP/Request2/Observer/Log.php';
|
||||
* require_once 'Log.php';
|
||||
*
|
||||
* $request = new HTTP_Request2('http://www.example.com');
|
||||
* // we want to log with PEAR log
|
||||
* $observer = new HTTP_Request2_Observer_Log(Log::factory('console'));
|
||||
*
|
||||
* // we only want to log received headers
|
||||
* $observer->events = array('receivedHeaders');
|
||||
*
|
||||
* $request->attach($observer);
|
||||
* $request->send();
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author David Jean Louis <izi@php.net>
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Observer_Log implements SplObserver
|
||||
{
|
||||
// properties {{{
|
||||
|
||||
/**
|
||||
* The log target, it can be a a resource or a PEAR Log instance.
|
||||
*
|
||||
* @var resource|Log $target
|
||||
*/
|
||||
protected $target = null;
|
||||
|
||||
/**
|
||||
* The events to log.
|
||||
*
|
||||
* @var array $events
|
||||
*/
|
||||
public $events = array(
|
||||
'connect',
|
||||
'sentHeaders',
|
||||
'sentBody',
|
||||
'receivedHeaders',
|
||||
'receivedBody',
|
||||
'disconnect',
|
||||
);
|
||||
|
||||
// }}}
|
||||
// __construct() {{{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $target Can be a file path (default: php://output), a resource,
|
||||
* or an instance of the PEAR Log class.
|
||||
* @param array $events Array of events to listen to (default: all events)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target = 'php://output', array $events = array())
|
||||
{
|
||||
if (!empty($events)) {
|
||||
$this->events = $events;
|
||||
}
|
||||
if (is_resource($target) || $target instanceof Log) {
|
||||
$this->target = $target;
|
||||
} elseif (false === ($this->target = @fopen($target, 'ab'))) {
|
||||
throw new HTTP_Request2_Exception("Unable to open '{$target}'");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// update() {{{
|
||||
|
||||
/**
|
||||
* Called when the request notifies us of an event.
|
||||
*
|
||||
* @param HTTP_Request2 $subject The HTTP_Request2 instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
$event = $subject->getLastEvent();
|
||||
if (!in_array($event['name'], $this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['name']) {
|
||||
case 'connect':
|
||||
$this->log('* Connected to ' . $event['data']);
|
||||
break;
|
||||
case 'sentHeaders':
|
||||
$headers = explode("\r\n", $event['data']);
|
||||
array_pop($headers);
|
||||
foreach ($headers as $header) {
|
||||
$this->log('> ' . $header);
|
||||
}
|
||||
break;
|
||||
case 'sentBody':
|
||||
$this->log('> ' . $event['data'] . ' byte(s) sent');
|
||||
break;
|
||||
case 'receivedHeaders':
|
||||
$this->log(sprintf(
|
||||
'< HTTP/%s %s %s', $event['data']->getVersion(),
|
||||
$event['data']->getStatus(), $event['data']->getReasonPhrase()
|
||||
));
|
||||
$headers = $event['data']->getHeader();
|
||||
foreach ($headers as $key => $val) {
|
||||
$this->log('< ' . $key . ': ' . $val);
|
||||
}
|
||||
$this->log('< ');
|
||||
break;
|
||||
case 'receivedBody':
|
||||
$this->log($event['data']->getBody());
|
||||
break;
|
||||
case 'disconnect':
|
||||
$this->log('* Disconnected');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
// log() {{{
|
||||
|
||||
/**
|
||||
* Logs the given message to the configured target.
|
||||
*
|
||||
* @param string $message Message to display
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if ($this->target instanceof Log) {
|
||||
$this->target->debug($message);
|
||||
} elseif (is_resource($this->target)) {
|
||||
fwrite($this->target, $message . "\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
?>
|
||||
631
vendor/pear/http_request2/HTTP/Request2/Response.php
vendored
631
vendor/pear/http_request2/HTTP/Request2/Response.php
vendored
|
|
@ -1,631 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class for HTTP_Request2 package
|
||||
*/
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*
|
||||
* The class is designed to be used in "streaming" scenario, building the
|
||||
* response as it is being received:
|
||||
* <code>
|
||||
* $statusLine = read_status_line();
|
||||
* $response = new HTTP_Request2_Response($statusLine);
|
||||
* do {
|
||||
* $headerLine = read_header_line();
|
||||
* $response->parseHeaderLine($headerLine);
|
||||
* } while ($headerLine != '');
|
||||
*
|
||||
* while ($chunk = read_body()) {
|
||||
* $response->appendBody($chunk);
|
||||
* }
|
||||
*
|
||||
* var_dump($response->getHeader(), $response->getCookies(), $response->getBody());
|
||||
* </code>
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6
|
||||
*/
|
||||
class HTTP_Request2_Response
|
||||
{
|
||||
/**
|
||||
* HTTP protocol version (e.g. 1.0, 1.1)
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
* @var integer
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
* @var string
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-6.1.1
|
||||
*/
|
||||
protected $reasonPhrase;
|
||||
|
||||
/**
|
||||
* Effective URL (may be different from original request URL in case of redirects)
|
||||
* @var string
|
||||
*/
|
||||
protected $effectiveUrl;
|
||||
|
||||
/**
|
||||
* Associative array of response headers
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Cookies set in the response
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = array();
|
||||
|
||||
/**
|
||||
* Name of last header processed by parseHederLine()
|
||||
*
|
||||
* Used to handle the headers that span multiple lines
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastHeader = null;
|
||||
|
||||
/**
|
||||
* Response body
|
||||
* @var string
|
||||
*/
|
||||
protected $body = '';
|
||||
|
||||
/**
|
||||
* Whether the body is still encoded by Content-Encoding
|
||||
*
|
||||
* cURL provides the decoded body to the callback; if we are reading from
|
||||
* socket the body is still gzipped / deflated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $bodyEncoded;
|
||||
|
||||
/**
|
||||
* Associative array of HTTP status code / reason phrase.
|
||||
*
|
||||
* @var array
|
||||
* @link http://tools.ietf.org/html/rfc2616#section-10
|
||||
*/
|
||||
protected static $phrases = array(
|
||||
|
||||
// 1xx: Informational - Request received, continuing process
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
// 2xx: Success - The action was successfully received, understood and
|
||||
// accepted
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
// 3xx: Redirection - Further action must be taken in order to complete
|
||||
// the request
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found', // 1.1
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
// 4xx: Client Error - The request contains bad syntax or cannot be
|
||||
// fulfilled
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
|
||||
// 5xx: Server Error - The server failed to fulfill an apparently
|
||||
// valid request
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
509 => 'Bandwidth Limit Exceeded',
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the default reason phrase for the given code or all reason phrases
|
||||
*
|
||||
* @param int $code Response code
|
||||
*
|
||||
* @return string|array|null Default reason phrase for $code if $code is given
|
||||
* (null if no phrase is available), array of all
|
||||
* reason phrases if $code is null
|
||||
* @link http://pear.php.net/bugs/18716
|
||||
*/
|
||||
public static function getDefaultReasonPhrase($code = null)
|
||||
{
|
||||
if (null === $code) {
|
||||
return self::$phrases;
|
||||
} else {
|
||||
return isset(self::$phrases[$code]) ? self::$phrases[$code] : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, parses the response status line
|
||||
*
|
||||
* @param string $statusLine Response status line (e.g. "HTTP/1.1 200 OK")
|
||||
* @param bool $bodyEncoded Whether body is still encoded by Content-Encoding
|
||||
* @param string $effectiveUrl Effective URL of the response
|
||||
*
|
||||
* @throws HTTP_Request2_MessageException if status line is invalid according to spec
|
||||
*/
|
||||
public function __construct($statusLine, $bodyEncoded = true, $effectiveUrl = null)
|
||||
{
|
||||
if (!preg_match('!^HTTP/(\d\.\d) (\d{3})(?: (.+))?!', $statusLine, $m)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Malformed response: {$statusLine}",
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
$this->version = $m[1];
|
||||
$this->code = intval($m[2]);
|
||||
$this->reasonPhrase = !empty($m[3]) ? trim($m[3]) : self::getDefaultReasonPhrase($this->code);
|
||||
$this->bodyEncoded = (bool)$bodyEncoded;
|
||||
$this->effectiveUrl = (string)$effectiveUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the line from HTTP response filling $headers array
|
||||
*
|
||||
* The method should be called after reading the line from socket or receiving
|
||||
* it into cURL callback. Passing an empty string here indicates the end of
|
||||
* response headers and triggers additional processing, so be sure to pass an
|
||||
* empty string in the end.
|
||||
*
|
||||
* @param string $headerLine Line from HTTP response
|
||||
*/
|
||||
public function parseHeaderLine($headerLine)
|
||||
{
|
||||
$headerLine = trim($headerLine, "\r\n");
|
||||
|
||||
if ('' == $headerLine) {
|
||||
// empty string signals the end of headers, process the received ones
|
||||
if (!empty($this->headers['set-cookie'])) {
|
||||
$cookies = is_array($this->headers['set-cookie'])?
|
||||
$this->headers['set-cookie']:
|
||||
array($this->headers['set-cookie']);
|
||||
foreach ($cookies as $cookieString) {
|
||||
$this->parseCookie($cookieString);
|
||||
}
|
||||
unset($this->headers['set-cookie']);
|
||||
}
|
||||
foreach (array_keys($this->headers) as $k) {
|
||||
if (is_array($this->headers[$k])) {
|
||||
$this->headers[$k] = implode(', ', $this->headers[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (preg_match('!^([^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+):(.+)$!', $headerLine, $m)) {
|
||||
// string of the form header-name: header value
|
||||
$name = strtolower($m[1]);
|
||||
$value = trim($m[2]);
|
||||
if (empty($this->headers[$name])) {
|
||||
$this->headers[$name] = $value;
|
||||
} else {
|
||||
if (!is_array($this->headers[$name])) {
|
||||
$this->headers[$name] = array($this->headers[$name]);
|
||||
}
|
||||
$this->headers[$name][] = $value;
|
||||
}
|
||||
$this->lastHeader = $name;
|
||||
|
||||
} elseif (preg_match('!^\s+(.+)$!', $headerLine, $m) && $this->lastHeader) {
|
||||
// continuation of a previous header
|
||||
if (!is_array($this->headers[$this->lastHeader])) {
|
||||
$this->headers[$this->lastHeader] .= ' ' . trim($m[1]);
|
||||
} else {
|
||||
$key = count($this->headers[$this->lastHeader]) - 1;
|
||||
$this->headers[$this->lastHeader][$key] .= ' ' . trim($m[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Set-Cookie header to fill $cookies array
|
||||
*
|
||||
* @param string $cookieString value of Set-Cookie header
|
||||
*
|
||||
* @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
|
||||
*/
|
||||
protected function parseCookie($cookieString)
|
||||
{
|
||||
$cookie = array(
|
||||
'expires' => null,
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
'secure' => false
|
||||
);
|
||||
|
||||
if (!strpos($cookieString, ';')) {
|
||||
// Only a name=value pair
|
||||
$pos = strpos($cookieString, '=');
|
||||
$cookie['name'] = trim(substr($cookieString, 0, $pos));
|
||||
$cookie['value'] = trim(substr($cookieString, $pos + 1));
|
||||
|
||||
} else {
|
||||
// Some optional parameters are supplied
|
||||
$elements = explode(';', $cookieString);
|
||||
$pos = strpos($elements[0], '=');
|
||||
$cookie['name'] = trim(substr($elements[0], 0, $pos));
|
||||
$cookie['value'] = trim(substr($elements[0], $pos + 1));
|
||||
|
||||
for ($i = 1; $i < count($elements); $i++) {
|
||||
if (false === strpos($elements[$i], '=')) {
|
||||
$elName = trim($elements[$i]);
|
||||
$elValue = null;
|
||||
} else {
|
||||
list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
|
||||
}
|
||||
$elName = strtolower($elName);
|
||||
if ('secure' == $elName) {
|
||||
$cookie['secure'] = true;
|
||||
} elseif ('expires' == $elName) {
|
||||
$cookie['expires'] = str_replace('"', '', $elValue);
|
||||
} elseif ('path' == $elName || 'domain' == $elName) {
|
||||
$cookie[$elName] = urldecode($elValue);
|
||||
} else {
|
||||
$cookie[$elName] = $elValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cookies[] = $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string to the response body
|
||||
*
|
||||
* @param string $bodyChunk part of response body
|
||||
*/
|
||||
public function appendBody($bodyChunk)
|
||||
{
|
||||
$this->body .= $bodyChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective URL of the response
|
||||
*
|
||||
* This may be different from the request URL if redirects were followed.
|
||||
*
|
||||
* @return string
|
||||
* @link http://pear.php.net/bugs/bug.php?id=18412
|
||||
*/
|
||||
public function getEffectiveUrl()
|
||||
{
|
||||
return $this->effectiveUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reason phrase
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
{
|
||||
return $this->reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether response is a redirect that can be automatically handled by HTTP_Request2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedirect()
|
||||
{
|
||||
return in_array($this->code, array(300, 301, 302, 303, 307))
|
||||
&& isset($this->headers['location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either the named header or all response headers
|
||||
*
|
||||
* @param string $headerName Name of header to return
|
||||
*
|
||||
* @return string|array Value of $headerName header (null if header is
|
||||
* not present), array of all response headers if
|
||||
* $headerName is null
|
||||
*/
|
||||
public function getHeader($headerName = null)
|
||||
{
|
||||
if (null === $headerName) {
|
||||
return $this->headers;
|
||||
} else {
|
||||
$headerName = strtolower($headerName);
|
||||
return isset($this->headers[$headerName])? $this->headers[$headerName]: null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cookies set in response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCookies()
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the response
|
||||
*
|
||||
* @return string
|
||||
* @throws HTTP_Request2_Exception if body cannot be decoded
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (0 == strlen($this->body) || !$this->bodyEncoded
|
||||
|| !in_array(strtolower($this->getHeader('content-encoding')), array('gzip', 'deflate'))
|
||||
) {
|
||||
return $this->body;
|
||||
|
||||
} else {
|
||||
if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
|
||||
$oldEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
|
||||
try {
|
||||
switch (strtolower($this->getHeader('content-encoding'))) {
|
||||
case 'gzip':
|
||||
$decoded = self::decodeGzip($this->body);
|
||||
break;
|
||||
case 'deflate':
|
||||
$decoded = self::decodeDeflate($this->body);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!empty($oldEncoding)) {
|
||||
mb_internal_encoding($oldEncoding);
|
||||
}
|
||||
if (!empty($e)) {
|
||||
throw $e;
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP version of the response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by gzip
|
||||
*
|
||||
* The real decoding work is done by gzinflate() built-in function, this
|
||||
* method only parses the header and checks data for compliance with
|
||||
* RFC 1952
|
||||
*
|
||||
* @param string $data gzip-encoded data
|
||||
*
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
*/
|
||||
public static function decodeGzip($data)
|
||||
{
|
||||
$length = strlen($data);
|
||||
// If it doesn't look like gzip-encoded data, don't bother
|
||||
if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
|
||||
return $data;
|
||||
}
|
||||
if (!function_exists('gzinflate')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Unable to decode body: gzip extension not available',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
$method = ord(substr($data, 2, 1));
|
||||
if (8 != $method) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: unknown compression method',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$flags = ord(substr($data, 3, 1));
|
||||
if ($flags & 224) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: reserved bits are set',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
// header is 10 bytes minimum. may be longer, though.
|
||||
$headerLength = 10;
|
||||
// extra fields, need to skip 'em
|
||||
if ($flags & 4) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$extraLength = unpack('v', substr($data, 10, 2));
|
||||
if ($length - $headerLength - 2 - $extraLength[1] < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $extraLength[1] + 2;
|
||||
}
|
||||
// file name, need to skip that
|
||||
if ($flags & 8) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$filenameLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $filenameLength + 1;
|
||||
}
|
||||
// comment, need to skip that also
|
||||
if ($flags & 16) {
|
||||
if ($length - $headerLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$commentLength = strpos(substr($data, $headerLength), chr(0));
|
||||
if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += $commentLength + 1;
|
||||
}
|
||||
// have a CRC for header. let's check
|
||||
if ($flags & 2) {
|
||||
if ($length - $headerLength - 2 < 8) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Error parsing gzip header: data too short',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$crcReal = 0xffff & crc32(substr($data, 0, $headerLength));
|
||||
$crcStored = unpack('v', substr($data, $headerLength, 2));
|
||||
if ($crcReal != $crcStored[1]) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Header CRC check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
$headerLength += 2;
|
||||
}
|
||||
// unpacked data CRC and size at the end of encoded data
|
||||
$tmp = unpack('V2', substr($data, -8));
|
||||
$dataCrc = $tmp[1];
|
||||
$dataSize = $tmp[2];
|
||||
|
||||
// finally, call the gzinflate() function
|
||||
// don't pass $dataSize to gzinflate, see bugs #13135, #14370
|
||||
$unpacked = gzinflate(substr($data, $headerLength, -8));
|
||||
if (false === $unpacked) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'gzinflate() call failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
} elseif ($dataSize != strlen($unpacked)) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Data size check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
} elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
|
||||
throw new HTTP_Request2_Exception(
|
||||
'Data CRC check failed',
|
||||
HTTP_Request2_Exception::DECODE_ERROR
|
||||
);
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the message-body encoded by deflate
|
||||
*
|
||||
* @param string $data deflate-encoded data
|
||||
*
|
||||
* @return string decoded data
|
||||
* @throws HTTP_Request2_LogicException
|
||||
*/
|
||||
public static function decodeDeflate($data)
|
||||
{
|
||||
if (!function_exists('gzuncompress')) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
'Unable to decode body: gzip extension not available',
|
||||
HTTP_Request2_Exception::MISCONFIGURATION
|
||||
);
|
||||
}
|
||||
// RFC 2616 defines 'deflate' encoding as zlib format from RFC 1950,
|
||||
// while many applications send raw deflate stream from RFC 1951.
|
||||
// We should check for presence of zlib header and use gzuncompress() or
|
||||
// gzinflate() as needed. See bug #15305
|
||||
$header = unpack('n', substr($data, 0, 2));
|
||||
return (0 == $header[1] % 31)? gzuncompress($data): gzinflate($data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
135
vendor/pear/http_request2/HTTP/Request2/SOCKS5.php
vendored
135
vendor/pear/http_request2/HTTP/Request2/SOCKS5.php
vendored
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* SOCKS5 proxy connection class
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Socket wrapper class used by Socket Adapter */
|
||||
require_once 'HTTP/Request2/SocketWrapper.php';
|
||||
|
||||
/**
|
||||
* SOCKS5 proxy connection class (used by Socket Adapter)
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19332
|
||||
* @link http://tools.ietf.org/html/rfc1928
|
||||
*/
|
||||
class HTTP_Request2_SOCKS5 extends HTTP_Request2_SocketWrapper
|
||||
{
|
||||
/**
|
||||
* Constructor, tries to connect and authenticate to a SOCKS5 proxy
|
||||
*
|
||||
* @param string $address Proxy address, e.g. 'tcp://localhost:1080'
|
||||
* @param int $timeout Connection timeout (seconds)
|
||||
* @param array $contextOptions Stream context options
|
||||
* @param string $username Proxy user name
|
||||
* @param string $password Proxy password
|
||||
*
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function __construct(
|
||||
$address, $timeout = 10, array $contextOptions = array(),
|
||||
$username = null, $password = null
|
||||
) {
|
||||
parent::__construct($address, $timeout, $contextOptions);
|
||||
|
||||
if (strlen($username)) {
|
||||
$request = pack('C4', 5, 2, 0, 2);
|
||||
} else {
|
||||
$request = pack('C3', 5, 1, 0);
|
||||
}
|
||||
$this->write($request);
|
||||
$response = unpack('Cversion/Cmethod', $this->read(3));
|
||||
if (5 != $response['version']) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Invalid version received from SOCKS5 proxy: ' . $response['version'],
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
}
|
||||
switch ($response['method']) {
|
||||
case 2:
|
||||
$this->performAuthentication($username, $password);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Connection rejected by proxy due to unsupported auth method"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs username/password authentication for SOCKS5
|
||||
*
|
||||
* @param string $username Proxy user name
|
||||
* @param string $password Proxy password
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
* @link http://tools.ietf.org/html/rfc1929
|
||||
*/
|
||||
protected function performAuthentication($username, $password)
|
||||
{
|
||||
$request = pack('C2', 1, strlen($username)) . $username
|
||||
. pack('C', strlen($password)) . $password;
|
||||
|
||||
$this->write($request);
|
||||
$response = unpack('Cvn/Cstatus', $this->read(3));
|
||||
if (1 != $response['vn'] || 0 != $response['status']) {
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
'Connection rejected by proxy due to invalid username and/or password'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to a remote host via proxy
|
||||
*
|
||||
* @param string $remoteHost Remote host
|
||||
* @param int $remotePort Remote port
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function connect($remoteHost, $remotePort)
|
||||
{
|
||||
$request = pack('C5', 0x05, 0x01, 0x00, 0x03, strlen($remoteHost))
|
||||
. $remoteHost . pack('n', $remotePort);
|
||||
|
||||
$this->write($request);
|
||||
$response = unpack('Cversion/Creply/Creserved', $this->read(1024));
|
||||
if (5 != $response['version'] || 0 != $response['reserved']) {
|
||||
throw new HTTP_Request2_MessageException(
|
||||
'Invalid response received from SOCKS5 proxy',
|
||||
HTTP_Request2_Exception::MALFORMED_RESPONSE
|
||||
);
|
||||
} elseif (0 != $response['reply']) {
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Unable to connect to {$remoteHost}:{$remotePort} through SOCKS5 proxy",
|
||||
0, $response['reply']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,297 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Socket wrapper class used by Socket Adapter
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Exception classes for HTTP_Request2 package */
|
||||
require_once 'HTTP/Request2/Exception.php';
|
||||
|
||||
/**
|
||||
* Socket wrapper class used by Socket Adapter
|
||||
*
|
||||
* Needed to properly handle connection errors, global timeout support and
|
||||
* similar things. Loosely based on Net_Socket used by older HTTP_Request.
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19332
|
||||
* @link http://tools.ietf.org/html/rfc1928
|
||||
*/
|
||||
class HTTP_Request2_SocketWrapper
|
||||
{
|
||||
/**
|
||||
* PHP warning messages raised during stream_socket_client() call
|
||||
* @var array
|
||||
*/
|
||||
protected $connectionWarnings = array();
|
||||
|
||||
/**
|
||||
* Connected socket
|
||||
* @var resource
|
||||
*/
|
||||
protected $socket;
|
||||
|
||||
/**
|
||||
* Sum of start time and global timeout, exception will be thrown if request continues past this time
|
||||
* @var integer
|
||||
*/
|
||||
protected $deadline;
|
||||
|
||||
/**
|
||||
* Global timeout value, mostly for exception messages
|
||||
* @var integer
|
||||
*/
|
||||
protected $timeout;
|
||||
|
||||
/**
|
||||
* Class constructor, tries to establish connection
|
||||
*
|
||||
* @param string $address Address for stream_socket_client() call,
|
||||
* e.g. 'tcp://localhost:80'
|
||||
* @param int $timeout Connection timeout (seconds)
|
||||
* @param array $contextOptions Context options
|
||||
*
|
||||
* @throws HTTP_Request2_LogicException
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
*/
|
||||
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();
|
||||
foreach ($contextOptions as $wrapper => $options) {
|
||||
foreach ($options as $name => $value) {
|
||||
if (!stream_context_set_option($context, $wrapper, $name, $value)) {
|
||||
throw new HTTP_Request2_LogicException(
|
||||
"Error setting '{$wrapper}' wrapper context option '{$name}'"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
set_error_handler(array($this, 'connectionWarningsHandler'));
|
||||
$this->socket = stream_socket_client(
|
||||
$address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context
|
||||
);
|
||||
restore_error_handler();
|
||||
// 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);
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
"Unable to connect to {$address}. Error: {$error}", 0, $errno
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor, disconnects socket
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
fclose($this->socket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fread(), handles global request timeout
|
||||
*
|
||||
* @param int $length Reads up to this number of bytes
|
||||
*
|
||||
* @return string Data read from socket
|
||||
* @throws HTTP_Request2_MessageException In case of timeout
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
$data = fread($this->socket, $length);
|
||||
$this->checkTimeout();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads until either the end of the socket or a newline, whichever comes first
|
||||
*
|
||||
* Strips the trailing newline from the returned data, handles global
|
||||
* request timeout. Method idea borrowed from Net_Socket PEAR package.
|
||||
*
|
||||
* @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)
|
||||
* @throws HTTP_Request2_MessageException In case of timeout
|
||||
*/
|
||||
public function readLine($bufferSize, $localTimeout = null)
|
||||
{
|
||||
$line = '';
|
||||
while (!feof($this->socket)) {
|
||||
if (null !== $localTimeout) {
|
||||
stream_set_timeout($this->socket, $localTimeout);
|
||||
} elseif ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
|
||||
$line .= @fgets($this->socket, $bufferSize);
|
||||
|
||||
if (null === $localTimeout) {
|
||||
$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") {
|
||||
return rtrim($line, "\r\n");
|
||||
}
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fwrite(), handles global request timeout
|
||||
*
|
||||
* @param string $data String to be written
|
||||
*
|
||||
* @return int
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
public function write($data)
|
||||
{
|
||||
if ($this->deadline) {
|
||||
stream_set_timeout($this->socket, max($this->deadline - time(), 1));
|
||||
}
|
||||
$written = fwrite($this->socket, $data);
|
||||
$this->checkTimeout();
|
||||
// http://www.php.net/manual/en/function.fwrite.php#96951
|
||||
if ($written < strlen($data)) {
|
||||
throw new HTTP_Request2_MessageException('Error writing request');
|
||||
}
|
||||
return $written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for end-of-file on a socket
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function eof()
|
||||
{
|
||||
return feof($this->socket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request deadline
|
||||
*
|
||||
* @param int $deadline Exception will be thrown if request continues
|
||||
* past this time
|
||||
* @param int $timeout Original request timeout value, to use in
|
||||
* Exception message
|
||||
*/
|
||||
public function setDeadline($deadline, $timeout)
|
||||
{
|
||||
$this->deadline = $deadline;
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on encryption on a socket
|
||||
*
|
||||
* @throws HTTP_Request2_ConnectionException
|
||||
*/
|
||||
public function enableCrypto()
|
||||
{
|
||||
$modes = array(
|
||||
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
||||
);
|
||||
|
||||
foreach ($modes as $mode) {
|
||||
if (stream_socket_enable_crypto($this->socket, true, $mode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new HTTP_Request2_ConnectionException(
|
||||
'Failed to enable secure connection when connecting through proxy'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an Exception if stream timed out
|
||||
*
|
||||
* @throws HTTP_Request2_MessageException
|
||||
*/
|
||||
protected function checkTimeout()
|
||||
{
|
||||
$info = stream_get_meta_data($this->socket);
|
||||
if ($info['timed_out'] || $this->deadline && time() > $this->deadline) {
|
||||
$reason = $this->deadline
|
||||
? "after {$this->timeout} second(s)"
|
||||
: 'due to default_socket_timeout php.ini setting';
|
||||
throw new HTTP_Request2_MessageException(
|
||||
"Request timed out {$reason}", HTTP_Request2_Exception::TIMEOUT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler to use during stream_socket_client() call
|
||||
*
|
||||
* One stream_socket_client() call may produce *multiple* PHP warnings
|
||||
* (especially OpenSSL-related), we keep them in an array to later use for
|
||||
* the message of HTTP_Request2_ConnectionException
|
||||
*
|
||||
* @param int $errno error level
|
||||
* @param string $errstr error message
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function connectionWarningsHandler($errno, $errstr)
|
||||
{
|
||||
if ($errno & E_WARNING) {
|
||||
array_unshift($this->connectionWarnings, $errstr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
80
vendor/pear/http_request2/README.md
vendored
80
vendor/pear/http_request2/README.md
vendored
|
|
@ -1,80 +0,0 @@
|
|||
|
||||
# HTTP_Request2
|
||||
|
||||
Provides an easy way to perform HTTP requests, uses pluggable adapters
|
||||
|
||||
* Socket: pure PHP implementation of HTTP protocol (does *not* use http stream wrapper), based on older [PEAR HTTP_Request] package
|
||||
* Curl: wrapper around PHP's cURL extension
|
||||
* Mock: used for testing packages depending on HTTP_Request2, returns predefined responses without network interaction
|
||||
|
||||
Both Socket and Curl adapters support POST requests with data and file uploads, basic and digest
|
||||
authentication, cookies, managing cookies across requests, HTTP and SOCKS5 proxies, gzip and
|
||||
deflate encodings, redirects, monitoring the request progress with Observers...
|
||||
|
||||
This package is [PEAR HTTP_Request2] and has been migrated from [PEAR SVN]
|
||||
|
||||
Please report all issues via the [PEAR bug tracker].
|
||||
|
||||
Pull requests are welcome.
|
||||
|
||||
[PEAR HTTP_Request]: http://pear.php.net/package/HTTP_Request/
|
||||
[PEAR HTTP_Request2]: http://pear.php.net/package/HTTP_Request2/
|
||||
[PEAR SVN]: https://svn.php.net/repository/pear/packages/HTTP_Request2
|
||||
[PEAR bug tracker]: http://pear.php.net/bugs/search.php?cmd=display&package_name[]=HTTP_Request2
|
||||
|
||||
## Basic usage
|
||||
|
||||
```PHP
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
|
||||
try {
|
||||
$response = $request->send();
|
||||
if (200 == $response->getStatus()) {
|
||||
echo $response->getBody();
|
||||
} else {
|
||||
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
|
||||
$response->getReasonPhrase();
|
||||
}
|
||||
} catch (HTTP_Request2_Exception $e) {
|
||||
echo 'Error: ' . $e->getMessage();
|
||||
}
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
...is available on PEAR website
|
||||
|
||||
* Numerous [configuration options](http://pear.php.net/manual/en/package.http.http-request2.config.php)
|
||||
* How to populate [the request object](http://pear.php.net/manual/en/package.http.http-request2.request.php)
|
||||
* Description of [available adapters](http://pear.php.net/manual/en/package.http.http-request2.adapters.php)
|
||||
* Processing of [HTTP response](http://pear.php.net/manual/en/package.http.http-request2.response.php)
|
||||
* Monitoring the progress of request with [observers](http://pear.php.net/manual/en/package.http.http-request2.observers.php)
|
||||
* Possible [exceptions](http://pear.php.net/manual/en/package.http.http-request2.exceptions.php)
|
||||
|
||||
[Generated API documentation](http://pear.php.net/package/HTTP_Request2/docs/latest/) for the current release is also there.
|
||||
|
||||
## Testing, Packaging and Installing (Pear)
|
||||
|
||||
To test, run either
|
||||
|
||||
$ phpunit tests/
|
||||
|
||||
or
|
||||
|
||||
$ pear run-tests -r
|
||||
|
||||
You may need to set up the NetworkConfig.php file if you want to perform tests that interact with a web server.
|
||||
Its template is NetworkConfig.php.dist file, consult it for the details.
|
||||
|
||||
To build, simply
|
||||
|
||||
$ pear package
|
||||
|
||||
To install from scratch
|
||||
|
||||
$ pear install package.xml
|
||||
|
||||
To upgrade
|
||||
|
||||
$ pear upgrade -f package.xml
|
||||
34
vendor/pear/http_request2/composer.json
vendored
34
vendor/pear/http_request2/composer.json
vendored
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"name" : "pear/http_request2",
|
||||
"description" : "Provides an easy way to perform HTTP requests.",
|
||||
"type" : "library",
|
||||
"keywords" : [ "http", "request", "pear", "curl" ],
|
||||
"homepage" : "http://pear.php.net/package/HTTP_Request2",
|
||||
"license" : "BSD-3-Clause",
|
||||
"authors" : [
|
||||
{
|
||||
"name" : "Alexey Borzov",
|
||||
"email" : "avb@php.net"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=HTTP_Request2",
|
||||
"source": "https://github.com/pear/HTTP_Request2"
|
||||
},
|
||||
"require" : {
|
||||
"php" : ">=5.2.0",
|
||||
"pear/net_url2" : ">=2.0.0",
|
||||
"pear/pear_exception" : "*"
|
||||
},
|
||||
"suggest" : {
|
||||
"ext-fileinfo" : "Adds support for looking up mime-types using finfo.",
|
||||
"ext-zlib" : "Allows handling gzip compressed responses.",
|
||||
"lib-curl" : "Allows using cURL as a request backend.",
|
||||
"lib-openssl" : "Allows handling SSL requests when not using cURL."
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"HTTP_Request2" : ""
|
||||
}
|
||||
}
|
||||
}
|
||||
96
vendor/pear/http_request2/data/generate-list.php
vendored
96
vendor/pear/http_request2/data/generate-list.php
vendored
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper file for downloading Public Suffix List and converting it to PHP array
|
||||
*
|
||||
* You can run this script to update PSL to the current version instead of
|
||||
* waiting for a new release of HTTP_Request2.
|
||||
*/
|
||||
|
||||
/** URL to download Public Suffix List from */
|
||||
define('LIST_URL', 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
|
||||
/** Name of PHP file to write */
|
||||
define('OUTPUT_FILE', dirname(__FILE__) . '/public-suffix-list.php');
|
||||
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
function buildSubdomain(&$node, $tldParts)
|
||||
{
|
||||
$part = trim(array_pop($tldParts));
|
||||
|
||||
if (!array_key_exists($part, $node)) {
|
||||
$node[$part] = array();
|
||||
}
|
||||
|
||||
if (0 < count($tldParts)) {
|
||||
buildSubdomain($node[$part], $tldParts);
|
||||
}
|
||||
}
|
||||
|
||||
function writeNode($fp, $valueTree, $key = null, $indent = 0)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
fwrite($fp, "return ");
|
||||
|
||||
} else {
|
||||
fwrite($fp, str_repeat(' ', $indent) . "'$key' => ");
|
||||
}
|
||||
|
||||
if (0 == ($count = count($valueTree))) {
|
||||
fwrite($fp, 'true');
|
||||
} else {
|
||||
fwrite($fp, "array(\n");
|
||||
for ($keys = array_keys($valueTree), $i = 0; $i < $count; $i++) {
|
||||
writeNode($fp, $valueTree[$keys[$i]], $keys[$i], $indent + 1);
|
||||
if ($i + 1 != $count) {
|
||||
fwrite($fp, ",\n");
|
||||
} else {
|
||||
fwrite($fp, "\n");
|
||||
}
|
||||
}
|
||||
fwrite($fp, str_repeat(' ', $indent) . ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$request = new HTTP_Request2(LIST_URL);
|
||||
$response = $request->send();
|
||||
if (200 != $response->getStatus()) {
|
||||
throw new Exception("List download URL returned status: " .
|
||||
$response->getStatus() . ' ' . $response->getReasonPhrase());
|
||||
}
|
||||
$list = $response->getBody();
|
||||
if (false === strpos($list, '// ===BEGIN ICANN DOMAINS===')) {
|
||||
throw new Exception("List download URL does not contain expected phrase");
|
||||
}
|
||||
if (!($fp = @fopen(OUTPUT_FILE, 'wt'))) {
|
||||
throw new Exception("Unable to open " . OUTPUT_FILE);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
$tldTree = array();
|
||||
$license = true;
|
||||
|
||||
fwrite($fp, "<?php\n");
|
||||
|
||||
foreach (array_filter(array_map('trim', explode("\n", $list))) as $line) {
|
||||
if ('//' != substr($line, 0, 2)) {
|
||||
buildSubdomain($tldTree, explode('.', $line));
|
||||
|
||||
} elseif ($license) {
|
||||
if (0 === strpos($line, "// ===BEGIN ICANN DOMAINS===")) {
|
||||
fwrite($fp, "\n");
|
||||
$license = false;
|
||||
} else {
|
||||
fwrite($fp, $line . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeNode($fp, $tldTree);
|
||||
fwrite($fp, ";\n?>");
|
||||
fclose($fp);
|
||||
?>
|
||||
6701
vendor/pear/http_request2/data/public-suffix-list.php
vendored
6701
vendor/pear/http_request2/data/public-suffix-list.php
vendored
File diff suppressed because it is too large
Load diff
31
vendor/pear/http_request2/docs/LICENSE
vendored
31
vendor/pear/http_request2/docs/LICENSE
vendored
|
|
@ -1,31 +0,0 @@
|
|||
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.
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Usage example for HTTP_Request2 package: uploading a file to rapidshare.com
|
||||
*
|
||||
* Inspired by Perl usage example: http://images.rapidshare.com/software/rsapi.pl
|
||||
* Rapidshare API description: http://rapidshare.com/dev.html
|
||||
*/
|
||||
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
// You'll probably want to change this
|
||||
$filename = '/etc/passwd';
|
||||
|
||||
try {
|
||||
// First step: get an available upload server
|
||||
$request = new HTTP_Request2(
|
||||
'http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1'
|
||||
);
|
||||
$server = $request->send()->getBody();
|
||||
if (!preg_match('/^(\\d+)$/', $server)) {
|
||||
throw new Exception("Invalid upload server: {$server}");
|
||||
}
|
||||
|
||||
// Calculate file hash, we'll use it later to check upload
|
||||
if (false === ($hash = @md5_file($filename))) {
|
||||
throw new Exception("Cannot calculate MD5 hash of '{$filename}'");
|
||||
}
|
||||
|
||||
// Second step: upload a file to the available server
|
||||
$uploader = new HTTP_Request2(
|
||||
"http://rs{$server}l3.rapidshare.com/cgi-bin/upload.cgi",
|
||||
HTTP_Request2::METHOD_POST
|
||||
);
|
||||
// Adding the file
|
||||
$uploader->addUpload('filecontent', $filename);
|
||||
// This will tell server to return program-friendly output
|
||||
$uploader->addPostParameter('rsapi_v1', '1');
|
||||
|
||||
$response = $uploader->send()->getBody();
|
||||
if (!preg_match_all('/^(File[^=]+)=(.+)$/m', $response, $m, PREG_SET_ORDER)) {
|
||||
throw new Exception("Invalid response: {$response}");
|
||||
}
|
||||
$rspAry = array();
|
||||
foreach ($m as $item) {
|
||||
$rspAry[$item[1]] = $item[2];
|
||||
}
|
||||
// Check that uploaded file has the same hash
|
||||
if (empty($rspAry['File1.4'])) {
|
||||
throw new Exception("MD5 hash data not found in response");
|
||||
} elseif ($hash != strtolower($rspAry['File1.4'])) {
|
||||
throw new Exception("Upload failed, local MD5 is {$hash}, uploaded MD5 is {$rspAry['File1.4']}");
|
||||
}
|
||||
echo "Upload succeeded\nDownload link: {$rspAry['File1.1']}\nDelete link: {$rspAry['File1.2']}\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
646
vendor/pear/http_request2/package.xml
vendored
646
vendor/pear/http_request2/package.xml
vendored
|
|
@ -1,646 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<package version="2.0"
|
||||
xmlns="http://pear.php.net/dtd/package-2.0"
|
||||
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
|
||||
|
||||
<name>HTTP_Request2</name>
|
||||
<channel>pear.php.net</channel>
|
||||
<extends>HTTP_Request</extends>
|
||||
<summary>Provides an easy way to perform HTTP requests.</summary>
|
||||
<description>
|
||||
PHP5 rewrite of HTTP_Request package (with parts of HTTP_Client). Provides
|
||||
cleaner API and pluggable Adapters:
|
||||
* Socket adapter, based on old HTTP_Request code,
|
||||
* Curl adapter, wraps around PHP's cURL extension,
|
||||
* Mock adapter, to use for testing packages dependent on HTTP_Request2.
|
||||
Supports POST requests with data and file uploads, basic and digest
|
||||
authentication, cookies, managing cookies across requests, proxies, gzip and
|
||||
deflate encodings, redirects, monitoring the request progress with Observers...
|
||||
</description>
|
||||
<lead>
|
||||
<name>Alexey Borzov</name>
|
||||
<user>avb</user>
|
||||
<email>avb@php.net</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<date>2014-01-16</date>
|
||||
<version>
|
||||
<release>2.2.1</release>
|
||||
<api>2.2.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/BSD-3-Clause">BSD 3-Clause License</license>
|
||||
<notes>
|
||||
* Fixed a bogus timeout Exception in Socket adapter after waiting for
|
||||
"100 Continue" response: the same one second timeout was used
|
||||
for further socket operations if explicit 'timeout' parameter was not set.
|
||||
Thanks to Andrea Brancatelli (abrancatelli as schema31 dot it) for the report.
|
||||
* Bundled a separate LICENSE file (request #20175). Updated phrasing and links
|
||||
to mention 3-Clause BSD license the package actually uses.
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
<dir name="HTTP">
|
||||
<dir name="Request2">
|
||||
<dir name="Adapter">
|
||||
<file role="php" name="Curl.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="Mock.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="Socket.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
</dir>
|
||||
<file role="php" name="Adapter.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="CookieJar.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
<tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
|
||||
</file>
|
||||
<file role="php" name="Exception.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="MultipartBody.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="SocketWrapper.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<file role="php" name="SOCKS5.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
<dir name="Observer">
|
||||
<file role="php" name="Log.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
</dir>
|
||||
<file role="php" name="Response.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
</dir>
|
||||
<file role="php" name="Request2.php">
|
||||
<tasks:replace from="@package_version@" to="version" type="package-info" />
|
||||
</file>
|
||||
</dir>
|
||||
<dir name="tests">
|
||||
<dir name="_files">
|
||||
<file role="test" name="bug_15305" />
|
||||
<file role="test" name="bug_18169" />
|
||||
<file role="test" name="empty.gif" />
|
||||
<file role="test" name="plaintext.txt" />
|
||||
<file role="test" name="response_cookies" />
|
||||
<file role="test" name="response_deflate" />
|
||||
<file role="test" name="response_gzip" />
|
||||
<file role="test" name="response_gzip_broken" />
|
||||
<file role="test" name="response_headers" />
|
||||
</dir>
|
||||
<dir name="_network">
|
||||
<file role="test" name="basicauth.php" />
|
||||
<file role="test" name="bug19934.php" />
|
||||
<file role="test" name="cookies.php" />
|
||||
<file role="test" name="digestauth.php" />
|
||||
<file role="test" name="getparameters.php" />
|
||||
<file role="test" name="postparameters.php" />
|
||||
<file role="test" name="rawpostdata.php" />
|
||||
<file role="test" name="redirects.php" />
|
||||
<file role="test" name="setcookie.php" />
|
||||
<file role="test" name="timeout.php" />
|
||||
<file role="test" name="uploads.php" />
|
||||
</dir>
|
||||
<dir name="Request2">
|
||||
<dir name="Adapter">
|
||||
<file role="test" name="AllTests.php" />
|
||||
<file role="test" name="CommonNetworkTest.php" />
|
||||
<file role="test" name="CurlTest.php" />
|
||||
<file role="test" name="MockTest.php" />
|
||||
<file role="test" name="SkippedTests.php" />
|
||||
<file role="test" name="SocketProxyTest.php" />
|
||||
<file role="test" name="SocketTest.php" />
|
||||
</dir>
|
||||
<file role="test" name="AllTests.php" />
|
||||
<file role="test" name="CookieJarTest.php" />
|
||||
<file role="test" name="MultipartBodyTest.php" />
|
||||
<file role="test" name="ResponseTest.php" />
|
||||
</dir>
|
||||
<file role="test" name="AllTests.php" />
|
||||
<file role="test" name="NetworkConfig.php.dist" />
|
||||
<file role="test" name="ObserverTest.php" />
|
||||
<file role="test" name="Request2Test.php" />
|
||||
<file role="test" name="TestHelper.php" />
|
||||
</dir>
|
||||
<dir name="docs">
|
||||
<file role="doc" name="LICENSE" />
|
||||
<file role="doc" name="examples/upload-rapidshare.php" />
|
||||
</dir>
|
||||
<dir name="data">
|
||||
<file role="data" name="generate-list.php" />
|
||||
<file role="data" name="public-suffix-list.php" />
|
||||
</dir>
|
||||
</dir>
|
||||
</contents>
|
||||
<dependencies>
|
||||
<required>
|
||||
<php>
|
||||
<min>5.2.0</min>
|
||||
</php>
|
||||
<pearinstaller>
|
||||
<min>1.9.2</min>
|
||||
</pearinstaller>
|
||||
<package>
|
||||
<name>Net_URL2</name>
|
||||
<channel>pear.php.net</channel>
|
||||
<min>2.0.0</min>
|
||||
</package>
|
||||
<package>
|
||||
<name>PEAR</name>
|
||||
<channel>pear.php.net</channel>
|
||||
<min>1.9.2</min>
|
||||
</package>
|
||||
</required>
|
||||
<optional>
|
||||
<extension>
|
||||
<name>curl</name>
|
||||
</extension>
|
||||
<extension>
|
||||
<name>fileinfo</name>
|
||||
</extension>
|
||||
<extension>
|
||||
<name>zlib</name>
|
||||
</extension>
|
||||
<extension>
|
||||
<name>openssl</name>
|
||||
</extension>
|
||||
</optional>
|
||||
</dependencies>
|
||||
<phprelease>
|
||||
<filelist>
|
||||
<install as="LICENSE" name="docs/LICENSE" />
|
||||
<install as="examples/upload-rapidshare.php" name="docs/examples/upload-rapidshare.php" />
|
||||
|
||||
<install as="generate-list.php" name="data/generate-list.php" />
|
||||
<install as="public-suffix-list.php" name="data/public-suffix-list.php" />
|
||||
|
||||
<install as="AllTests.php" name="tests/AllTests.php" />
|
||||
<install as="NetworkConfig.php.dist" name="tests/NetworkConfig.php.dist" />
|
||||
<install as="ObserverTest.php" name="tests/ObserverTest.php" />
|
||||
<install as="Request2Test.php" name="tests/Request2Test.php" />
|
||||
<install as="TestHelper.php" name="tests/TestHelper.php" />
|
||||
|
||||
<install as="_files/bug_15305" name="tests/_files/bug_15305" />
|
||||
<install as="_files/bug_18169" name="tests/_files/bug_18169" />
|
||||
<install as="_files/empty.gif" name="tests/_files/empty.gif" />
|
||||
<install as="_files/plaintext.txt" name="tests/_files/plaintext.txt" />
|
||||
<install as="_files/response_cookies" name="tests/_files/response_cookies" />
|
||||
<install as="_files/response_deflate" name="tests/_files/response_deflate" />
|
||||
<install as="_files/response_gzip" name="tests/_files/response_gzip" />
|
||||
<install as="_files/response_gzip_broken" name="tests/_files/response_gzip_broken" />
|
||||
<install as="_files/response_headers" name="tests/_files/response_headers" />
|
||||
|
||||
<install as="_network/basicauth.php" name="tests/_network/basicauth.php" />
|
||||
<install as="_network/bug19934.php" name="tests/_network/bug19934.php" />
|
||||
<install as="_network/cookies.php" name="tests/_network/cookies.php" />
|
||||
<install as="_network/digestauth.php" name="tests/_network/digestauth.php" />
|
||||
<install as="_network/getparameters.php" name="tests/_network/getparameters.php" />
|
||||
<install as="_network/postparameters.php" name="tests/_network/postparameters.php" />
|
||||
<install as="_network/rawpostdata.php" name="tests/_network/rawpostdata.php" />
|
||||
<install as="_network/redirects.php" name="tests/_network/redirects.php" />
|
||||
<install as="_network/setcookie.php" name="tests/_network/setcookie.php" />
|
||||
<install as="_network/timeout.php" name="tests/_network/timeout.php" />
|
||||
<install as="_network/uploads.php" name="tests/_network/uploads.php" />
|
||||
|
||||
<install as="Request2/AllTests.php" name="tests/Request2/AllTests.php" />
|
||||
<install as="Request2/CookieJarTest.php" name="tests/Request2/CookieJarTest.php" />
|
||||
<install as="Request2/MultipartBodyTest.php" name="tests/Request2/MultipartBodyTest.php" />
|
||||
<install as="Request2/ResponseTest.php" name="tests/Request2/ResponseTest.php" />
|
||||
|
||||
<install as="Request2/Adapter/AllTests.php" name="tests/Request2/Adapter/AllTests.php" />
|
||||
<install as="Request2/Adapter/CommonNetworkTest.php" name="tests/Request2/Adapter/CommonNetworkTest.php" />
|
||||
<install as="Request2/Adapter/CurlTest.php" name="tests/Request2/Adapter/CurlTest.php" />
|
||||
<install as="Request2/Adapter/MockTest.php" name="tests/Request2/Adapter/MockTest.php" />
|
||||
<install as="Request2/Adapter/SkippedTests.php" name="tests/Request2/Adapter/SkippedTests.php" />
|
||||
<install as="Request2/Adapter/SocketProxyTest.php" name="tests/Request2/Adapter/SocketProxyTest.php" />
|
||||
<install as="Request2/Adapter/SocketTest.php" name="tests/Request2/Adapter/SocketTest.php" />
|
||||
</filelist>
|
||||
</phprelease>
|
||||
<changelog>
|
||||
<release>
|
||||
<date>2014-01-12</date>
|
||||
<version>
|
||||
<release>2.2.0</release>
|
||||
<api>2.2.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
New features
|
||||
* Socket adapter will send "Expect: 100-continue" header and wait for
|
||||
"100 Continue" response by default before sending large request body
|
||||
(request #19233). This can be disabled by setting an empty "Expect"
|
||||
header, the same way as done with Curl adapter (see bug #15937)
|
||||
* It is possible to specify a local IP address to bind to using 'local_ip'
|
||||
configuration parameter (request #19515)
|
||||
|
||||
Other changes and fixes
|
||||
* An infinite loop was possible when using a stream wrapper instead of
|
||||
a regular file with MultipartBody (bug #19934)
|
||||
* Socket adapter will properly send chunked request body if
|
||||
"Transfer-Encoding: chunked" header is set for the request (bug #20125)
|
||||
* Updated Public Suffix List to the latest version and updated its download script
|
||||
* Unit tests fixes
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<date>2012-04-08</date>
|
||||
<version>
|
||||
<release>2.1.1</release>
|
||||
<api>2.1.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
Fixes for SOCKS5 proxies support in Socket adapter
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<date>2012-04-07</date>
|
||||
<version>
|
||||
<release>2.1.0</release>
|
||||
<api>2.1.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
New features:
|
||||
* Mock adapter can return responses based on request URL (request #19276)
|
||||
* Support for SOCKS5 proxies, added 'proxy_type' configuration parameter
|
||||
(request #19332)
|
||||
* Proxy configuration may be given as an URL, e.g.
|
||||
$request->setConfig('proxy', 'socks5://localhost:1080');
|
||||
|
||||
Other changes and fixes:
|
||||
* Coding standards fixes (request #14990)
|
||||
* Unit tests now run from SVN checkout and under PHPUnit 3.6.x
|
||||
* Explicit dependency on PEAR (until PEAR_Exception is a separate package)
|
||||
* Get rid of track_errors, use a more robust solution (bug #19337)
|
||||
* Additional class_exists() check in setAdapter() (request #19344)
|
||||
* Public suffix list updated to current version
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<date>2011-10-20</date>
|
||||
<version>
|
||||
<release>2.0.0</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
2.0.0RC2 repackaged as stable and depending on stable Net_URL2. No code changes.
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<date>2011-10-01</date>
|
||||
<version>
|
||||
<release>2.0.0RC2</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Added an accessor method for HTTP_Request2_Response::$phrases (request #18716)
|
||||
* HTTP_Request2::send() throws an exception if URL is not provided
|
||||
rather than dies with a fatal error (bug #18755)
|
||||
* Public Suffix List updated to current version
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<date>2011-05-06</date>
|
||||
<version>
|
||||
<release>2.0.0RC1</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
SSL options for Curl Adapter are always set, this prevents errors when
|
||||
redirecting from HTTP to HTTPS (bug #18443)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>2.0.0beta3</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
<api>beta</api>
|
||||
</stability>
|
||||
<date>2011-04-03</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Added getEffectiveUrl() method to Response object, it returns the URL
|
||||
response was received from, possibly after redirects (request #18412)
|
||||
* Curl Adapter didn't send body for PUT requests sometimes (bug #18421)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>2.0.0beta2</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
<api>beta</api>
|
||||
</stability>
|
||||
<date>2011-03-25</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Unit tests can now be run under recent PHPUnit versions (3.5+)
|
||||
* Public Suffix List updated to current version
|
||||
* PHP warning produced by stream_socket_client() in Socket adapter is now
|
||||
added to Exception message (bug #18331)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>2.0.0beta1</release>
|
||||
<api>2.0.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>beta</release>
|
||||
<api>beta</api>
|
||||
</stability>
|
||||
<date>2011-02-27</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
Additions and changes:
|
||||
* Implemented cookie jar that allows to store and pass cookies across HTTP
|
||||
requests (see request #18225)
|
||||
* Added several specialized subclasses of HTTP_Request2_Exception, they are
|
||||
now thrown instead of the parent. Also added error codes and possibility
|
||||
to get native error code (as returned by stream_socket_client() and
|
||||
curl_errno()) (request #16762)
|
||||
* An additional 'sentBody' event is now sent to Observers (request #16828)
|
||||
* setBody() and addUpload() can now accept file pointers (request #16863)
|
||||
|
||||
Bugfixes:
|
||||
* Incorrect check in Socket Adapter prevented Keep-alive from working in
|
||||
some cases (bug #17031)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.6.0</release>
|
||||
<api>0.6.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2011-02-14</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
Additions and changes:
|
||||
* Added test suite that interacts with a webserver. Please refer to
|
||||
tests/NetworkConfig.php.dist for instructions.
|
||||
* Packaging changes: docs/ and tests/ contents are installed without
|
||||
redundant subdirectories.
|
||||
* Added a $replace parameter to HTTP_Request2::setHeader() that controls
|
||||
whether new header value will overwrite previous one or be appended
|
||||
to it (request #17507)
|
||||
|
||||
Bugfixes:
|
||||
* Fixed a typo in Curl Adapter that prevented 'strict_redirects' from working
|
||||
* Curl Adapter will throw an exception if CURLOPT_FOLLOWLOCATION can not be
|
||||
enabled due to PHP setup (bug #17450)
|
||||
* Allow parameters in manually set Content-Type headers (bug #17460)
|
||||
* Properly reset redirect limit if multiple requests are performed with the
|
||||
same instance of Socket Adapter (bug #17826)
|
||||
* Response::getBody() no longer tries to decode empty strings (bug #18169)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.5.2</release>
|
||||
<api>0.5.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2010-04-21</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* magic_quotes_runtime PHP setting could be incorrectly enabled after
|
||||
performing the request (bug #16440)
|
||||
* Unit tests fixes (bugs #17079, #17106, #17326)
|
||||
* Observer_Log now appends to the log file rather than rewrites it (thanks to
|
||||
troelskn at gmail dot com for reporting)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.5.1</release>
|
||||
<api>0.5.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-11-21</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Content-Type request header is no longer removed for POST and PUT requests
|
||||
with empty request body (request #16799).
|
||||
* CURLOPT_NOBODY option is now set when doing HEAD requests with Curl adapter.
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.5.0</release>
|
||||
<api>0.5.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-11-18</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Redirect support added, new configuration parameters 'follow_redirects',
|
||||
'max_redirects' and 'strict_redirects' available
|
||||
|
||||
* Implemented workaround for PHP bug #47204, Curl Adapter can now handle
|
||||
Digest authentication and redirects when doing POST requests, unfortunately
|
||||
this requires loading the entire request body into memory.
|
||||
* Config parameter 'use_brackets' is propagated to created instances of Net_URL2
|
||||
* Prevent memory leaks due to circular references (request #16646)
|
||||
* Fixed a misleading error message when timing out due to default_socket_timeout
|
||||
* HTTP_Request2::setBody() can now accept an instance of HTTP_Request2_MultipartBody
|
||||
without trying to convert it to string
|
||||
* Calling HTTP_Request2::setBody() now clears post parameters and uploads
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.4.1</release>
|
||||
<api>0.4.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-09-14</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Decoding of gzipped responses failed if mbstring.func_overload was enabled
|
||||
(bug #16555)
|
||||
* Changed boundary generation in multipart bodies to work correctly with
|
||||
rapidshare.com, added first usage example: file uploading to rapidshare.com
|
||||
* Added forgotten optional dependency on OpenSSL PHP extension
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.4.0</release>
|
||||
<api>0.4.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-05-03</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
* Added 'store_body' config parameter, if set to false it will prevent storing
|
||||
the response body in Response object (request #15881)
|
||||
* HTTP_Request2::setHeader() method now works as documented, setHeader('name')
|
||||
will remove the 'name' header, while setHeader('name', '') will set 'name'
|
||||
header to empty value (bug #15937)
|
||||
* Custom 'Host' header will not be overwritten by generated one (bug #16146)
|
||||
* When trying to reuse the connected socket in Socket adapter, make sure that
|
||||
it is still connected (bug #16149)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.3.0</release>
|
||||
<api>0.3.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-01-28</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
API changes:
|
||||
* Removed HTTP_Request2::getConfigValue() method
|
||||
|
||||
Feature additions:
|
||||
* Added digest authentication (RFC 2617) support to Socket adapter. Thanks
|
||||
to Tom Snyder (tomsn at inetoffice dot com) who sent me a prototype
|
||||
implementation for HTTP_Request a couple of years ago.
|
||||
* Added HTTPS proxy support to Socket adapter, this works through CONNECT
|
||||
request described in RFC 2817.
|
||||
* Mock adapter can now throw an Exception instead of returning a response
|
||||
if Exception object is added via its addResponse() method (request #15629)
|
||||
|
||||
Other changes and fixes:
|
||||
* Support RFC 3986 by not encoding '~' in POST body (request #15368)
|
||||
* Prevent an error with particular versions of PHP and Curl (bug #15617)
|
||||
* Regular expressions used in HTTP_Request2 are now class constants
|
||||
(request #15630)
|
||||
* Curl adapter now throws an exception in case of malformed (non-HTTP)
|
||||
response rather than dies with a fatal error (bug #15716)
|
||||
* Curl handle wasn't closed in Curl adapter in case of error (bug #15721)
|
||||
* Curl adapter sent an extra 'sentHeaders' event and returned bogus
|
||||
response status when server returned 100-Continue response (bug #15785)
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.2.0</release>
|
||||
<api>0.2.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2009-01-07</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
API changes:
|
||||
* HTTP_Request2::getConfigValue() is deprecated and will be removed in next
|
||||
release. Use HTTP_Request2::getConfig().
|
||||
* Changed HTTP_Request2::setConfig() to accept a pair of parameter name and
|
||||
parameter value in addition to array('parameter name' => 'value')
|
||||
* Added HTTP_Request2::getConfig() method that can return a single
|
||||
configuration parameter or the whole configuration array
|
||||
|
||||
Other additions and changes:
|
||||
* Added a debug Observer that can log request progress to a file or an
|
||||
instance of PEAR::Log (thanks to David Jean Louis, request #15424)
|
||||
* Added a new 'timeout' parameter that limits total number of seconds
|
||||
a request can take (see requests #5735 and #8964)
|
||||
* Added various SSL protocol options: 'ssl_verify_peer', 'ssl_verify_host',
|
||||
'ssl_cafile', 'ssl_capath', 'ssl_local_cert', 'ssl_passphrase'. Note that
|
||||
'ssl_verify_host' option behaves differently in Socket and Curl Adapters:
|
||||
http://bugs.php.net/bug.php?id=47030
|
||||
|
||||
Fixes:
|
||||
* Fixed 'data error' when processing response encoded by 'deflate'
|
||||
encoding (bug #15305)
|
||||
* Curl Adapter now passes full request headers in 'sentHeaders' event
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>0.1.0</release>
|
||||
<api>0.1.0</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>alpha</release>
|
||||
<api>alpha</api>
|
||||
</stability>
|
||||
<date>2008-11-17</date>
|
||||
<license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license>
|
||||
<notes>
|
||||
Initial release. The features supported are mostly the same as those of
|
||||
HTTP_Request, with the following additional feature requests implemented:
|
||||
* cURL extension support (request #5463)
|
||||
* It is now possible to monitor the file upload progress with Observers
|
||||
(request #7630)
|
||||
* Added 'sentHeaders' notification providing the request headers to the
|
||||
Observers (request #7633)
|
||||
* Added support for 'deflate' encoding (request #11246)
|
||||
</notes>
|
||||
</release>
|
||||
</changelog>
|
||||
</package>
|
||||
54
vendor/pear/http_request2/tests/AllTests.php
vendored
54
vendor/pear/http_request2/tests/AllTests.php
vendored
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD')) {
|
||||
define('PHPUnit_MAIN_METHOD', 'HTTP_Request2_AllTests::main');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/Request2Test.php';
|
||||
require_once dirname(__FILE__) . '/ObserverTest.php';
|
||||
require_once dirname(__FILE__) . '/Request2/AllTests.php';
|
||||
|
||||
class HTTP_Request2_AllTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
if (!function_exists('phpunit_autoload')) {
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
}
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('HTTP_Request2 package');
|
||||
|
||||
$suite->addTest(Request2_AllTests::suite());
|
||||
$suite->addTestSuite('HTTP_Request2Test');
|
||||
$suite->addTestSuite('HTTP_Request2_ObserverTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'HTTP_Request2_AllTests::main') {
|
||||
HTTP_Request2_AllTests::main();
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file contains configuration needed for running HTTP_Request2 tests
|
||||
* that interact with the network. Do not edit this file, copy it to
|
||||
* NetworkConfig.php and edit the copy instead.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base URL for HTTP_Request2 Adapters tests
|
||||
*
|
||||
* To enable the tests that actually perform network interaction, you should
|
||||
* copy the contents of _network directory to a directory under your web
|
||||
* server's document root or create a symbolic link to _network directory
|
||||
* there. Set this constant to point to the URL of that directory.
|
||||
*/
|
||||
define('HTTP_REQUEST2_TESTS_BASE_URL', null);
|
||||
|
||||
/**
|
||||
* URL that is protected by server digest authentication
|
||||
*
|
||||
* This is needed for testing of 100 Continue handling, we can't implement
|
||||
* digest in PHP since it will kick in a bit later
|
||||
*/
|
||||
define('HTTP_REQUEST2_TESTS_DIGEST_URL', null);
|
||||
|
||||
/**#@+
|
||||
* Proxy setup for Socket Adapter tests
|
||||
*
|
||||
* Set these constants to run additional tests for Socket Adapter using a HTTP
|
||||
* proxy. If proxy host is not set then the tests will not be run.
|
||||
*/
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_HOST', null);
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_PORT', 8080);
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_USER', '');
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_PASSWORD', '');
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_AUTH_SCHEME', 'basic');
|
||||
define('HTTP_REQUEST2_TESTS_PROXY_TYPE', 'http');
|
||||
/**#@-*/
|
||||
?>
|
||||
95
vendor/pear/http_request2/tests/ObserverTest.php
vendored
95
vendor/pear/http_request2/tests/ObserverTest.php
vendored
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(__FILE__) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request
|
||||
*/
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Mock observer
|
||||
*/
|
||||
class HTTP_Request2_MockObserver implements SplObserver
|
||||
{
|
||||
public $calls = 0;
|
||||
|
||||
public $event;
|
||||
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
$this->calls++;
|
||||
$this->event = $subject->getLastEvent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test for subject-observer pattern implementation in HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_ObserverTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetLastEvent()
|
||||
{
|
||||
$request = new HTTP_Request2();
|
||||
$observer = new HTTP_Request2_MockObserver();
|
||||
$request->attach($observer);
|
||||
|
||||
$request->setLastEvent('foo', 'bar');
|
||||
$this->assertEquals(1, $observer->calls);
|
||||
$this->assertEquals(array('name' => 'foo', 'data' => 'bar'), $observer->event);
|
||||
|
||||
$request->setLastEvent('baz');
|
||||
$this->assertEquals(2, $observer->calls);
|
||||
$this->assertEquals(array('name' => 'baz', 'data' => null), $observer->event);
|
||||
}
|
||||
|
||||
public function testAttachOnlyOnce()
|
||||
{
|
||||
$request = new HTTP_Request2();
|
||||
$observer = new HTTP_Request2_MockObserver();
|
||||
$observer2 = new HTTP_Request2_MockObserver();
|
||||
$request->attach($observer);
|
||||
$request->attach($observer2);
|
||||
$request->attach($observer);
|
||||
|
||||
$request->setLastEvent('event', 'data');
|
||||
$this->assertEquals(1, $observer->calls);
|
||||
$this->assertEquals(1, $observer2->calls);
|
||||
}
|
||||
|
||||
public function testDetach()
|
||||
{
|
||||
$request = new HTTP_Request2();
|
||||
$observer = new HTTP_Request2_MockObserver();
|
||||
$observer2 = new HTTP_Request2_MockObserver();
|
||||
|
||||
$request->attach($observer);
|
||||
$request->detach($observer2); // should not be a error
|
||||
$request->setLastEvent('first');
|
||||
|
||||
$request->detach($observer);
|
||||
$request->setLastEvent('second');
|
||||
$this->assertEquals(1, $observer->calls);
|
||||
$this->assertEquals(array('name' => 'first', 'data' => null), $observer->event);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD')) {
|
||||
define('PHPUnit_MAIN_METHOD', 'Request2_Adapter_AllTests::main');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/MockTest.php';
|
||||
require_once dirname(__FILE__) . '/SkippedTests.php';
|
||||
require_once dirname(__FILE__) . '/SocketTest.php';
|
||||
require_once dirname(__FILE__) . '/SocketProxyTest.php';
|
||||
require_once dirname(__FILE__) . '/CurlTest.php';
|
||||
|
||||
class Request2_Adapter_AllTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('HTTP_Request2 package - Request2 - Adapter');
|
||||
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_MockTest');
|
||||
if (defined('HTTP_REQUEST2_TESTS_BASE_URL') && HTTP_REQUEST2_TESTS_BASE_URL) {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_SocketTest');
|
||||
} else {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_Skip_SocketTest');
|
||||
}
|
||||
if (defined('HTTP_REQUEST2_TESTS_PROXY_HOST') && HTTP_REQUEST2_TESTS_PROXY_HOST
|
||||
&& defined('HTTP_REQUEST2_TESTS_BASE_URL') && HTTP_REQUEST2_TESTS_BASE_URL
|
||||
) {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_SocketProxyTest');
|
||||
} else {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_Skip_SocketProxyTest');
|
||||
}
|
||||
if (defined('HTTP_REQUEST2_TESTS_BASE_URL') && HTTP_REQUEST2_TESTS_BASE_URL
|
||||
&& extension_loaded('curl')
|
||||
) {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_CurlTest');
|
||||
} else {
|
||||
$suite->addTestSuite('HTTP_Request2_Adapter_Skip_CurlTest');
|
||||
}
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'Request2_Adapter_AllTests::main') {
|
||||
Request2_Adapter_AllTests::main();
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,387 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
|
||||
|
||||
/** Class representing a HTTP request */
|
||||
require_once 'HTTP/Request2.php';
|
||||
/** Class for building multipart/form-data request body */
|
||||
require_once 'HTTP/Request2/MultipartBody.php';
|
||||
|
||||
class SlowpokeBody extends HTTP_Request2_MultipartBody
|
||||
{
|
||||
protected $doSleep;
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->doSleep = true;
|
||||
parent::rewind();
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->doSleep) {
|
||||
sleep(3);
|
||||
$this->doSleep = false;
|
||||
}
|
||||
return parent::read($length);
|
||||
}
|
||||
}
|
||||
|
||||
class HeaderObserver implements SplObserver
|
||||
{
|
||||
public $headers;
|
||||
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
$event = $subject->getLastEvent();
|
||||
|
||||
// force a timeout when writing request body
|
||||
if ('sentHeaders' == $event['name']) {
|
||||
$this->headers = $event['data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for HTTP_Request2 package that require a working webserver
|
||||
*
|
||||
* The class contains some common tests that should be run for all Adapters,
|
||||
* it is extended by their unit tests.
|
||||
*
|
||||
* You need to properly set up this test suite, refer to NetworkConfig.php.dist
|
||||
*/
|
||||
abstract class HTTP_Request2_Adapter_CommonNetworkTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* HTTP Request object
|
||||
* @var HTTP_Request2
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Base URL for remote test files
|
||||
* @var string
|
||||
*/
|
||||
protected $baseUrl;
|
||||
|
||||
/**
|
||||
* Configuration for HTTP Request object
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!defined('HTTP_REQUEST2_TESTS_BASE_URL') || !HTTP_REQUEST2_TESTS_BASE_URL) {
|
||||
$this->markTestSkipped('Base URL is not configured');
|
||||
|
||||
} else {
|
||||
$this->baseUrl = rtrim(HTTP_REQUEST2_TESTS_BASE_URL, '/') . '/';
|
||||
$name = strtolower(preg_replace('/^test/i', '', $this->getName())) . '.php';
|
||||
|
||||
$this->request = new HTTP_Request2(
|
||||
$this->baseUrl . $name, HTTP_Request2::METHOD_GET, $this->config
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests possibility to send GET parameters
|
||||
*
|
||||
* NB: Currently there are problems with Net_URL2::setQueryVariables(), thus
|
||||
* array structure is simple: http://pear.php.net/bugs/bug.php?id=18267
|
||||
*/
|
||||
public function testGetParameters()
|
||||
{
|
||||
$data = array(
|
||||
'bar' => array(
|
||||
'key' => 'value'
|
||||
),
|
||||
'foo' => 'some value',
|
||||
'numbered' => array('first', 'second')
|
||||
);
|
||||
|
||||
$this->request->getUrl()->setQueryVariables($data);
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(serialize($data), $response->getBody());
|
||||
}
|
||||
|
||||
public function testPostParameters()
|
||||
{
|
||||
$data = array(
|
||||
'bar' => array(
|
||||
'key' => 'some other value'
|
||||
),
|
||||
'baz' => array(
|
||||
'key1' => array(
|
||||
'key2' => 'yet another value'
|
||||
)
|
||||
),
|
||||
'foo' => 'some value',
|
||||
'indexed' => array('first', 'second')
|
||||
);
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->addPostParameter($data);
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(serialize($data), $response->getBody());
|
||||
}
|
||||
|
||||
public function testUploads()
|
||||
{
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->addUpload('foo', dirname(dirname(dirname(__FILE__))) . '/_files/empty.gif', 'picture.gif', 'image/gif')
|
||||
->addUpload('bar', array(
|
||||
array(dirname(dirname(dirname(__FILE__))) . '/_files/empty.gif', null, 'image/gif'),
|
||||
array(dirname(dirname(dirname(__FILE__))) . '/_files/plaintext.txt', 'secret.txt', 'text/x-whatever')
|
||||
));
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertContains("foo picture.gif image/gif 43", $response->getBody());
|
||||
$this->assertContains("bar[0] empty.gif image/gif 43", $response->getBody());
|
||||
$this->assertContains("bar[1] secret.txt text/x-whatever 15", $response->getBody());
|
||||
}
|
||||
|
||||
public function testRawPostData()
|
||||
{
|
||||
$data = 'Nothing to see here, move along';
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setBody($data);
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals($data, $response->getBody());
|
||||
}
|
||||
|
||||
public function testCookies()
|
||||
{
|
||||
$cookies = array(
|
||||
'CUSTOMER' => 'WILE_E_COYOTE',
|
||||
'PART_NUMBER' => 'ROCKET_LAUNCHER_0001'
|
||||
);
|
||||
|
||||
foreach ($cookies as $k => $v) {
|
||||
$this->request->addCookie($k, $v);
|
||||
}
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(serialize($cookies), $response->getBody());
|
||||
}
|
||||
|
||||
public function testTimeout()
|
||||
{
|
||||
$this->request->setConfig('timeout', 2);
|
||||
try {
|
||||
$this->request->send();
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
} catch (HTTP_Request2_MessageException $e) {
|
||||
$this->assertEquals(HTTP_Request2_Exception::TIMEOUT, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTimeoutInRequest()
|
||||
{
|
||||
$this->request->setConfig('timeout', 2)
|
||||
->setUrl($this->baseUrl . 'postparameters.php')
|
||||
->setBody(new SlowpokeBody(array('foo' => 'some value'), array()));
|
||||
try {
|
||||
$this->request->send();
|
||||
$this->fail('Expected HTTP_Request2_MessageException was not thrown');
|
||||
} catch (HTTP_Request2_MessageException $e) {
|
||||
$this->assertEquals(HTTP_Request2_Exception::TIMEOUT, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testBasicAuth()
|
||||
{
|
||||
$this->request->getUrl()->setQueryVariables(array(
|
||||
'user' => 'luser',
|
||||
'pass' => 'qwerty'
|
||||
));
|
||||
$wrong = clone $this->request;
|
||||
|
||||
$this->request->setAuth('luser', 'qwerty');
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
|
||||
$wrong->setAuth('luser', 'password');
|
||||
$response = $wrong->send();
|
||||
$this->assertEquals(401, $response->getStatus());
|
||||
}
|
||||
|
||||
public function testDigestAuth()
|
||||
{
|
||||
$this->request->getUrl()->setQueryVariables(array(
|
||||
'user' => 'luser',
|
||||
'pass' => 'qwerty'
|
||||
));
|
||||
$wrong = clone $this->request;
|
||||
|
||||
$this->request->setAuth('luser', 'qwerty', HTTP_Request2::AUTH_DIGEST);
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
|
||||
$wrong->setAuth('luser', 'password', HTTP_Request2::AUTH_DIGEST);
|
||||
$response = $wrong->send();
|
||||
$this->assertEquals(401, $response->getStatus());
|
||||
}
|
||||
|
||||
public function testRedirectsDefault()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php')
|
||||
->setConfig(array('follow_redirects' => true, 'strict_redirects' => false))
|
||||
->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->addPostParameter('foo', 'foo value');
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertContains('Method=GET', $response->getBody());
|
||||
$this->assertNotContains('foo', $response->getBody());
|
||||
$this->assertEquals($this->baseUrl . 'redirects.php?redirects=0', $response->getEffectiveUrl());
|
||||
}
|
||||
|
||||
public function testRedirectsStrict()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php')
|
||||
->setConfig(array('follow_redirects' => true, 'strict_redirects' => true))
|
||||
->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->addPostParameter('foo', 'foo value');
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertContains('Method=POST', $response->getBody());
|
||||
$this->assertContains('foo', $response->getBody());
|
||||
}
|
||||
|
||||
public function testRedirectsLimit()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php?redirects=4')
|
||||
->setConfig(array('follow_redirects' => true, 'max_redirects' => 2));
|
||||
|
||||
try {
|
||||
$this->request->send();
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
} catch (HTTP_Request2_MessageException $e) {
|
||||
$this->assertEquals(HTTP_Request2_Exception::TOO_MANY_REDIRECTS, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectsRelative()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php?special=relative')
|
||||
->setConfig(array('follow_redirects' => true));
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertContains('did relative', $response->getBody());
|
||||
}
|
||||
|
||||
public function testRedirectsNonHTTP()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php?special=ftp')
|
||||
->setConfig(array('follow_redirects' => true));
|
||||
|
||||
try {
|
||||
$this->request->send();
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
} catch (HTTP_Request2_MessageException $e) {
|
||||
$this->assertEquals(HTTP_Request2_Exception::NON_HTTP_REDIRECT, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCookieJar()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'setcookie.php?name=cookie_name&value=cookie_value');
|
||||
$req2 = clone $this->request;
|
||||
|
||||
$this->request->setCookieJar()->send();
|
||||
$jar = $this->request->getCookieJar();
|
||||
$jar->store(
|
||||
array('name' => 'foo', 'value' => 'bar'),
|
||||
$this->request->getUrl()
|
||||
);
|
||||
|
||||
$response = $req2->setUrl($this->baseUrl . 'cookies.php')->setCookieJar($jar)->send();
|
||||
$this->assertEquals(
|
||||
serialize(array('cookie_name' => 'cookie_value', 'foo' => 'bar')),
|
||||
$response->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCookieJarAndRedirect()
|
||||
{
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php?special=cookie')
|
||||
->setConfig('follow_redirects', true)
|
||||
->setCookieJar();
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(serialize(array('cookie_on_redirect' => 'success')), $response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://pear.php.net/bugs/bug.php?id=20125
|
||||
*/
|
||||
public function testChunkedRequest()
|
||||
{
|
||||
$data = array(
|
||||
'long' => str_repeat('a', 1000),
|
||||
'very_long' => str_repeat('b', 2000)
|
||||
);
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setUrl($this->baseUrl . 'postparameters.php')
|
||||
->setConfig('buffer_size', 512)
|
||||
->setHeader('Transfer-Encoding', 'chunked')
|
||||
->addPostParameter($data);
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertEquals(serialize($data), $response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19233
|
||||
* @link http://pear.php.net/bugs/bug.php?id=15937
|
||||
*/
|
||||
public function testPreventExpectHeader()
|
||||
{
|
||||
$fp = fopen(dirname(dirname(dirname(__FILE__))) . '/_files/bug_15305', 'rb');
|
||||
$observer = new HeaderObserver();
|
||||
$body = new HTTP_Request2_MultipartBody(
|
||||
array(),
|
||||
array(
|
||||
'upload' => array(
|
||||
'fp' => $fp,
|
||||
'filename' => 'bug_15305',
|
||||
'type' => 'application/octet-stream',
|
||||
'size' => 16338
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setUrl($this->baseUrl . 'uploads.php')
|
||||
->setHeader('Expect', '')
|
||||
->setBody($body)
|
||||
->attach($observer);
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertNotContains('Expect:', $observer->headers);
|
||||
$this->assertContains('upload bug_15305 application/octet-stream 16338', $response->getBody());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Tests for HTTP_Request2 package that require a working webserver */
|
||||
require_once dirname(__FILE__) . '/CommonNetworkTest.php';
|
||||
|
||||
/** Adapter for HTTP_Request2 wrapping around cURL extension */
|
||||
|
||||
/**
|
||||
* Unit test for Curl Adapter of HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_CurlTest extends HTTP_Request2_Adapter_CommonNetworkTest
|
||||
{
|
||||
/**
|
||||
* Configuration for HTTP Request object
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array(
|
||||
'adapter' => 'HTTP_Request2_Adapter_Curl'
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks whether redirect support in cURL is disabled by safe_mode or open_basedir
|
||||
* @return bool
|
||||
*/
|
||||
protected function isRedirectSupportDisabled()
|
||||
{
|
||||
return ini_get('safe_mode') || ini_get('open_basedir');
|
||||
}
|
||||
|
||||
public function testRedirectsDefault()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testRedirectsDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectsStrict()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testRedirectsStrict();
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectsLimit()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testRedirectsLimit();
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectsRelative()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testRedirectsRelative();
|
||||
}
|
||||
}
|
||||
|
||||
public function testRedirectsNonHTTP()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testRedirectsNonHTTP();
|
||||
}
|
||||
}
|
||||
|
||||
public function testCookieJarAndRedirect()
|
||||
{
|
||||
if ($this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
||||
} else {
|
||||
parent::testCookieJarAndRedirect();
|
||||
}
|
||||
}
|
||||
|
||||
public function testBug17450()
|
||||
{
|
||||
if (!$this->isRedirectSupportDisabled()) {
|
||||
$this->markTestSkipped('Neither safe_mode nor open_basedir is enabled');
|
||||
}
|
||||
|
||||
$this->request->setUrl($this->baseUrl . 'redirects.php')
|
||||
->setConfig(array('follow_redirects' => true));
|
||||
|
||||
try {
|
||||
$this->request->send();
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
|
||||
} catch (HTTP_Request2_LogicException $e) {
|
||||
$this->assertEquals(HTTP_Request2_Exception::MISCONFIGURATION, $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request
|
||||
*/
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Mock adapter intended for testing
|
||||
*/
|
||||
require_once 'HTTP/Request2/Adapter/Mock.php';
|
||||
|
||||
/**
|
||||
* Unit test for HTTP_Request2_Response class
|
||||
*/
|
||||
class HTTP_Request2_Adapter_MockTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testDefaultResponse()
|
||||
{
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_GET,
|
||||
array('adapter' => 'mock'));
|
||||
$response = $req->send();
|
||||
$this->assertEquals(400, $response->getStatus());
|
||||
$this->assertEquals(0, count($response->getHeader()));
|
||||
$this->assertEquals('', $response->getBody());
|
||||
}
|
||||
|
||||
public function testResponseFromString()
|
||||
{
|
||||
$mock = new HTTP_Request2_Adapter_Mock();
|
||||
$mock->addResponse(
|
||||
"HTTP/1.1 200 OK\r\n" .
|
||||
"Content-Type: text/plain; charset=iso-8859-1\r\n" .
|
||||
"\r\n" .
|
||||
"This is a string"
|
||||
);
|
||||
$req = new HTTP_Request2('http://www.example.com/');
|
||||
$req->setAdapter($mock);
|
||||
|
||||
$response = $req->send();
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
$this->assertEquals(1, count($response->getHeader()));
|
||||
$this->assertEquals('This is a string', $response->getBody());
|
||||
}
|
||||
|
||||
public function testResponseFromFile()
|
||||
{
|
||||
$mock = new HTTP_Request2_Adapter_Mock();
|
||||
$mock->addResponse(fopen(dirname(dirname(dirname(__FILE__))) .
|
||||
'/_files/response_headers', 'rb'));
|
||||
|
||||
$req = new HTTP_Request2('http://www.example.com/');
|
||||
$req->setAdapter($mock);
|
||||
|
||||
$response = $req->send();
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
$this->assertEquals(7, count($response->getHeader()));
|
||||
$this->assertEquals('Nothing to see here, move along.', $response->getBody());
|
||||
}
|
||||
|
||||
public function testResponsesQueue()
|
||||
{
|
||||
$mock = new HTTP_Request2_Adapter_Mock();
|
||||
$mock->addResponse(
|
||||
"HTTP/1.1 301 Over there\r\n" .
|
||||
"Location: http://www.example.com/newpage.html\r\n" .
|
||||
"\r\n" .
|
||||
"The document is over there"
|
||||
);
|
||||
$mock->addResponse(
|
||||
"HTTP/1.1 200 OK\r\n" .
|
||||
"Content-Type: text/plain; charset=iso-8859-1\r\n" .
|
||||
"\r\n" .
|
||||
"This is a string"
|
||||
);
|
||||
|
||||
$req = new HTTP_Request2('http://www.example.com/');
|
||||
$req->setAdapter($mock);
|
||||
$this->assertEquals(301, $req->send()->getStatus());
|
||||
$this->assertEquals(200, $req->send()->getStatus());
|
||||
$this->assertEquals(400, $req->send()->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returning URL-specific responses
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19276
|
||||
*/
|
||||
public function testRequest19276()
|
||||
{
|
||||
$mock = new HTTP_Request2_Adapter_Mock();
|
||||
$mock->addResponse(
|
||||
"HTTP/1.1 200 OK\r\n" .
|
||||
"Content-Type: text/plain; charset=iso-8859-1\r\n" .
|
||||
"\r\n" .
|
||||
"This is a response from example.org",
|
||||
'http://example.org/'
|
||||
);
|
||||
$mock->addResponse(
|
||||
"HTTP/1.1 200 OK\r\n" .
|
||||
"Content-Type: text/plain; charset=iso-8859-1\r\n" .
|
||||
"\r\n" .
|
||||
"This is a response from example.com",
|
||||
'http://example.com/'
|
||||
);
|
||||
|
||||
$req1 = new HTTP_Request2('http://localhost/');
|
||||
$req1->setAdapter($mock);
|
||||
$this->assertEquals(400, $req1->send()->getStatus());
|
||||
|
||||
$req2 = new HTTP_Request2('http://example.com/');
|
||||
$req2->setAdapter($mock);
|
||||
$this->assertContains('example.com', $req2->send()->getBody());
|
||||
|
||||
$req3 = new HTTP_Request2('http://example.org');
|
||||
$req3->setAdapter($mock);
|
||||
$this->assertContains('example.org', $req3->send()->getBody());
|
||||
}
|
||||
|
||||
public function testResponseException()
|
||||
{
|
||||
$mock = new HTTP_Request2_Adapter_Mock();
|
||||
$mock->addResponse(
|
||||
new HTTP_Request2_Exception('Shit happens')
|
||||
);
|
||||
$req = new HTTP_Request2('http://www.example.com/');
|
||||
$req->setAdapter($mock);
|
||||
try {
|
||||
$req->send();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Shit happens', $e->getMessage());
|
||||
return;
|
||||
}
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Shows a skipped test if networked tests are not configured
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Skip_SocketTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSocketAdapter()
|
||||
{
|
||||
$this->markTestSkipped('Socket Adapter tests need base URL configured.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a skipped test if proxy is not configured
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Skip_SocketProxyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSocketAdapterWithProxy()
|
||||
{
|
||||
$this->markTestSkipped('Socket Adapter proxy tests need base URL and proxy configured');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a skipped test if networked tests are not configured or cURL extension is unavailable
|
||||
*/
|
||||
class HTTP_Request2_Adapter_Skip_CurlTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCurlAdapter()
|
||||
{
|
||||
$this->markTestSkipped('Curl Adapter tests need base URL configured and curl extension available');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Tests for HTTP_Request2 package that require a working webserver */
|
||||
require_once dirname(__FILE__) . '/CommonNetworkTest.php';
|
||||
|
||||
/**
|
||||
* Unit test for Socket Adapter of HTTP_Request2 working through proxy
|
||||
*/
|
||||
class HTTP_Request2_Adapter_SocketProxyTest extends HTTP_Request2_Adapter_CommonNetworkTest
|
||||
{
|
||||
/**
|
||||
* Configuration for HTTP Request object
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array(
|
||||
'adapter' => 'HTTP_Request2_Adapter_Socket'
|
||||
);
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!defined('HTTP_REQUEST2_TESTS_PROXY_HOST') || !HTTP_REQUEST2_TESTS_PROXY_HOST) {
|
||||
$this->markTestSkipped('Proxy is not configured');
|
||||
|
||||
} else {
|
||||
$this->config += array(
|
||||
'proxy_host' => HTTP_REQUEST2_TESTS_PROXY_HOST,
|
||||
'proxy_port' => HTTP_REQUEST2_TESTS_PROXY_PORT,
|
||||
'proxy_user' => HTTP_REQUEST2_TESTS_PROXY_USER,
|
||||
'proxy_password' => HTTP_REQUEST2_TESTS_PROXY_PASSWORD,
|
||||
'proxy_auth_scheme' => HTTP_REQUEST2_TESTS_PROXY_AUTH_SCHEME,
|
||||
'proxy_type' => HTTP_REQUEST2_TESTS_PROXY_TYPE
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Tests for HTTP_Request2 package that require a working webserver */
|
||||
require_once dirname(__FILE__) . '/CommonNetworkTest.php';
|
||||
|
||||
/** Socket-based adapter for HTTP_Request2 */
|
||||
require_once 'HTTP/Request2/Adapter/Socket.php';
|
||||
|
||||
/**
|
||||
* Unit test for Socket Adapter of HTTP_Request2
|
||||
*/
|
||||
class HTTP_Request2_Adapter_SocketTest extends HTTP_Request2_Adapter_CommonNetworkTest
|
||||
{
|
||||
/**
|
||||
* Configuration for HTTP Request object
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array(
|
||||
'adapter' => 'HTTP_Request2_Adapter_Socket'
|
||||
);
|
||||
|
||||
public function testBug17826()
|
||||
{
|
||||
$adapter = new HTTP_Request2_Adapter_Socket();
|
||||
|
||||
$request1 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
|
||||
$request1->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))
|
||||
->setAdapter($adapter)
|
||||
->send();
|
||||
|
||||
$request2 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
|
||||
$request2->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))
|
||||
->setAdapter($adapter)
|
||||
->send();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Infinite loop with stream wrapper passed as upload
|
||||
*
|
||||
* Dunno how the original reporter managed to pass a file pointer
|
||||
* that doesn't support fstat() to MultipartBody, maybe he didn't use
|
||||
* addUpload(). So we don't use it, either.
|
||||
*
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19934
|
||||
*/
|
||||
public function testBug19934()
|
||||
{
|
||||
if (!in_array('http', stream_get_wrappers())) {
|
||||
$this->markTestSkipped("This test requires an HTTP fopen wrapper enabled");
|
||||
}
|
||||
|
||||
$fp = fopen($this->baseUrl . '/bug19934.php', 'rb');
|
||||
$body = new HTTP_Request2_MultipartBody(
|
||||
array(),
|
||||
array(
|
||||
'upload' => array(
|
||||
'fp' => $fp,
|
||||
'filename' => 'foo.txt',
|
||||
'type' => 'text/plain',
|
||||
'size' => 20000
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setUrl($this->baseUrl . 'uploads.php')
|
||||
->setBody($body);
|
||||
|
||||
set_error_handler(array($this, 'rewindWarningsHandler'));
|
||||
$response = $this->request->send();
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertContains("upload foo.txt text/plain 20000", $response->getBody());
|
||||
}
|
||||
|
||||
public function rewindWarningsHandler($errno, $errstr)
|
||||
{
|
||||
if (($errno & E_WARNING) && false !== strpos($errstr, 'rewind')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not send request body twice to URLs protected by digest auth
|
||||
*
|
||||
* @link http://pear.php.net/bugs/bug.php?id=19233
|
||||
*/
|
||||
public function test100ContinueHandling()
|
||||
{
|
||||
if (!defined('HTTP_REQUEST2_TESTS_DIGEST_URL') || !HTTP_REQUEST2_TESTS_DIGEST_URL) {
|
||||
$this->markTestSkipped('This test requires an URL protected by server digest auth');
|
||||
}
|
||||
|
||||
$fp = fopen(dirname(dirname(dirname(__FILE__))) . '/_files/bug_15305', 'rb');
|
||||
$body = $this->getMock(
|
||||
'HTTP_Request2_MultipartBody', array('read'), array(
|
||||
array(),
|
||||
array(
|
||||
'upload' => array(
|
||||
'fp' => $fp,
|
||||
'filename' => 'bug_15305',
|
||||
'type' => 'application/octet-stream',
|
||||
'size' => 16338
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$body->expects($this->never())->method('read');
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setUrl(HTTP_REQUEST2_TESTS_DIGEST_URL)
|
||||
->setBody($body);
|
||||
|
||||
$this->assertEquals(401, $this->request->send()->getStatus());
|
||||
}
|
||||
|
||||
public function test100ContinueTimeoutBug()
|
||||
{
|
||||
$fp = fopen(dirname(dirname(dirname(__FILE__))) . '/_files/bug_15305', 'rb');
|
||||
$body = new HTTP_Request2_MultipartBody(
|
||||
array(),
|
||||
array(
|
||||
'upload' => array(
|
||||
'fp' => $fp,
|
||||
'filename' => 'bug_15305',
|
||||
'type' => 'application/octet-stream',
|
||||
'size' => 16338
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_POST)
|
||||
->setUrl($this->baseUrl . 'uploads.php?slowpoke')
|
||||
->setBody($body);
|
||||
|
||||
$response = $this->request->send();
|
||||
$this->assertContains('upload bug_15305 application/octet-stream 16338', $response->getBody());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD')) {
|
||||
define('PHPUnit_MAIN_METHOD', 'Request2_AllTests::main');
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__) . '/CookieJarTest.php';
|
||||
require_once dirname(__FILE__) . '/MultipartBodyTest.php';
|
||||
require_once dirname(__FILE__) . '/ResponseTest.php';
|
||||
require_once dirname(__FILE__) . '/Adapter/AllTests.php';
|
||||
|
||||
class Request2_AllTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
if (!function_exists('phpunit_autoload')) {
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
}
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('HTTP_Request2 package - Request2');
|
||||
|
||||
$suite->addTestSuite('HTTP_Request2_CookieJarTest');
|
||||
$suite->addTestSuite('HTTP_Request2_MultipartBodyTest');
|
||||
$suite->addTestSuite('HTTP_Request2_ResponseTest');
|
||||
$suite->addTest(Request2_Adapter_AllTests::suite());
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'Request2_AllTests::main') {
|
||||
Request2_AllTests::main();
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,370 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(__FILE__)) . '/TestHelper.php';
|
||||
/** Stores cookies and passes them between HTTP requests */
|
||||
require_once 'HTTP/Request2/CookieJar.php';
|
||||
|
||||
/**
|
||||
* Unit test for HTTP_Request2_CookieJar class
|
||||
*/
|
||||
class HTTP_Request2_CookieJarTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Cookie jar instance being tested
|
||||
* @var HTTP_Request2_CookieJar
|
||||
*/
|
||||
protected $jar;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->jar = new HTTP_Request2_CookieJar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can't store junk "cookies" in jar
|
||||
*
|
||||
* @dataProvider invalidCookieProvider
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testStoreInvalid($cookie)
|
||||
{
|
||||
$this->jar->store($cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider noPSLDomainsProvider
|
||||
*/
|
||||
public function testDomainMatchNoPSL($requestHost, $cookieDomain, $expected)
|
||||
{
|
||||
$this->jar->usePublicSuffixList(false);
|
||||
$this->assertEquals($expected, $this->jar->domainMatch($requestHost, $cookieDomain));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider PSLDomainsProvider
|
||||
*/
|
||||
public function testDomainMatchPSL($requestHost, $cookieDomain, $expected)
|
||||
{
|
||||
$this->jar->usePublicSuffixList(true);
|
||||
$this->assertEquals($expected, $this->jar->domainMatch($requestHost, $cookieDomain));
|
||||
}
|
||||
|
||||
public function testConvertExpiresToISO8601()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$dt->modify('+1 day');
|
||||
|
||||
$this->jar->store(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'expires' => $dt->format(DateTime::COOKIE),
|
||||
'secure' => false
|
||||
));
|
||||
$cookies = $this->jar->getAll();
|
||||
$this->assertEquals($cookies[0]['expires'], $dt->format(DateTime::ISO8601));
|
||||
}
|
||||
|
||||
public function testProblem2038()
|
||||
{
|
||||
$this->jar->store(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'expires' => 'Sun, 01 Jan 2040 03:04:05 GMT',
|
||||
'secure' => false
|
||||
));
|
||||
$cookies = $this->jar->getAll();
|
||||
$this->assertEquals(array(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'expires' => '2040-01-01T03:04:05+0000',
|
||||
'secure' => false
|
||||
)), $cookies);
|
||||
}
|
||||
|
||||
public function testStoreExpired()
|
||||
{
|
||||
$base = array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'secure' => false
|
||||
);
|
||||
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$dt->modify('-1 day');
|
||||
$yesterday = $dt->format(DateTime::COOKIE);
|
||||
|
||||
$dt->modify('+2 days');
|
||||
$tomorrow = $dt->format(DateTime::COOKIE);
|
||||
|
||||
$this->jar->store($base + array('expires' => $yesterday));
|
||||
$this->assertEquals(0, count($this->jar->getAll()));
|
||||
|
||||
$this->jar->store($base + array('expires' => $tomorrow));
|
||||
$this->assertEquals(1, count($this->jar->getAll()));
|
||||
$this->jar->store($base + array('expires' => $yesterday));
|
||||
$this->assertEquals(0, count($this->jar->getAll()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider cookieAndSetterProvider
|
||||
*/
|
||||
public function testGetDomainAndPathFromSetter($cookie, $setter, $expected)
|
||||
{
|
||||
$this->jar->store($cookie, $setter);
|
||||
$expected = array_merge($cookie, $expected);
|
||||
$cookies = $this->jar->getAll();
|
||||
$this->assertEquals($expected, $cookies[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider cookieMatchProvider
|
||||
*/
|
||||
public function testGetMatchingCookies($url, $expectedCount)
|
||||
{
|
||||
$cookies = array(
|
||||
array('domain' => '.example.com', 'path' => '/', 'secure' => false),
|
||||
array('domain' => '.example.com', 'path' => '/', 'secure' => true),
|
||||
array('domain' => '.example.com', 'path' => '/path', 'secure' => false),
|
||||
array('domain' => '.example.com', 'path' => '/other', 'secure' => false),
|
||||
array('domain' => 'example.com', 'path' => '/', 'secure' => false),
|
||||
array('domain' => 'www.example.com', 'path' => '/', 'secure' => false),
|
||||
array('domain' => 'specific.example.com', 'path' => '/path', 'secure' => false),
|
||||
array('domain' => 'nowww.example.com', 'path' => '/', 'secure' => false),
|
||||
);
|
||||
|
||||
for ($i = 0; $i < count($cookies); $i++) {
|
||||
$this->jar->store($cookies[$i] + array('expires' => null, 'name' => "cookie{$i}", 'value' => "cookie_{$i}_value"));
|
||||
}
|
||||
|
||||
$this->assertEquals($expectedCount, count($this->jar->getMatching(new Net_URL2($url))));
|
||||
}
|
||||
|
||||
public function testLongestPathFirst()
|
||||
{
|
||||
$cookie = array(
|
||||
'name' => 'foo',
|
||||
'domain' => '.example.com',
|
||||
);
|
||||
foreach (array('/', '/specific/path/', '/specific/') as $path) {
|
||||
$this->jar->store($cookie + array('path' => $path, 'value' => str_replace('/', '_', $path)));
|
||||
}
|
||||
$this->assertEquals(
|
||||
'foo=_specific_path_; foo=_specific_; foo=_',
|
||||
$this->jar->getMatching(new Net_URL2('http://example.com/specific/path/file.php'), true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSerializable()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$dt->modify('+1 day');
|
||||
$cookie = array('domain' => '.example.com', 'path' => '/', 'secure' => false, 'value' => 'foo');
|
||||
|
||||
$this->jar->store($cookie + array('name' => 'session', 'expires' => null));
|
||||
$this->jar->store($cookie + array('name' => 'long', 'expires' => $dt->format(DateTime::COOKIE)));
|
||||
|
||||
$newJar = unserialize(serialize($this->jar));
|
||||
$cookies = $newJar->getAll();
|
||||
$this->assertEquals(1, count($cookies));
|
||||
$this->assertEquals('long', $cookies[0]['name']);
|
||||
|
||||
$this->jar->serializeSessionCookies(true);
|
||||
$newJar = unserialize(serialize($this->jar));
|
||||
$this->assertEquals($this->jar->getAll(), $newJar->getAll());
|
||||
}
|
||||
|
||||
public function testRemoveExpiredOnUnserialize()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
$dt->modify('+2 seconds');
|
||||
|
||||
$this->jar->store(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'expires' => $dt->format(DateTime::COOKIE),
|
||||
));
|
||||
|
||||
$serialized = serialize($this->jar);
|
||||
sleep(2);
|
||||
$newJar = unserialize($serialized);
|
||||
$this->assertEquals(array(), $newJar->getAll());
|
||||
}
|
||||
|
||||
public static function invalidCookieProvider()
|
||||
{
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('name' => 'foo')),
|
||||
array(array(
|
||||
'name' => 'a name',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
)),
|
||||
array(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'a value',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
)),
|
||||
array(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => null,
|
||||
)),
|
||||
array(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => null,
|
||||
'path' => '/',
|
||||
)),
|
||||
array(array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => '/',
|
||||
'expires' => 'invalid date',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
public static function noPSLdomainsProvider()
|
||||
{
|
||||
return array(
|
||||
array('localhost', 'localhost', true),
|
||||
array('www.example.com', 'www.example.com', true),
|
||||
array('127.0.0.1', '127.0.0.1', true),
|
||||
array('127.0.0.1', '.0.0.1', false),
|
||||
array('www.example.com', '.example.com', true),
|
||||
array('deep.within.example.com', '.example.com', true),
|
||||
array('example.com', '.com', false),
|
||||
array('anotherexample.com', 'example.com', false),
|
||||
array('whatever.msk.ru', '.msk.ru', true),
|
||||
array('whatever.co.uk', '.co.uk', true),
|
||||
array('whatever.uk', '.whatever.uk', true),
|
||||
array('whatever.tokyo.jp', '.whatever.tokyo.jp', true),
|
||||
array('metro.tokyo.jp', '.metro.tokyo.jp', true),
|
||||
array('foo.bar', '.foo.bar', true)
|
||||
);
|
||||
}
|
||||
|
||||
public static function PSLdomainsProvider()
|
||||
{
|
||||
return array(
|
||||
array('localhost', 'localhost', true),
|
||||
array('www.example.com', 'www.example.com', true),
|
||||
array('127.0.0.1', '127.0.0.1', true),
|
||||
array('127.0.0.1', '.0.0.1', false),
|
||||
array('www.example.com', '.example.com', true),
|
||||
array('deep.within.example.com', '.example.com', true),
|
||||
array('example.com', '.com', false),
|
||||
array('anotherexample.com', 'example.com', false),
|
||||
array('whatever.msk.ru', '.msk.ru', false),
|
||||
array('whatever.co.uk', '.co.uk', false),
|
||||
array('whatever.uk', '.whatever.uk', false),
|
||||
array('whatever.tr', '.whatever.tr', false),
|
||||
array('nic.tr', '.nic.tr', true),
|
||||
array('foo.bar', '.foo.bar', true)
|
||||
);
|
||||
}
|
||||
|
||||
public static function cookieAndSetterProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => null,
|
||||
'path' => null,
|
||||
'expires' => null,
|
||||
'secure' => false
|
||||
),
|
||||
new Net_Url2('http://example.com/directory/file.php'),
|
||||
array(
|
||||
'domain' => 'example.com',
|
||||
'path' => '/directory/'
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => '.example.com',
|
||||
'path' => null,
|
||||
'expires' => null,
|
||||
'secure' => false
|
||||
),
|
||||
new Net_Url2('http://example.com/path/to/file.php'),
|
||||
array(
|
||||
'path' => '/path/to/'
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => null,
|
||||
'path' => '/',
|
||||
'expires' => null,
|
||||
'secure' => false
|
||||
),
|
||||
new Net_Url2('http://example.com/another/file.php'),
|
||||
array(
|
||||
'domain' => 'example.com'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function cookieMatchProvider()
|
||||
{
|
||||
return array(
|
||||
array('http://www.example.com/path/file.php', 4),
|
||||
array('https://www.example.com/path/file.php', 5),
|
||||
array('http://example.com/path/file.php', 3),
|
||||
array('http://specific.example.com/path/file.php', 4),
|
||||
array('http://specific.example.com/other/file.php', 3),
|
||||
array('http://another.example.com/another', 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(__FILE__)) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request
|
||||
*/
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Unit test for HTTP_Request2_MultipartBody class
|
||||
*/
|
||||
class HTTP_Request2_MultipartBodyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUploadSimple()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$body = $req->addPostParameter('foo', 'I am a parameter')
|
||||
->addUpload('upload', dirname(dirname(__FILE__)) . '/_files/plaintext.txt')
|
||||
->getBody();
|
||||
|
||||
$this->assertTrue($body instanceof HTTP_Request2_MultipartBody);
|
||||
$asString = $body->__toString();
|
||||
$boundary = $body->getBoundary();
|
||||
$this->assertEquals($body->getLength(), strlen($asString));
|
||||
$this->assertContains('This is a test.', $asString);
|
||||
$this->assertContains('I am a parameter', $asString);
|
||||
$this->assertRegexp("!--{$boundary}--\r\n$!", $asString);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testRequest16863()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$fp = fopen(dirname(dirname(__FILE__)) . '/_files/plaintext.txt', 'rb');
|
||||
$body = $req->addUpload('upload', $fp)
|
||||
->getBody();
|
||||
|
||||
$asString = $body->__toString();
|
||||
$this->assertContains('name="upload"; filename="anonymous.blob"', $asString);
|
||||
$this->assertContains('This is a test.', $asString);
|
||||
|
||||
$req->addUpload('bad_upload', fopen('php://input', 'rb'));
|
||||
}
|
||||
|
||||
public function testStreaming()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$body = $req->addPostParameter('foo', 'I am a parameter')
|
||||
->addUpload('upload', dirname(dirname(__FILE__)) . '/_files/plaintext.txt')
|
||||
->getBody();
|
||||
$asString = '';
|
||||
while ($part = $body->read(10)) {
|
||||
$asString .= $part;
|
||||
}
|
||||
$this->assertEquals($body->getLength(), strlen($asString));
|
||||
$this->assertContains('This is a test.', $asString);
|
||||
$this->assertContains('I am a parameter', $asString);
|
||||
}
|
||||
|
||||
public function testUploadArray()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$body = $req->addUpload('upload', array(
|
||||
array(dirname(dirname(__FILE__)) . '/_files/plaintext.txt', 'bio.txt', 'text/plain'),
|
||||
array(fopen(dirname(dirname(__FILE__)) . '/_files/empty.gif', 'rb'), 'photo.gif', 'image/gif')
|
||||
))
|
||||
->getBody();
|
||||
$asString = $body->__toString();
|
||||
$this->assertContains(file_get_contents(dirname(dirname(__FILE__)) . '/_files/empty.gif'), $asString);
|
||||
$this->assertContains('name="upload[0]"; filename="bio.txt"', $asString);
|
||||
$this->assertContains('name="upload[1]"; filename="photo.gif"', $asString);
|
||||
|
||||
$body2 = $req->setConfig(array('use_brackets' => false))->getBody();
|
||||
$asString = $body2->__toString();
|
||||
$this->assertContains('name="upload"; filename="bio.txt"', $asString);
|
||||
$this->assertContains('name="upload"; filename="photo.gif"', $asString);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(dirname(__FILE__)) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP response
|
||||
*/
|
||||
require_once 'HTTP/Request2/Response.php';
|
||||
|
||||
/**
|
||||
* Unit test for HTTP_Request2_Response class
|
||||
*/
|
||||
class HTTP_Request2_ResponseTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_MessageException
|
||||
*/
|
||||
public function testParseStatusLine()
|
||||
{
|
||||
$response = new HTTP_Request2_Response('HTTP/1.1 200 OK');
|
||||
$this->assertEquals('1.1', $response->getVersion());
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
$this->assertEquals('OK', $response->getReasonPhrase());
|
||||
|
||||
$response2 = new HTTP_Request2_Response('HTTP/1.2 222 Nishtyak!');
|
||||
$this->assertEquals('1.2', $response2->getVersion());
|
||||
$this->assertEquals(222, $response2->getStatus());
|
||||
$this->assertEquals('Nishtyak!', $response2->getReasonPhrase());
|
||||
|
||||
$response3 = new HTTP_Request2_Response('Invalid status line');
|
||||
}
|
||||
|
||||
public function testParseHeaders()
|
||||
{
|
||||
$response = $this->readResponseFromFile('response_headers');
|
||||
$this->assertEquals(7, count($response->getHeader()));
|
||||
$this->assertEquals('PHP/6.2.2', $response->getHeader('X-POWERED-BY'));
|
||||
$this->assertEquals('text/html; charset=windows-1251', $response->getHeader('cOnTeNt-TyPe'));
|
||||
$this->assertEquals('accept-charset, user-agent', $response->getHeader('vary'));
|
||||
}
|
||||
|
||||
public function testParseCookies()
|
||||
{
|
||||
$response = $this->readResponseFromFile('response_cookies');
|
||||
$cookies = $response->getCookies();
|
||||
$this->assertEquals(4, count($cookies));
|
||||
$expected = array(
|
||||
array('name' => 'foo', 'value' => 'bar', 'expires' => null,
|
||||
'domain' => null, 'path' => null, 'secure' => false),
|
||||
array('name' => 'PHPSESSID', 'value' => '1234567890abcdef1234567890abcdef',
|
||||
'expires' => null, 'domain' => null, 'path' => '/', 'secure' => true),
|
||||
array('name' => 'A', 'value' => 'B=C', 'expires' => null,
|
||||
'domain' => null, 'path' => null, 'secure' => false),
|
||||
array('name' => 'baz', 'value' => '%20a%20value', 'expires' => 'Sun, 03 Jan 2010 03:04:05 GMT',
|
||||
'domain' => 'pear.php.net', 'path' => null, 'secure' => false),
|
||||
);
|
||||
foreach ($cookies as $k => $cookie) {
|
||||
$this->assertEquals($expected[$k], $cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_MessageException
|
||||
*/
|
||||
public function testGzipEncoding()
|
||||
{
|
||||
$response = $this->readResponseFromFile('response_gzip');
|
||||
$this->assertEquals('0e964e9273c606c46afbd311b5ad4d77', md5($response->getBody()));
|
||||
|
||||
$response = $this->readResponseFromFile('response_gzip_broken');
|
||||
$body = $response->getBody();
|
||||
}
|
||||
|
||||
public function testDeflateEncoding()
|
||||
{
|
||||
$response = $this->readResponseFromFile('response_deflate');
|
||||
$this->assertEquals('0e964e9273c606c46afbd311b5ad4d77', md5($response->getBody()));
|
||||
}
|
||||
|
||||
public function testBug15305()
|
||||
{
|
||||
$response = $this->readResponseFromFile('bug_15305');
|
||||
$this->assertEquals('c8c5088fc8a7652afef380f086c010a6', md5($response->getBody()));
|
||||
}
|
||||
|
||||
public function testBug18169()
|
||||
{
|
||||
$response = $this->readResponseFromFile('bug_18169');
|
||||
$this->assertEquals('', $response->getBody());
|
||||
}
|
||||
|
||||
protected function readResponseFromFile($filename)
|
||||
{
|
||||
$fp = fopen(dirname(dirname(__FILE__)) . '/_files/' . $filename, 'rb');
|
||||
$response = new HTTP_Request2_Response(fgets($fp));
|
||||
do {
|
||||
$headerLine = fgets($fp);
|
||||
$response->parseHeaderLine($headerLine);
|
||||
} while ('' != trim($headerLine));
|
||||
|
||||
while (!feof($fp)) {
|
||||
$response->appendBody(fread($fp, 1024));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
391
vendor/pear/http_request2/tests/Request2Test.php
vendored
391
vendor/pear/http_request2/tests/Request2Test.php
vendored
|
|
@ -1,391 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Sets up includes */
|
||||
require_once dirname(__FILE__) . '/TestHelper.php';
|
||||
|
||||
/**
|
||||
* Class representing a HTTP request
|
||||
*/
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
/**
|
||||
* Unit test for HTTP_Request2 class
|
||||
*/
|
||||
class HTTP_Request2Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructorSetsDefaults()
|
||||
{
|
||||
$url = new Net_URL2('http://www.example.com/foo');
|
||||
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST, array('connect_timeout' => 666));
|
||||
|
||||
$this->assertSame($url, $req->getUrl());
|
||||
$this->assertEquals(HTTP_Request2::METHOD_POST, $req->getMethod());
|
||||
$this->assertEquals(666, $req->getConfig('connect_timeout'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testSetUrl()
|
||||
{
|
||||
$urlString = 'http://www.example.com/foo/bar.php';
|
||||
$url = new Net_URL2($urlString);
|
||||
|
||||
$req1 = new HTTP_Request2();
|
||||
$req1->setUrl($url);
|
||||
$this->assertSame($url, $req1->getUrl());
|
||||
|
||||
$req2 = new HTTP_Request2();
|
||||
$req2->setUrl($urlString);
|
||||
$this->assertInstanceOf('Net_URL2', $req2->getUrl());
|
||||
$this->assertEquals($urlString, $req2->getUrl()->getUrl());
|
||||
|
||||
$req3 = new HTTP_Request2();
|
||||
$req3->setUrl(array('This will cause an error'));
|
||||
}
|
||||
|
||||
public function testConvertUserinfoToAuth()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setUrl('http://foo:b%40r@www.example.com/');
|
||||
|
||||
$this->assertEquals('', (string)$req->getUrl()->getUserinfo());
|
||||
$this->assertEquals(
|
||||
array('user' => 'foo', 'password' => 'b@r', 'scheme' => HTTP_Request2::AUTH_BASIC),
|
||||
$req->getAuth()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testSetMethod()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setMethod(HTTP_Request2::METHOD_PUT);
|
||||
$this->assertEquals(HTTP_Request2::METHOD_PUT, $req->getMethod());
|
||||
|
||||
$req->setMethod('Invalid method');
|
||||
}
|
||||
|
||||
public function testSetAndGetConfig()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$this->assertArrayHasKey('connect_timeout', $req->getConfig());
|
||||
|
||||
$req->setConfig(array('connect_timeout' => 123));
|
||||
$this->assertEquals(123, $req->getConfig('connect_timeout'));
|
||||
try {
|
||||
$req->setConfig(array('foo' => 'unknown parameter'));
|
||||
$this->fail('Expected HTTP_Request2_LogicException was not thrown');
|
||||
} catch (HTTP_Request2_LogicException $e) {}
|
||||
|
||||
try {
|
||||
$req->getConfig('bar');
|
||||
$this->fail('Expected HTTP_Request2_LogicException was not thrown');
|
||||
} catch (HTTP_Request2_LogicException $e) {}
|
||||
}
|
||||
|
||||
public function testSetProxyAsUrl()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setConfig('proxy', 'socks5://foo:bar%25baz@localhost:1080/');
|
||||
|
||||
$this->assertEquals('socks5', $req->getConfig('proxy_type'));
|
||||
$this->assertEquals('localhost', $req->getConfig('proxy_host'));
|
||||
$this->assertEquals(1080, $req->getConfig('proxy_port'));
|
||||
$this->assertEquals('foo', $req->getConfig('proxy_user'));
|
||||
$this->assertEquals('bar%baz', $req->getConfig('proxy_password'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testHeaders()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$autoHeaders = $req->getHeaders();
|
||||
|
||||
$req->setHeader('Foo', 'Bar');
|
||||
$req->setHeader('Foo-Bar: value');
|
||||
$req->setHeader(array('Another-Header' => 'another value', 'Yet-Another: other_value'));
|
||||
$this->assertEquals(
|
||||
array('foo-bar' => 'value', 'another-header' => 'another value',
|
||||
'yet-another' => 'other_value', 'foo' => 'Bar') + $autoHeaders,
|
||||
$req->getHeaders()
|
||||
);
|
||||
|
||||
$req->setHeader('FOO-BAR');
|
||||
$req->setHeader(array('aNOTHER-hEADER'));
|
||||
$this->assertEquals(
|
||||
array('yet-another' => 'other_value', 'foo' => 'Bar') + $autoHeaders,
|
||||
$req->getHeaders()
|
||||
);
|
||||
|
||||
$req->setHeader('Invalid header', 'value');
|
||||
}
|
||||
|
||||
public function testBug15937()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$autoHeaders = $req->getHeaders();
|
||||
|
||||
$req->setHeader('Expect: ');
|
||||
$req->setHeader('Foo', '');
|
||||
$this->assertEquals(
|
||||
array('expect' => '', 'foo' => '') + $autoHeaders,
|
||||
$req->getHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequest17507()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
|
||||
$req->setHeader('accept-charset', 'iso-8859-1');
|
||||
$req->setHeader('accept-charset', array('windows-1251', 'utf-8'), false);
|
||||
|
||||
$req->setHeader(array('accept' => 'text/html'));
|
||||
$req->setHeader(array('accept' => 'image/gif'), null, false);
|
||||
|
||||
$headers = $req->getHeaders();
|
||||
|
||||
$this->assertEquals('iso-8859-1, windows-1251, utf-8', $headers['accept-charset']);
|
||||
$this->assertEquals('text/html, image/gif', $headers['accept']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testCookies()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->addCookie('name', 'value');
|
||||
$req->addCookie('foo', 'bar');
|
||||
$headers = $req->getHeaders();
|
||||
$this->assertEquals('name=value; foo=bar', $headers['cookie']);
|
||||
|
||||
$req->addCookie('invalid cookie', 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testPlainBody()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setBody('A string');
|
||||
$this->assertEquals('A string', $req->getBody());
|
||||
|
||||
$req->setBody(dirname(__FILE__) . '/_files/plaintext.txt', true);
|
||||
$headers = $req->getHeaders();
|
||||
$this->assertRegexp(
|
||||
'!^(text/plain|application/octet-stream)!',
|
||||
$headers['content-type']
|
||||
);
|
||||
$this->assertEquals('This is a test.', fread($req->getBody(), 1024));
|
||||
|
||||
$req->setBody('missing file', true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testRequest16863()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setBody(fopen(dirname(__FILE__) . '/_files/plaintext.txt', 'rb'));
|
||||
$headers = $req->getHeaders();
|
||||
$this->assertEquals('application/octet-stream', $headers['content-type']);
|
||||
|
||||
$req->setBody(fopen('php://input', 'rb'));
|
||||
}
|
||||
|
||||
public function testUrlencodedBody()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$req->addPostParameter('foo', 'bar');
|
||||
$req->addPostParameter(array('baz' => 'quux'));
|
||||
$req->addPostParameter('foobar', array('one', 'two'));
|
||||
$this->assertEquals(
|
||||
'foo=bar&baz=quux&foobar%5B0%5D=one&foobar%5B1%5D=two',
|
||||
$req->getBody()
|
||||
);
|
||||
|
||||
$req->setConfig(array('use_brackets' => false));
|
||||
$this->assertEquals(
|
||||
'foo=bar&baz=quux&foobar=one&foobar=two',
|
||||
$req->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequest15368()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$req->addPostParameter('foo', 'te~st');
|
||||
$this->assertContains('~', $req->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
* @expectedExceptionMessage missing file
|
||||
*/
|
||||
public function testUpload()
|
||||
{
|
||||
$req = new HTTP_Request2(null, HTTP_Request2::METHOD_POST);
|
||||
$req->addUpload('upload', dirname(__FILE__) . '/_files/plaintext.txt');
|
||||
|
||||
$headers = $req->getHeaders();
|
||||
$this->assertEquals('multipart/form-data', $headers['content-type']);
|
||||
|
||||
$req->addUpload('upload_2', 'missing file');
|
||||
}
|
||||
|
||||
public function testPropagateUseBracketsToNetURL2()
|
||||
{
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_GET,
|
||||
array('use_brackets' => false));
|
||||
$req->getUrl()->setQueryVariable('foo', array('bar', 'baz'));
|
||||
$this->assertEquals('http://www.example.com/?foo=bar&foo=baz', $req->getUrl()->__toString());
|
||||
|
||||
$req->setConfig('use_brackets', true)->setUrl('http://php.example.com/');
|
||||
$req->getUrl()->setQueryVariable('foo', array('bar', 'baz'));
|
||||
$this->assertEquals('http://php.example.com/?foo[0]=bar&foo[1]=baz', $req->getUrl()->__toString());
|
||||
}
|
||||
|
||||
public function testSetBodyRemovesPostParameters()
|
||||
{
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
|
||||
$req->addPostParameter('foo', 'bar');
|
||||
$req->setBody('');
|
||||
$this->assertEquals('', $req->getBody());
|
||||
}
|
||||
|
||||
public function testPostParametersPrecedeSetBodyForPost()
|
||||
{
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
|
||||
$req->setBody('Request body');
|
||||
$req->addPostParameter('foo', 'bar');
|
||||
|
||||
$this->assertEquals('foo=bar', $req->getBody());
|
||||
|
||||
$req->setMethod(HTTP_Request2::METHOD_PUT);
|
||||
$this->assertEquals('Request body', $req->getBody());
|
||||
}
|
||||
|
||||
public function testSetMultipartBody()
|
||||
{
|
||||
require_once 'HTTP/Request2/MultipartBody.php';
|
||||
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
|
||||
$body = new HTTP_Request2_MultipartBody(array('foo' => 'bar'), array());
|
||||
$req->setBody($body);
|
||||
$this->assertSame($body, $req->getBody());
|
||||
}
|
||||
|
||||
public function testBug17460()
|
||||
{
|
||||
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_POST);
|
||||
$req->addPostParameter('foo', 'bar')
|
||||
->setHeader('content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
||||
|
||||
$this->assertEquals('foo=bar', $req->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
*/
|
||||
public function testCookieJar()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$this->assertNull($req->getCookieJar());
|
||||
|
||||
$req->setCookieJar();
|
||||
$jar = $req->getCookieJar();
|
||||
$this->assertInstanceOf('HTTP_Request2_CookieJar', $jar);
|
||||
|
||||
$req2 = new HTTP_Request2();
|
||||
$req2->setCookieJar($jar);
|
||||
$this->assertSame($jar, $req2->getCookieJar());
|
||||
|
||||
$req2->setCookieJar(null);
|
||||
$this->assertNull($req2->getCookieJar());
|
||||
|
||||
$req2->setCookieJar('foo');
|
||||
}
|
||||
|
||||
public function testAddCookieToJar()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->setCookieJar();
|
||||
|
||||
try {
|
||||
$req->addCookie('foo', 'bar');
|
||||
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
||||
} catch (HTTP_Request2_LogicException $e) { }
|
||||
|
||||
$req->setUrl('http://example.com/path/file.php');
|
||||
$req->addCookie('foo', 'bar');
|
||||
|
||||
$this->assertArrayNotHasKey('cookie', $req->getHeaders());
|
||||
$cookies = $req->getCookieJar()->getAll();
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'name' => 'foo',
|
||||
'value' => 'bar',
|
||||
'domain' => 'example.com',
|
||||
'path' => '/path/',
|
||||
'expires' => null,
|
||||
'secure' => false
|
||||
),
|
||||
$cookies[0]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
* @expectedExceptionMessage none
|
||||
*/
|
||||
public function testDisallowEmptyUrls()
|
||||
{
|
||||
$req = new HTTP_Request2();
|
||||
$req->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException HTTP_Request2_LogicException
|
||||
* @expectedExceptionMessage '/foo/bar.php'
|
||||
*/
|
||||
public function testDisallowRelativeUrls()
|
||||
{
|
||||
$req = new HTTP_Request2('/foo/bar.php');
|
||||
$req->send();
|
||||
}
|
||||
}
|
||||
?>
|
||||
51
vendor/pear/http_request2/tests/TestHelper.php
vendored
51
vendor/pear/http_request2/tests/TestHelper.php
vendored
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for HTTP_Request2 package
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/** Include PHPUnit dependencies based on version */
|
||||
require_once 'PHPUnit/Runner/Version.php';
|
||||
|
||||
// If running from SVN checkout, update include_path
|
||||
if ('@' . 'package_version@' == '@package_version@') {
|
||||
$classPath = realpath(dirname(dirname(__FILE__)));
|
||||
$includePath = array_map('realpath', explode(PATH_SEPARATOR, get_include_path()));
|
||||
if (0 !== ($key = array_search($classPath, $includePath))) {
|
||||
if (false !== $key) {
|
||||
unset($includePath[$key]);
|
||||
}
|
||||
set_include_path($classPath . PATH_SEPARATOR . implode(PATH_SEPARATOR, $includePath));
|
||||
}
|
||||
}
|
||||
|
||||
$phpunitVersion = PHPUnit_Runner_Version::id();
|
||||
if ($phpunitVersion == '@' . 'package_version@' || !version_compare($phpunitVersion, '3.8', '<=')) {
|
||||
echo "This version of PHPUnit is not supported.";
|
||||
exit(1);
|
||||
} elseif (version_compare($phpunitVersion, '3.5.0', '>=')) {
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
} else {
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
}
|
||||
|
||||
if (!defined('HTTP_REQUEST2_TESTS_BASE_URL')
|
||||
&& is_readable(dirname(__FILE__) . '/NetworkConfig.php')
|
||||
) {
|
||||
require_once dirname(__FILE__) . '/NetworkConfig.php';
|
||||
}
|
||||
?>
|
||||
BIN
vendor/pear/http_request2/tests/_files/bug_15305
vendored
BIN
vendor/pear/http_request2/tests/_files/bug_15305
vendored
Binary file not shown.
|
|
@ -1,9 +0,0 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Fri, 01 Jan 2010 02:03:04 GMT
|
||||
Server: Apache/3.0.1 (Unix)
|
||||
X-Powered-By: PHP/6.2.2
|
||||
Content-Type: text/plain; charset=iso-8859-1
|
||||
Content-Encoding: deflate
|
||||
Content-Length: 0
|
||||
Connection: close
|
||||
|
||||
BIN
vendor/pear/http_request2/tests/_files/empty.gif
vendored
BIN
vendor/pear/http_request2/tests/_files/empty.gif
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 43 B |
|
|
@ -1 +0,0 @@
|
|||
This is a test.
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Fri, 01 Jan 2010 02:03:04 GMT
|
||||
Server: Apache/3.0.1 (Unix)
|
||||
X-Powered-By: PHP/6.2.2
|
||||
Set-Cookie: foo=bar
|
||||
Set-Cookie: PHPSESSID=1234567890abcdef1234567890abcdef; path=/; secure
|
||||
Set-Cookie: A=B=C
|
||||
Set-Cookie: baz=%20a%20value; expires=Sun, 03 Jan 2010 03:04:05 GMT; domain=pear.php.net
|
||||
Content-Type: text/html; charset=windows-1251
|
||||
Content-Length: 32
|
||||
Connection: close
|
||||
|
||||
Nothing to see here, move along.
|
||||
Binary file not shown.
BIN
vendor/pear/http_request2/tests/_files/response_gzip
vendored
BIN
vendor/pear/http_request2/tests/_files/response_gzip
vendored
Binary file not shown.
Binary file not shown.
|
|
@ -1,12 +0,0 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Fri, 01 Jan 2010 02:03:04 GMT
|
||||
Vary: accept-charset
|
||||
Server: Apache/3.0.1 (Unix)
|
||||
X-Powered-By: PHP/6.2.2
|
||||
Vary: user-agent
|
||||
Content-Type: text/html;
|
||||
charset=windows-1251
|
||||
Content-Length: 32
|
||||
Connection: close
|
||||
|
||||
Nothing to see here, move along.
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null;
|
||||
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null;
|
||||
$wantedUser = isset($_GET['user']) ? $_GET['user'] : null;
|
||||
$wantedPass = isset($_GET['pass']) ? $_GET['pass'] : null;
|
||||
|
||||
if (!$user || !$pass || $user != $wantedUser || $pass != $wantedPass) {
|
||||
header('WWW-Authenticate: Basic realm="HTTP_Request2 tests"', true, 401);
|
||||
echo "Login required";
|
||||
} else {
|
||||
echo "Username={$user};Password={$pass}";
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
for ($j = 0; $j < 10; $j++) {
|
||||
echo str_repeat((string)$j, 98) . "\r\n";
|
||||
}
|
||||
flush();
|
||||
usleep(50000);
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
ksort($_COOKIE);
|
||||
echo serialize($_COOKIE);
|
||||
|
||||
?>
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mostly borrowed from PHP manual and Socket Adapter implementation
|
||||
*
|
||||
* @link http://php.net/manual/en/features.http-auth.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses the Digest auth header
|
||||
*
|
||||
* @param string $txt
|
||||
*/
|
||||
function http_digest_parse($txt)
|
||||
{
|
||||
$token = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+';
|
||||
$quoted = '"(?:\\\\.|[^\\\\"])*"';
|
||||
|
||||
// protect against missing data
|
||||
$needed_parts = array_flip(array('nonce', 'nc', 'cnonce', 'qop', 'username', 'uri', 'response'));
|
||||
$data = array();
|
||||
|
||||
preg_match_all("!({$token})\\s*=\\s*({$token}|{$quoted})!", $txt, $matches);
|
||||
for ($i = 0; $i < count($matches[0]); $i++) {
|
||||
// ignore unneeded parameters
|
||||
if (isset($needed_parts[$matches[1][$i]])) {
|
||||
unset($needed_parts[$matches[1][$i]]);
|
||||
if ('"' == substr($matches[2][$i], 0, 1)) {
|
||||
$data[$matches[1][$i]] = substr($matches[2][$i], 1, -1);
|
||||
} else {
|
||||
$data[$matches[1][$i]] = $matches[2][$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !empty($needed_parts) ? false : $data;
|
||||
}
|
||||
|
||||
$realm = 'HTTP_Request2 tests';
|
||||
$wantedUser = isset($_GET['user']) ? $_GET['user'] : null;
|
||||
$wantedPass = isset($_GET['pass']) ? $_GET['pass'] : null;
|
||||
$validAuth = false;
|
||||
|
||||
if (!empty($_SERVER['PHP_AUTH_DIGEST'])
|
||||
&& ($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST']))
|
||||
&& $wantedUser == $data['username']
|
||||
) {
|
||||
// generate the valid response
|
||||
$a1 = md5($data['username'] . ':' . $realm . ':' . $wantedPass);
|
||||
$a2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
|
||||
$response = md5($a1. ':' . $data['nonce'] . ':' . $data['nc'] . ':'
|
||||
. $data['cnonce'] . ':' . $data['qop'] . ':' . $a2);
|
||||
|
||||
// check valid response against existing one
|
||||
$validAuth = ($data['response'] == $response);
|
||||
}
|
||||
|
||||
if (!$validAuth || empty($_SERVER['PHP_AUTH_DIGEST'])) {
|
||||
header('WWW-Authenticate: Digest realm="' . $realm .
|
||||
'",qop="auth",nonce="' . uniqid() . '"', true, 401);
|
||||
echo "Login required";
|
||||
} else {
|
||||
echo "Username={$user}";
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
ksort($_GET);
|
||||
echo serialize($_GET);
|
||||
|
||||
?>
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
ksort($_POST);
|
||||
echo serialize($_POST);
|
||||
|
||||
?>
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
readfile('php://input');
|
||||
?>
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
$redirects = isset($_GET['redirects'])? $_GET['redirects']: 1;
|
||||
$https = !empty($_SERVER['HTTPS']) && ('off' != strtolower($_SERVER['HTTPS']));
|
||||
$special = isset($_GET['special'])? $_GET['special']: null;
|
||||
|
||||
if ('ftp' == $special) {
|
||||
header('Location: ftp://localhost/pub/exploit.exe', true, 301);
|
||||
|
||||
} elseif ('relative' == $special) {
|
||||
header('Location: ./getparameters.php?msg=did%20relative%20redirect', true, 302);
|
||||
|
||||
} elseif ('cookie' == $special) {
|
||||
setcookie('cookie_on_redirect', 'success');
|
||||
header('Location: ./cookies.php', true, 302);
|
||||
|
||||
} elseif ($redirects > 0) {
|
||||
$url = ($https? 'https': 'http') . '://' . $_SERVER['SERVER_NAME']
|
||||
. (($https && 443 == $_SERVER['SERVER_PORT'] || !$https && 80 == $_SERVER['SERVER_PORT'])
|
||||
? '' : ':' . $_SERVER['SERVER_PORT'])
|
||||
. $_SERVER['PHP_SELF'] . '?redirects=' . (--$redirects);
|
||||
header('Location: ' . $url, true, 302);
|
||||
|
||||
} else {
|
||||
echo "Method=" . $_SERVER['REQUEST_METHOD'] . ';';
|
||||
var_dump($_POST);
|
||||
var_dump($_GET);
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
$name = empty($_GET['name'])? 'foo': $_GET['name'];
|
||||
$value = empty($_GET['value'])? 'bar': $_GET['value'];
|
||||
|
||||
setcookie($name, $value);
|
||||
|
||||
echo "Cookie set!";
|
||||
?>
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
sleep(5);
|
||||
|
||||
?>
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to BSD 3-Clause License that is bundled
|
||||
* with this package in the file LICENSE and available at the URL
|
||||
* https://raw.github.com/pear/HTTP_Request2/trunk/docs/LICENSE
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Request2
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @copyright 2008-2014 Alexey Borzov <avb@php.net>
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
|
||||
* @link http://pear.php.net/package/HTTP_Request2
|
||||
*/
|
||||
|
||||
if (isset($_GET['slowpoke'])) {
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
if (!empty($_FILES)) {
|
||||
foreach ($_FILES as $name => $file) {
|
||||
if (is_array($file['name'])) {
|
||||
foreach($file['name'] as $k => $v) {
|
||||
echo "{$name}[{$k}] {$v} {$file['type'][$k]} {$file['size'][$k]}\n";
|
||||
}
|
||||
} else {
|
||||
echo "{$name} {$file['name']} {$file['type']} {$file['size']}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue