Projects
Kolab:3.4
php-pear-HTTP-Request2
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 13
View file
php5-pear-HTTP_Request2.changes
Deleted
@@ -1,46 +0,0 @@ -------------------------------------------------------------------- -Mon Jun 17 13:11:58 UTC 2013 - aj@ajaissle.de - -- Fix CookieJar.php checksum in package.xml (bnc#825249) - -------------------------------------------------------------------- -Fri Feb 1 09:06:09 UTC 2013 - aj@ajaissle.de - -- New upstream version 2.1.1 - -- Changelog 2.1.1 - * Fixes for SOCKS5 proxies support in Socket adapter - -- Changelog 2.1.0 - * 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 - - -- Changelog 2.0.0 - * 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 - -- Moved http_request2.patch into the spec file (sed) - -------------------------------------------------------------------- -Sat Sep 10 16:54:27 CEST 2011 - gerrit.beine@gmx.de - -- initial version 1.7.12
View file
php-pear-HTTP-Request2.spec
Added
@@ -0,0 +1,235 @@ +# spec file for php-pear-HTTP-Request2 +# +# Copyright (c) 2009-2014 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/3.0/ +# +# Please, preserve the changelog entries +# +%{!?__pear: %{expand: %%global __pear %{_bindir}/pear}} + +# Needed for openSUSE +%if 0%{?suse_version} +%{!?pear_cfgdir: %global pear_cfgdir %(%{__pear} config-get cfg_dir 2> /dev/null || echo undefined)} +%{!?pear_datadir: %global pear_datadir %(%{__pear} config-get data_dir 2> /dev/null || echo undefined)} +%{!?pear_docdir: %global pear_docdir %(%{__pear} config-get doc_dir 2> /dev/null || echo undefined)} +%{!?pear_metadir: %global pear_metadir %(%{__pear} config-get metadata_dir 2> /dev/null || echo undefined)} +%{!?pear_phpdir: %global pear_phpdir %(%{__pear} config-get php_dir 2> /dev/null || echo undefined)} +%{!?pear_testdir: %global pear_testdir %(%{__pear} config-get test_dir 2> /dev/null || echo undefined)} +%{!?pear_wwwdir: %global pear_wwwdir %(%{__pear} config-get www_dir 2> /dev/null || echo undefined)} +%{!?pear_xmldir: %global pear_xmldir %{_localstatedir}/lib/pear/pkgxml} +%endif + +%global pear_name HTTP_Request2 + +%if 0%{?suse_version} > 0 +Name: php5-pear-HTTP_Request2 +%else +Name: php-pear-HTTP-Request2 +%endif +Version: 2.2.1 +Release: 2%{?dist} +Summary: Provides an easy way to perform HTTP requests + +Group: Development/Libraries +License: BSD +URL: http://pear.php.net/package/HTTP_Request2 +Source0: http://pear.php.net/get/%{pear_name}-%{version}.tgz +Source2: xml2changelog + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildArch: noarch +%if 0%{?suse_version} > 0 +BuildRequires: php-pear >= 1.9.2 +%else +BuildRequires: php-pear(PEAR) >= 1.9.2 +%endif +# For test suite +%if 0%{?with_tests} +BuildRequires: php-pear(pear.phpunit.de/PHPUnit) +BuildRequires: php-pear(Net_URL2) >= 2.0.0 +%endif +# for xml2changelog +BuildRequires: php-simplexml + +Requires(post): %{__pear} +Requires(postun): %{__pear} +Provides: php-pear(%{pear_name}) = %{version} +# From package.xml +Requires: php-pear(Net_URL2) >= 2.0.0 +%if 0%{?suse_version} > 0 +Requires: php-pear >= 1.9.2 +%else +Requires: php-pear(PEAR) >= 1.9.2 +%endif + +# From package.xml, optional +Requires: php-curl +Requires: php-fileinfo +Requires: php-openssl +Requires: php-zlib +# From phpcompatinfo report for version 2.2.0 +Requires: php-date +Requires: php-mbstring +Requires: php-pcre +Requires: php-spl + + +%description +PHP5 rewrite of HTTP_Request package. Provides cleaner API and pluggable +Adapters. Currently available are: + * 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, proxies, gzip and deflate encodings, monitoring +the request progress with Observers... + + +%prep +%setup -q -c + +# Generate Changelog +%{_bindir}/php %{SOURCE2} package.xml >CHANGELOG +# Display Version / API +head -n 1 < CHANGELOG + +cd %{pear_name}-%{version} +# package.xml is V2 +mv ../package.xml %{name}.xml + + +%build +cd %{pear_name}-%{version} +# Empty build section, most likely nothing required. + + +%install +rm -rf %{buildroot} +install -Dpm 644 CHANGELOG %{buildroot}%{pear_docdir}/%{pear_name}/CHANGELOG + +cd %{pear_name}-%{version} +%{__pear} install --nodeps --packagingroot %{buildroot} %{name}.xml + +# for rpmlint +sed -i -e 's/\r//' %{buildroot}%{pear_docdir}/%{pear_name}/examples/upload-rapidshare.php + +# Clean up unnecessary files +rm -rf %{buildroot}%{pear_metadir}/.??* +%{__rm} -rf %{buildroot}%{pear_phpdir}/.{filemap,lock,registry,channels,depdb,depdblock} +%{__rm} -rf %{buildroot}/usr/share/php5/PEAR/.{filemap,lock,registry,channels,depdb,depdblock} + +# Install XML package description +mkdir -p %{buildroot}%{pear_xmldir} +install -pm 644 %{name}.xml %{buildroot}%{pear_xmldir} + + +%check +%if 0%{?with_tests} +cd %{pear_name}-%{version}/tests +# Tests: 97, Assertions: 171, Skipped: 3. + +phpunit \ + -d date.timezone=UTC \ + -d include_path=.:%{buildroot}%{pear_phpdir}:%{pear_phpdir} \ + AllTests.php +%else +echo 'Test suite disabled (missing "--with tests" option)' +%endif + + +%clean +rm -rf %{buildroot} + + +%post +%{__pear} install --nodeps --soft --force --register-only \ + %{pear_xmldir}/%{name}.xml >/dev/null || : + +%postun +if [ $1 -eq 0 ] ; then + %{__pear} uninstall --nodeps --ignore-errors --register-only \ + pear.php.net/%{pear_name} >/dev/null || : +fi + + +%files +%defattr(-,root,root,-) +%doc %{pear_docdir}/%{pear_name} +%{pear_xmldir}/%{name}.xml +%{pear_phpdir}/HTTP +%{pear_testdir}/%{pear_name} +%{pear_datadir}/%{pear_name} +%{pear_xmldir} + +%changelog +* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.2.1-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild + +* Fri Jan 17 2014 Remi Collet <remi@fedoraproject.org> - 2.2.1-1 +- update to 2.2.1 (stable) + +* Mon Jan 13 2014 Remi Collet <remi@fedoraproject.org> - 2.2.0-1 +- update to 2.2.0 (stable) +- https://pear.php.net/bugs/20176 - corrupted archive +- https://pear.php.net/bugs/20175 - license + +* Mon Aug 5 2013 Remi Collet <remi@fedoraproject.org> - 2.1.1-8 +- xml2change need simplexml + +* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1.1-7 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild + +* Thu Feb 14 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1.1-6 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild + +* Mon Dec 03 2012 Remi Collet <remi@fedoraproject.org> - 2.1.1-5 +- add requires on all extensions + +* Sun Aug 19 2012 Remi Collet <remi@fedoraproject.org> - 2.1.1-4 +- rebuilt for new pear_datadir + +* Tue Aug 14 2012 Remi Collet <remi@fedoraproject.org> - 2.1.1-3 +- rebuilt for new pear_testdir + +* Fri Jul 20 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1.1-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Sat May 12 2012 Remi Collet <remi@fedoraproject.org> - 2.1.1-1 +- Version 2.1.1 (stable) - API 2.1.0 (stable)
View file
php5-pear-HTTP_Request2.spec
Deleted
@@ -1,113 +0,0 @@ -# -# spec file for package php5-pear-HTTP_Request2 -# -# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. -# -# All modifications and additions to the file contributed by third parties -# remain the property of their copyright owners, unless otherwise agreed -# upon. The license for this file, and modifications and additions to the -# file, is the same license as for the pristine package itself (unless the -# license for the pristine package is not an Open Source License, in which -# case the license is the MIT License). An "Open Source License" is a -# license that conforms to the Open Source Definition (Version 1.9) -# published by the Open Source Initiative. - -# Please submit bugfixes or comments via http://bugs.opensuse.org/ -# - - -Name: php5-pear-HTTP_Request2 -%define pear_name HTTP_Request2 -%define pear_sname HTTP_Request2 -Summary: Provides an easy way to perform HTTP requests -License: PHP-3.01 -Group: Development/Libraries/PHP -Version: 2.1.1 -Release: 0 -BuildArch: noarch -Url: http://pear.php.net/package/%{pear_name} -Source: %{pear_name}-%{version}.tgz -# http_request2.patch: Patch CookieJar.php to not containg buildroot fragments -Patch1: http_request2.patch -BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: php >= 5.2 -%if 0%{?sles_version} == 10 -BuildRequires: php-macros -%else -BuildRequires: php-devel >= 5.2 -%endif -BuildRequires: php-pear >= 1.9.2 -Requires: php >= 5.2 -Requires: php-pear >= 1.9.2 -Requires: php-pear-Net_URL2 >= 2.0.0 - -Provides: pear-%{pear_name} -Provides: pear-%{pear_sname} = %{version} -Provides: php-pear-%{pear_name} -Provides: php-pear-%{pear_sname} = %{version} -Provides: php-pear(%{pear_sname}) = %{version} -Provides: php5-pear-%{pear_sname} = %{version} -Obsoletes: pear-%{pear_sname} < %{version} -Obsoletes: php-pear-%{pear_sname} < %{version} -Obsoletes: php5-pear-%{pear_sname} < %{version} - -%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... - -%prep -%setup -c -%patch1 -p1 - -# Patch package.xml to lower the required PEAR version to enable build -%if 0%{?suse_version} < 1200 && 0%{?sles_version} != 11 -sed -i 's/1.9.2/1.9.1/g' package.xml -%endif - -%build - -%install -%{__mv} package*.xml %{pear_name}-%{version} -cd %{pear_name}-%{version} -PHP_PEAR_PHP_BIN="$(which php) -d memory_limit=50m" -%{__pear} -v \ - -d bin_dir=%{_bindir} \ - -d data_dir=%{php_peardir}/data \ - -d test_dir=%{peardir}/tests \ - install --offline --nodeps -R "%{buildroot}" package.xml - -%{__install} -D -m 0644 package.xml %{buildroot}%{php_pearxmldir}/%{pear_name}.xml - -%{__rm} -rf %{buildroot}/{doc,tmp} -%{__rm} -rf %{buildroot}%{php_peardir}/.{filemap,lock,registry,channels,depdb,depdblock} - -cd .. - -%php_pear_gen_filelist - -%post -if [ "$1" = "1" ]; then - %{__pear} install --nodeps --soft --force --register-only %{php_pearxmldir}/%{pear_name}.xml -fi -if [ "$1" = "2" ]; then - %{__pear} upgrade --offline --register-only %{php_pearxmldir}/%{pear_name}.xml -fi - -%postun -if [ "$1" = "0" ]; then - %{__pear} uninstall --nodeps --ignore-errors --register-only pear.php.net/%{pear_name} -fi - -%clean -%{__rm} -rf %{buildroot} - -%files -f %{name}.files -%defattr(-, root, root) - -%changelog
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2.php
Deleted
@@ -1,1050 +0,0 @@ -<?php -/** - * Class representing a HTTP request message - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324936 2012-04-07 07:49:03Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.1 - * @link http://pear.php.net/package/HTTP_Request2 - * @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, - 'proxy_type' => 'http', - - '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(); -
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Adapter.php
Deleted
@@ -1,157 +0,0 @@ -<?php -/** - * Base class for HTTP_Request2 adapters - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324415 2012-03-21 10:50:50Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.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'; - } - $headers['content-length'] = $this->contentLength; - } - } -} -?>
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Adapter/Curl.php
Deleted
@@ -1,584 +0,0 @@ -<?php -/** - * Adapter for HTTP_Request2 wrapping around cURL extension - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324746 2012-04-03 15:09:16Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.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())) {
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Adapter/Mock.php
Deleted
@@ -1,189 +0,0 @@ -<?php -/** - * Mock adapter intended for testing - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324937 2012-04-07 10:05:57Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.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; - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Adapter/Socket.php
Deleted
@@ -1,1016 +0,0 @@ -<?php -/** - * Socket-based adapter for HTTP_Request2 - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: Socket.php 324953 2012-04-08 07:24:12Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -/** Base class for HTTP_Request2 adapters */ -require_once 'HTTP/Request2/Adapter.php'; - -/** Socket wrapper class */ -require_once 'HTTP/Request2/SocketWrapper.php'; - -/** - * Socket-based adapter for HTTP_Request2 - * - * This adapter uses only PHP sockets and will work on almost any PHP - * environment. Code is based on original HTTP_Request PEAR package. - * - * @category HTTP - * @package HTTP_Request2 - * @author Alexey Borzov <avb@php.net> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.1 - * @link http://pear.php.net/package/HTTP_Request2 - */ -class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter -{ - /** - * Regular expression for 'token' rule from RFC 2616 - */ - const REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+'; - - /** - * Regular expression for 'quoted-string' rule from RFC 2616 - */ - const REGEXP_QUOTED_STRING = '"(?:\\\\.|[^\\\\"])*"'; - - /** - * Connected sockets, needed for Keep-Alive support - * @var array - * @see connect() - */ - protected static $sockets = array(); - - /** - * Data for digest authentication scheme - * - * The keys for the array are URL prefixes. - * - * The values are associative arrays with data (realm, nonce, nonce-count, - * opaque...) needed for digest authentication. Stored here to prevent making - * duplicate requests to digest-protected resources after we have already - * received the challenge. - * - * @var array - */ - protected static $challenges = array(); - - /** - * Connected socket - * @var HTTP_Request2_SocketWrapper - * @see connect() - */ - protected $socket; - - /** - * Challenge used for server digest authentication - * @var array - */ - protected $serverChallenge; - - /** - * Challenge used for proxy digest authentication - * @var array - */ - protected $proxyChallenge; - - /** - * Remaining length of the current chunk, when reading chunked response - * @var integer - * @see readChunked() - */ - protected $chunkLength = 0; - - /** - * Remaining amount of redirections to follow - * - * Starts at 'max_redirects' configuration parameter and is reduced on each - * subsequent redirect. An Exception will be thrown once it reaches zero. - * - * @var integer - */ - protected $redirectCountdown = null; - - /** - * 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) - { - $this->request = $request; - - try { - $keepAlive = $this->connect(); - $headers = $this->prepareHeaders(); - $this->socket->write($headers); - // provide request headers to the observer, see request #7633 - $this->request->setLastEvent('sentHeaders', $headers); - $this->writeBody(); - - $response = $this->readResponse(); - - if ($jar = $request->getCookieJar()) { - $jar->addCookiesFromResponse($response, $request->getUrl()); - } - - if (!$this->canKeepAlive($keepAlive, $response)) { - $this->disconnect(); - } - - if ($this->shouldUseProxyDigestAuth($response)) { - return $this->sendRequest($request); - } - if ($this->shouldUseServerDigestAuth($response)) { - return $this->sendRequest($request); - } - if ($authInfo = $response->getHeader('authentication-info')) { - $this->updateChallenge($this->serverChallenge, $authInfo); - } - if ($proxyInfo = $response->getHeader('proxy-authentication-info')) { - $this->updateChallenge($this->proxyChallenge, $proxyInfo); - } - - } catch (Exception $e) { - $this->disconnect(); - } - - unset($this->request, $this->requestBody); - - if (!empty($e)) { - $this->redirectCountdown = null; - throw $e; - } - - if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) { - $this->redirectCountdown = null; - return $response; - } else { - return $this->handleRedirect($request, $response); - } - } - - /** - * Connects to the remote server - * - * @return bool whether the connection can be persistent - * @throws HTTP_Request2_Exception - */
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/CookieJar.php
Deleted
@@ -1,517 +0,0 @@ -<?php -/** - * Stores cookies and passes them between HTTP requests - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: CookieJar.php 324415 2012-03-21 10:50:50Z avb $ - * @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-license.php New BSD 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);
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Exception.php
Deleted
@@ -1,183 +0,0 @@ -<?php -/** - * Exception classes for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324415 2012-03-21 10:50:50Z avb $ - * @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-license.php New BSD License - * @version Release: 2.1.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-license.php New BSD License - * @version Release: 2.1.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-license.php New BSD License - * @version Release: 2.1.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-license.php New BSD License - * @version Release: 2.1.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-license.php New BSD License - * @version Release: 2.1.1 - * @link http://pear.php.net/package/HTTP_Request2 - */ -class HTTP_Request2_MessageException extends HTTP_Request2_Exception -{ -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/MultipartBody.php
Deleted
@@ -1,280 +0,0 @@ -<?php -/** - * Helper class for building multipart/form-data request body - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324415 2012-03-21 10:50:50Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.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 - */ - 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);
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Observer/Log.php
Deleted
@@ -1,215 +0,0 @@ -<?php -/** - * An observer useful for debugging / testing. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324415 2012-03-21 10:50:50Z 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: 2.1.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
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/Response.php
Deleted
@@ -1,654 +0,0 @@ -<?php -/** - * Class representing a HTTP response - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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 324936 2012-04-07 07:49:03Z 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> - * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version Release: 2.1.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',
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/SOCKS5.php
Deleted
@@ -1,158 +0,0 @@ -<?php -/** - * SOCKS5 proxy connection class - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: SOCKS5.php 324953 2012-04-08 07:24:12Z avb $ - * @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-license.php New BSD License - * @version Release: 2.1.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 $sslOptions SSL 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 $sslOptions = array(), - $username = null, $password = null - ) { - parent::__construct($address, $timeout, $sslOptions); - - 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'] - ); - } - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/HTTP/Request2/SocketWrapper.php
Deleted
@@ -1,283 +0,0 @@ -<?php -/** - * Socket wrapper class used by Socket Adapter - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: SocketWrapper.php 324935 2012-04-07 07:10:50Z avb $ - * @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-license.php New BSD License - * @version Release: 2.1.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 $sslOptions SSL context options - * - * @throws HTTP_Request2_LogicException - * @throws HTTP_Request2_ConnectionException - */ - public function __construct($address, $timeout, array $sslOptions = array()) - { - $context = stream_context_create(); - foreach ($sslOptions as $name => $value) { - if (!stream_context_set_option($context, 'ssl', $name, $value)) { - throw new HTTP_Request2_LogicException( - "Error setting SSL 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 (!$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 - * - * @return string Available data up to the newline (not including newline) - * @throws HTTP_Request2_MessageException In case of timeout - */ - public function readLine($bufferSize) - { - $line = ''; - while (!feof($this->socket)) { - if ($this->deadline) { - stream_set_timeout($this->socket, max($this->deadline - time(), 1)); - } - $line .= @fgets($this->socket, $bufferSize); - $this->checkTimeout(); - 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 - *
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/data/generate-list.php
Deleted
@@ -1,98 +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. - * - * @version SVN: $Id: generate-list.php 308480 2011-02-19 11:27:13Z avb $ - */ - -/** 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, 'The Original Code is the Public Suffix List.')) { - 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) { - fwrite($fp, $line . "\n"); - - if (0 === strpos($line, "// ***** END LICENSE BLOCK")) { - $license = false; - fwrite($fp, "\n"); - } - } -} - -writeNode($fp, $tldTree); -fwrite($fp, ";\n?>"); -fclose($fp); -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/data/public-suffix-list.php
Deleted
@@ -1,4831 +0,0 @@ -<?php -// ***** BEGIN LICENSE BLOCK ***** -// Version: MPL 1.1/GPL 2.0/LGPL 2.1 -// -// The contents of this file are subject to the Mozilla Public License Version -// 1.1 (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" basis, -// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -// for the specific language governing rights and limitations under the -// License. -// -// The Original Code is the Public Suffix List. -// -// The Initial Developer of the Original Code is -// Jo Hermans <jo.hermans@gmail.com>. -// Portions created by the Initial Developer are Copyright (C) 2007 -// the Initial Developer. All Rights Reserved. -// -// Contributor(s): -// Ruben Arakelyan <ruben@rubenarakelyan.com> -// Gervase Markham <gerv@gerv.net> -// Pamela Greene <pamg.bugs@gmail.com> -// David Triendl <david@triendl.name> -// Jothan Frakes <jothan@gmail.com> -// The kind representatives of many TLD registries -// -// Alternatively, the contents of this file may be used under the terms of -// either the GNU General Public License Version 2 or later (the "GPL"), or -// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -// in which case the provisions of the GPL or the LGPL are applicable instead -// of those above. If you wish to allow use of your version of this file only -// under the terms of either the GPL or the LGPL, and not to allow others to -// use your version of this file under the terms of the MPL, indicate your -// decision by deleting the provisions above and replace them with the notice -// and other provisions required by the GPL or the LGPL. If you do not delete -// the provisions above, a recipient may use your version of this file under -// the terms of any one of the MPL, the GPL or the LGPL. -// -// ***** END LICENSE BLOCK ***** - -return array( - 'ac' => array( - 'com' => true, - 'edu' => true, - 'gov' => true, - 'net' => true, - 'mil' => true, - 'org' => true - ), - 'ad' => array( - 'nom' => true - ), - 'ae' => array( - 'co' => true, - 'net' => true, - 'org' => true, - 'sch' => true, - 'ac' => true, - 'gov' => true, - 'mil' => true - ), - 'aero' => array( - 'accident-investigation' => true, - 'accident-prevention' => true, - 'aerobatic' => true, - 'aeroclub' => true, - 'aerodrome' => true, - 'agents' => true, - 'aircraft' => true, - 'airline' => true, - 'airport' => true, - 'air-surveillance' => true, - 'airtraffic' => true, - 'air-traffic-control' => true, - 'ambulance' => true, - 'amusement' => true, - 'association' => true, - 'author' => true, - 'ballooning' => true, - 'broker' => true, - 'caa' => true, - 'cargo' => true, - 'catering' => true, - 'certification' => true, - 'championship' => true, - 'charter' => true, - 'civilaviation' => true, - 'club' => true, - 'conference' => true, - 'consultant' => true, - 'consulting' => true, - 'control' => true, - 'council' => true, - 'crew' => true, - 'design' => true, - 'dgca' => true, - 'educator' => true, - 'emergency' => true, - 'engine' => true, - 'engineer' => true, - 'entertainment' => true, - 'equipment' => true, - 'exchange' => true, - 'express' => true, - 'federation' => true, - 'flight' => true, - 'freight' => true, - 'fuel' => true, - 'gliding' => true, - 'government' => true, - 'groundhandling' => true, - 'group' => true, - 'hanggliding' => true, - 'homebuilt' => true, - 'insurance' => true, - 'journal' => true, - 'journalist' => true, - 'leasing' => true, - 'logistics' => true, - 'magazine' => true, - 'maintenance' => true, - 'marketplace' => true, - 'media' => true, - 'microlight' => true, - 'modelling' => true, - 'navigation' => true, - 'parachuting' => true, - 'paragliding' => true, - 'passenger-association' => true, - 'pilot' => true, - 'press' => true, - 'production' => true, - 'recreation' => true, - 'repbody' => true, - 'res' => true, - 'research' => true, - 'rotorcraft' => true, - 'safety' => true, - 'scientist' => true, - 'services' => true, - 'show' => true, - 'skydiving' => true, - 'software' => true, - 'student' => true, - 'taxi' => true, - 'trader' => true, - 'trading' => true, - 'trainer' => true, - 'union' => true, - 'workinggroup' => true, - 'works' => true - ), - 'af' => array( - 'gov' => true, - 'com' => true, - 'org' => true, - 'net' => true, - 'edu' => true - ), - 'ag' => array( - 'com' => true, - 'org' => true, - 'net' => true, - 'co' => true, - 'nom' => true - ), - 'ai' => array( - 'off' => true, - 'com' => true, - 'net' => true, - 'org' => true - ), - 'al' => array( - 'com' => true, - 'edu' => true, - 'gov' => true, - 'mil' => true, - 'net' => true, - 'org' => true - ), - 'am' => true, - 'an' => array( - 'com' => true, - 'net' => true, - 'org' => true, - 'edu' => true - ), - 'ao' => array( - 'ed' => true, - 'gv' => true, - 'og' => true, - 'co' => true, - 'pb' => true, - 'it' => true - ), - 'aq' => true,
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/docs/examples/upload-rapidshare.php
Deleted
@@ -1,60 +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 - * - * $Id: upload-rapidshare.php 287307 2009-08-14 15:40:22Z avb $ - */ - -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(); -} -?>
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/AllTests.php
Deleted
@@ -1,77 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: AllTests.php 324415 2012-03-21 10:50:50Z avb $ - * @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(); -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/NetworkConfig.php.dist
Deleted
@@ -1,73 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: NetworkConfig.php.dist 324935 2012-04-07 07:10:50Z avb $ - * @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); - -/**#@+ - * 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'); -/**#@-*/ -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/ObserverTest.php
Deleted
@@ -1,118 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: ObserverTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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); - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/AllTests.php
Deleted
@@ -1,93 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: AllTests.php 324415 2012-03-21 10:50:50Z avb $ - * @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(); -} -?>
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/CommonNetworkTest.php
Deleted
@@ -1,336 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: CommonNetworkTest.php 324935 2012-04-07 07:10:50Z avb $ - * @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 SlowpokeObserver implements SplObserver -{ - public function update(SplSubject $subject) - { - $event = $subject->getLastEvent(); - - // force a timeout when writing request body - if ('sentHeaders' == $event['name']) { - sleep(3); - } - } -} - -/** - * 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($response->getBody(), serialize($data)); - } - - 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($response->getBody(), serialize($data)); - } - - 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($response->getBody(), $data); - } - - 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($response->getBody(), serialize($cookies)); - } - - 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()
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/CurlTest.php
Deleted
@@ -1,143 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: CurlTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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()); - } - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/MockTest.php
Deleted
@@ -1,180 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: MockTest.php 324937 2012-04-07 10:05:57Z avb $ - * @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'); - } -} -?>
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/SkippedTests.php
Deleted
@@ -1,79 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: SkippedTests.php 324415 2012-03-21 10:50:50Z avb $ - * @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'); - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/SocketProxyTest.php
Deleted
@@ -1,78 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: SocketProxyTest.php 324935 2012-04-07 07:10:50Z avb $ - * @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(); - } - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/Adapter/SocketTest.php
Deleted
@@ -1,78 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: SocketTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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(); - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/AllTests.php
Deleted
@@ -1,79 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: AllTests.php 324415 2012-03-21 10:50:50Z avb $ - * @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(); -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/CookieJarTest.php
Deleted
@@ -1,393 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: CookieJarTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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() - {
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/MultipartBodyTest.php
Deleted
@@ -1,125 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: MultipartBodyTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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); - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2/ResponseTest.php
Deleted
@@ -1,151 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: ResponseTest.php 324415 2012-03-21 10:50:50Z avb $ - * @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; - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/Request2Test.php
Deleted
@@ -1,414 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: Request2Test.php 324936 2012-04-07 07:49:03Z avb $ - * @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']); - }
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/TestHelper.php
Deleted
@@ -1,71 +0,0 @@ -<?php -/** - * Unit tests for HTTP_Request2 package - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: TestHelper.php 324415 2012-03-21 10:50:50Z avb $ - * @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 (!in_array($classPath, $includePath)) { - set_include_path($classPath . PATH_SEPARATOR . get_include_path()); - } -} - -$phpunitVersion = PHPUnit_Runner_Version::id(); -if ($phpunitVersion == '@' . 'package_version@' || !version_compare($phpunitVersion, '3.7', '<=')) { - 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'; -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/basicauth.php
Deleted
@@ -1,56 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: basicauth.php 324415 2012-03-21 10:50:50Z avb $ - * @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}"; -} - -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/cookies.php
Deleted
@@ -1,47 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: cookies.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -ksort($_COOKIE); -echo serialize($_COOKIE); - -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/digestauth.php
Deleted
@@ -1,106 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: digestauth.php 324415 2012-03-21 10:50:50Z avb $ - * @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}"; -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/getparameters.php
Deleted
@@ -1,47 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: getparameters.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -ksort($_GET); -echo serialize($_GET); - -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/postparameters.php
Deleted
@@ -1,47 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: postparameters.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -ksort($_POST); -echo serialize($_POST); - -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/rawpostdata.php
Deleted
@@ -1,45 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: rawpostdata.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -readfile('php://input'); -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/redirects.php
Deleted
@@ -1,70 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: redirects.php 324415 2012-03-21 10:50:50Z avb $ - * @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); -} -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/setcookie.php
Deleted
@@ -1,50 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: setcookie.php 324415 2012-03-21 10:50:50Z avb $ - * @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!"; -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/timeout.php
Deleted
@@ -1,46 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: timeout.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -sleep(5); - -?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/HTTP_Request2-2.1.1/tests/_network/uploads.php
Deleted
@@ -1,55 +0,0 @@ -<?php -/** - * Helper files for HTTP_Request2 unit tests. Should be accessible via HTTP. - * - * PHP version 5 - * - * LICENSE: - * - * Copyright (c) 2008-2012, 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: uploads.php 324415 2012-03-21 10:50:50Z avb $ - * @link http://pear.php.net/package/HTTP_Request2 - */ - -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"; - } - } -} -?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2.php
Added
@@ -0,0 +1,1030 @@ +<?php +/** + * Class representing a HTTP request message + * + * 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 + */ + +/** + * 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> + * @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-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, + 'local_ip' => null, + + 'proxy_host' => '', + 'proxy_port' => '', + 'proxy_user' => '', + 'proxy_password' => '', + 'proxy_auth_scheme' => self::AUTH_BASIC, + 'proxy_type' => 'http', + + '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; + + /** + * Cookie jar to persist cookies between requests + * @var HTTP_Request2_CookieJar + */ + protected $cookieJar = null; + + /** + * Constructor. Can set request URL, method and configuration array. + * + * Also sets a default value for User-Agent header.
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Adapter.php
Added
@@ -0,0 +1,137 @@ +<?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; + } + } + } +} +?>
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Adapter/Curl.php
Added
@@ -0,0 +1,567 @@ +<?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); + }
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Adapter/Mock.php
Added
@@ -0,0 +1,166 @@ +<?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; + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Adapter/Socket.php
Added
@@ -0,0 +1,1121 @@ +<?php +/** + * Socket-based adapter for HTTP_Request2 + * + * 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'; + +/** Socket wrapper class */ +require_once 'HTTP/Request2/SocketWrapper.php'; + +/** + * Socket-based adapter for HTTP_Request2 + * + * This adapter uses only PHP sockets and will work on almost any PHP + * environment. Code is based on original HTTP_Request PEAR 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 + */ +class HTTP_Request2_Adapter_Socket extends HTTP_Request2_Adapter +{ + /** + * Regular expression for 'token' rule from RFC 2616 + */ + const REGEXP_TOKEN = '[^\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]+'; + + /** + * Regular expression for 'quoted-string' rule from RFC 2616 + */ + const REGEXP_QUOTED_STRING = '"(?>[^"\\\\]+|\\\\.)*"'; + + /** + * Connected sockets, needed for Keep-Alive support + * @var array + * @see connect() + */ + protected static $sockets = array(); + + /** + * Data for digest authentication scheme + * + * The keys for the array are URL prefixes. + * + * The values are associative arrays with data (realm, nonce, nonce-count, + * opaque...) needed for digest authentication. Stored here to prevent making + * duplicate requests to digest-protected resources after we have already + * received the challenge. + * + * @var array + */ + protected static $challenges = array(); + + /** + * Connected socket + * @var HTTP_Request2_SocketWrapper + * @see connect() + */ + protected $socket; + + /** + * Challenge used for server digest authentication + * @var array + */ + protected $serverChallenge; + + /** + * Challenge used for proxy digest authentication + * @var array + */ + protected $proxyChallenge; + + /** + * Remaining length of the current chunk, when reading chunked response + * @var integer + * @see readChunked() + */ + protected $chunkLength = 0; + + /** + * Remaining amount of redirections to follow + * + * Starts at 'max_redirects' configuration parameter and is reduced on each + * subsequent redirect. An Exception will be thrown once it reaches zero. + * + * @var integer + */ + protected $redirectCountdown = null; + + /** + * Whether to wait for "100 Continue" response before sending request body + * @var bool + */ + protected $expect100Continue = false; + + /** + * Sends request to the remote server and returns its response + * + * @param HTTP_Request2 $request HTTP request message + * + * @return HTTP_Request2_Response + * @throws HTTP_Request2_Exception + */ + public function sendRequest(HTTP_Request2 $request) + { + $this->request = $request; + + try { + $keepAlive = $this->connect(); + $headers = $this->prepareHeaders(); + $this->socket->write($headers); + // provide request headers to the observer, see request #7633 + $this->request->setLastEvent('sentHeaders', $headers); + + if (!$this->expect100Continue) { + $this->writeBody(); + $response = $this->readResponse(); + + } else { + $response = $this->readResponse(); + if (!$response || 100 == $response->getStatus()) { + $this->expect100Continue = false; + // either got "100 Continue" or timed out -> send body + $this->writeBody(); + $response = $this->readResponse(); + } + } + + + if ($jar = $request->getCookieJar()) { + $jar->addCookiesFromResponse($response, $request->getUrl()); + } + + if (!$this->canKeepAlive($keepAlive, $response)) { + $this->disconnect(); + } + + if ($this->shouldUseProxyDigestAuth($response)) { + return $this->sendRequest($request); + } + if ($this->shouldUseServerDigestAuth($response)) { + return $this->sendRequest($request); + } + if ($authInfo = $response->getHeader('authentication-info')) { + $this->updateChallenge($this->serverChallenge, $authInfo); + } + if ($proxyInfo = $response->getHeader('proxy-authentication-info')) { + $this->updateChallenge($this->proxyChallenge, $proxyInfo); + } + + } catch (Exception $e) { + $this->disconnect(); + } + + unset($this->request, $this->requestBody); + + if (!empty($e)) { + $this->redirectCountdown = null; + throw $e; + } + + if (!$request->getConfig('follow_redirects') || !$response->isRedirect()) { + $this->redirectCountdown = null; + return $response; + } else { + return $this->handleRedirect($request, $response); + } + } + + /** + * Connects to the remote server + * + * @return bool whether the connection can be persistent + * @throws HTTP_Request2_Exception + */ + protected function connect() + { + $secure = 0 == strcasecmp($this->request->getUrl()->getScheme(), 'https'); + $tunnel = HTTP_Request2::METHOD_CONNECT == $this->request->getMethod(); + $headers = $this->request->getHeaders();
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/CookieJar.php
Added
@@ -0,0 +1,494 @@ +<?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)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Exception.php
Added
@@ -0,0 +1,160 @@ +<?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 +{ +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/MultipartBody.php
Added
@@ -0,0 +1,268 @@ +<?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);
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Observer/Log.php
Added
@@ -0,0 +1,192 @@ +<?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"); + } + } + + // }}} +} + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/Response.php
Added
@@ -0,0 +1,631 @@ +<?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;
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/SOCKS5.php
Added
@@ -0,0 +1,135 @@ +<?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'] + ); + } + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/HTTP/Request2/SocketWrapper.php
Added
@@ -0,0 +1,297 @@ +<?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) {
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/data/generate-list.php
Added
@@ -0,0 +1,96 @@ +<?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); +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/data/public-suffix-list.php
Added
@@ -0,0 +1,6701 @@ +<?php +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +return array( + 'ac' => array( + 'com' => true, + 'edu' => true, + 'gov' => true, + 'net' => true, + 'mil' => true, + 'org' => true + ), + 'ad' => array( + 'nom' => true + ), + 'ae' => array( + 'co' => true, + 'net' => true, + 'org' => true, + 'sch' => true, + 'ac' => true, + 'gov' => true, + 'mil' => true + ), + 'aero' => array( + 'accident-investigation' => true, + 'accident-prevention' => true, + 'aerobatic' => true, + 'aeroclub' => true, + 'aerodrome' => true, + 'agents' => true, + 'aircraft' => true, + 'airline' => true, + 'airport' => true, + 'air-surveillance' => true, + 'airtraffic' => true, + 'air-traffic-control' => true, + 'ambulance' => true, + 'amusement' => true, + 'association' => true, + 'author' => true, + 'ballooning' => true, + 'broker' => true, + 'caa' => true, + 'cargo' => true, + 'catering' => true, + 'certification' => true, + 'championship' => true, + 'charter' => true, + 'civilaviation' => true, + 'club' => true, + 'conference' => true, + 'consultant' => true, + 'consulting' => true, + 'control' => true, + 'council' => true, + 'crew' => true, + 'design' => true, + 'dgca' => true, + 'educator' => true, + 'emergency' => true, + 'engine' => true, + 'engineer' => true, + 'entertainment' => true, + 'equipment' => true, + 'exchange' => true, + 'express' => true, + 'federation' => true, + 'flight' => true, + 'freight' => true, + 'fuel' => true, + 'gliding' => true, + 'government' => true, + 'groundhandling' => true, + 'group' => true, + 'hanggliding' => true, + 'homebuilt' => true, + 'insurance' => true, + 'journal' => true, + 'journalist' => true, + 'leasing' => true, + 'logistics' => true, + 'magazine' => true, + 'maintenance' => true, + 'marketplace' => true, + 'media' => true, + 'microlight' => true, + 'modelling' => true, + 'navigation' => true, + 'parachuting' => true, + 'paragliding' => true, + 'passenger-association' => true, + 'pilot' => true, + 'press' => true, + 'production' => true, + 'recreation' => true, + 'repbody' => true, + 'res' => true, + 'research' => true, + 'rotorcraft' => true, + 'safety' => true, + 'scientist' => true, + 'services' => true, + 'show' => true, + 'skydiving' => true, + 'software' => true, + 'student' => true, + 'taxi' => true, + 'trader' => true, + 'trading' => true, + 'trainer' => true, + 'union' => true, + 'workinggroup' => true, + 'works' => true + ), + 'af' => array( + 'gov' => true, + 'com' => true, + 'org' => true, + 'net' => true, + 'edu' => true + ), + 'ag' => array( + 'com' => true, + 'org' => true, + 'net' => true, + 'co' => true, + 'nom' => true + ), + 'ai' => array( + 'off' => true, + 'com' => true, + 'net' => true, + 'org' => true + ), + 'al' => array( + 'com' => true, + 'edu' => true, + 'gov' => true, + 'mil' => true, + 'net' => true, + 'org' => true + ), + 'am' => true, + 'an' => array( + 'com' => true, + 'net' => true, + 'org' => true, + 'edu' => true + ), + 'ao' => array( + 'ed' => true, + 'gv' => true, + 'og' => true, + 'co' => true, + 'pb' => true, + 'it' => true + ), + 'aq' => true, + 'ar' => array( + 'com' => array( + 'blogspot' => true + ), + 'edu' => true, + 'gob' => true, + 'int' => true, + 'mil' => true, + 'net' => true, + 'org' => true, + 'tur' => true + ), + 'arpa' => array( + 'e164' => true, + 'in-addr' => true, + 'ip6' => true, + 'iris' => true, + 'uri' => true, + 'urn' => true + ), + 'as' => array( + 'gov' => true + ), + 'asia' => true, + 'at' => array( + 'ac' => true, + 'co' => array( + 'blogspot' => true + ), + 'gv' => true, + 'or' => true, + 'biz' => true, + 'info' => true, + 'priv' => true + ), + 'au' => array( + 'com' => array( + 'blogspot' => true
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/docs/LICENSE
Added
@@ -0,0 +1,31 @@ +HTTP_Request2 + +Copyright (c) 2008-2014, Alexey Borzov <avb@php.net> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of Alexey Borzov nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE.
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/docs/examples/upload-rapidshare.php
Added
@@ -0,0 +1,58 @@ +<?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(); +} +?>
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/AllTests.php
Added
@@ -0,0 +1,54 @@ +<?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(); +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/NetworkConfig.php.dist
Added
@@ -0,0 +1,58 @@ +<?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'); +/**#@-*/ +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/ObserverTest.php
Added
@@ -0,0 +1,95 @@ +<?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); + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/AllTests.php
Added
@@ -0,0 +1,70 @@ +<?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(); +} +?>
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/CommonNetworkTest.php
Added
@@ -0,0 +1,387 @@ +<?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()); + } + } +
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/CurlTest.php
Added
@@ -0,0 +1,120 @@ +<?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()); + } + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/MockTest.php
Added
@@ -0,0 +1,157 @@ +<?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'); + } +} +?>
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/SkippedTests.php
Added
@@ -0,0 +1,56 @@ +<?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'); + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/SocketProxyTest.php
Added
@@ -0,0 +1,55 @@ +<?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(); + } + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/Adapter/SocketTest.php
Added
@@ -0,0 +1,159 @@ +<?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()); + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/AllTests.php
Added
@@ -0,0 +1,56 @@ +<?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(); +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/CookieJarTest.php
Added
@@ -0,0 +1,370 @@ +<?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))); +
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/MultipartBodyTest.php
Added
@@ -0,0 +1,102 @@ +<?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); + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2/ResponseTest.php
Added
@@ -0,0 +1,128 @@ +<?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; + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/Request2Test.php
Added
@@ -0,0 +1,391 @@ +<?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();
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/TestHelper.php
Added
@@ -0,0 +1,51 @@ +<?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'; +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/bug_15305
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/bug_15305)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/bug_18169
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/bug_18169)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/empty.gif
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/empty.gif)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/plaintext.txt
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/plaintext.txt)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/response_cookies
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/response_cookies)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/response_deflate
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/response_deflate)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/response_gzip
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/response_gzip)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/response_gzip_broken
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/response_gzip_broken)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_files/response_headers
Changed
(renamed from HTTP_Request2-2.1.1/tests/_files/response_headers)
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/basicauth.php
Added
@@ -0,0 +1,33 @@ +<?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}"; +} + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/bug19934.php
Added
@@ -0,0 +1,27 @@ +<?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); +} \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/cookies.php
Added
@@ -0,0 +1,24 @@ +<?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); + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/digestauth.php
Added
@@ -0,0 +1,83 @@ +<?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}"; +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/getparameters.php
Added
@@ -0,0 +1,24 @@ +<?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); + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/postparameters.php
Added
@@ -0,0 +1,24 @@ +<?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); + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/rawpostdata.php
Added
@@ -0,0 +1,22 @@ +<?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'); +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/redirects.php
Added
@@ -0,0 +1,47 @@ +<?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); +} +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/setcookie.php
Added
@@ -0,0 +1,27 @@ +<?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!"; +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/timeout.php
Added
@@ -0,0 +1,23 @@ +<?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); + +?> \ No newline at end of file
View file
HTTP_Request2-2.2.1.tgz/HTTP_Request2-2.2.1/tests/_network/uploads.php
Added
@@ -0,0 +1,36 @@ +<?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"; + } + } +} +?> \ No newline at end of file
View file
HTTP_Request2-2.1.1.tgz/package.xml -> HTTP_Request2-2.2.1.tgz/package.xml
Changed
@@ -18,57 +18,62 @@ <email>avb@php.net</email> <active>yes</active> </lead> - <date>2012-04-08</date> - <time>07:27:30</time> + <date>2014-01-16</date> + <time>18:42:51</time> <version> - <release>2.1.1</release> - <api>2.1.0</api> + <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-license.php">BSD License</license> + <license uri="http://opensource.org/licenses/BSD-3-Clause">BSD 3-Clause License</license> <notes> -Fixes for SOCKS5 proxies support in Socket adapter +* 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 at 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="/"> - <file md5sum="c945a959bd5f4fd7da559ff69e4cab4c" name="HTTP/Request2/Adapter/Curl.php" role="php"> + <file md5sum="a4876c9f72ed0357756f03d564ce5e9c" name="HTTP/Request2/Adapter/Curl.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="20b8160c918d0f310d41d56bf77ad736" name="HTTP/Request2/Adapter/Mock.php" role="php"> + <file md5sum="50cf79a96336eddd14bdb8a0d66b024b" name="HTTP/Request2/Adapter/Mock.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="9dcf3817d365abfd71228a34a422622e" name="HTTP/Request2/Adapter/Socket.php" role="php"> + <file md5sum="25b48415df62f50105cf8293f956fd1b" name="HTTP/Request2/Adapter/Socket.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="0157991488a16ba6759d7ab071c12e0b" name="HTTP/Request2/Observer/Log.php" role="php"> + <file md5sum="86709e7a6185872f153de203f91bff09" name="HTTP/Request2/Observer/Log.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="8cd1e67c2265e698ee3589835dcc3bc6" name="HTTP/Request2/Adapter.php" role="php"> + <file md5sum="9b35c8e2367ff27f70ceb9a63211381c" name="HTTP/Request2/Adapter.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="3c9c24dec19485c5b17b179b9371c7cf" name="HTTP/Request2/CookieJar.php" role="php"> + <file md5sum="feb121033ec9f1d128795fd658ca13a1" name="HTTP/Request2/CookieJar.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> <tasks:replace from="@data_dir@" to="data_dir" type="pear-config" /> </file> - <file md5sum="1cbd54cb951fdcdb17b04b156d5cd821" name="HTTP/Request2/Exception.php" role="php"> + <file md5sum="7eb3da1c08001d8590fc10b35e511578" name="HTTP/Request2/Exception.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="9cd9c1afda061a4362bd5205b65f1893" name="HTTP/Request2/MultipartBody.php" role="php"> + <file md5sum="a223169a1699e2dc7265ac30a2c41bc0" name="HTTP/Request2/MultipartBody.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="46ef0d8881865459df52199711e98ac5" name="HTTP/Request2/SocketWrapper.php" role="php"> + <file md5sum="0a27f3572655068a50bc3d74dd9d925a" name="HTTP/Request2/SocketWrapper.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="6520fb9dc8567415e225ea963c6b9e42" name="HTTP/Request2/SOCKS5.php" role="php"> + <file md5sum="cf32993de6ae6f6f7fc88ff69da09f17" name="HTTP/Request2/SOCKS5.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="b927cbb243338ac1548ed71ccd54cf18" name="HTTP/Request2/Response.php" role="php"> + <file md5sum="1c39892dad9b7781c392780dcce3da76" name="HTTP/Request2/Response.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> - <file md5sum="b04972f9a87b7605034eae5b9d916ca4" name="HTTP/Request2.php" role="php"> + <file md5sum="8384d8d5292e22944905ed618f033c45" name="HTTP/Request2.php" role="php"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <file md5sum="22d7f11b85dd00bd8919a4226a5a0388" name="tests/_files/bug_15305" role="test" /> @@ -80,35 +85,37 @@ <file md5sum="c36530c79c044fde1745b244c38d381f" name="tests/_files/response_gzip" role="test" /> <file md5sum="722328bfe89a9c9f7de5a020ed2c4589" name="tests/_files/response_gzip_broken" role="test" /> <file md5sum="1fb55dfe18831f8fe6280280e72ad216" name="tests/_files/response_headers" role="test" /> - <file md5sum="9a0e02c985032d546318ce45d23c8b13" name="tests/_network/basicauth.php" role="test" /> - <file md5sum="7d7d7cd8485b0ec753fc9267ea849942" name="tests/_network/cookies.php" role="test" /> - <file md5sum="a1f4f779b73402b972009567119b82b5" name="tests/_network/digestauth.php" role="test" /> - <file md5sum="72cd7e3612aff2f6910d29337e3fbaf6" name="tests/_network/getparameters.php" role="test" /> - <file md5sum="884ef81808598dbd1b61bace633159ee" name="tests/_network/postparameters.php" role="test" /> - <file md5sum="4ab49e3e817bc100ab88dc4fde5e4bf0" name="tests/_network/rawpostdata.php" role="test" /> - <file md5sum="dc5bd28dd437bc823bb7a690423aa902" name="tests/_network/redirects.php" role="test" /> - <file md5sum="b72fbeed9dd4f1bfa5eae165953ce13f" name="tests/_network/setcookie.php" role="test" /> - <file md5sum="31f055cf3a58230db2483c24d4d85a16" name="tests/_network/timeout.php" role="test" /> - <file md5sum="e5ca17957148df0aef8a2e85818d8e09" name="tests/_network/uploads.php" role="test" /> - <file md5sum="73d5fe8c2bc54b19171e024c8c753454" name="tests/Request2/Adapter/AllTests.php" role="test" /> - <file md5sum="d2a6fe5c65b7a912c0c99dd7c7238c3b" name="tests/Request2/Adapter/CommonNetworkTest.php" role="test" /> - <file md5sum="31d563b3f266d6c31f417c3d9396c851" name="tests/Request2/Adapter/CurlTest.php" role="test" /> - <file md5sum="6a4145f0466332120fd1e12ca0fe10df" name="tests/Request2/Adapter/MockTest.php" role="test" /> - <file md5sum="ed93ec6686dabe969d2ba78a18a07a86" name="tests/Request2/Adapter/SkippedTests.php" role="test" /> - <file md5sum="f5146962f6eacd9d5bc9e5b8e19d42b0" name="tests/Request2/Adapter/SocketProxyTest.php" role="test" /> - <file md5sum="f3c64aedfae2483309e3cbaf79e9818d" name="tests/Request2/Adapter/SocketTest.php" role="test" /> - <file md5sum="55a3a4b9d76cd8a9960de4f108adbccb" name="tests/Request2/AllTests.php" role="test" /> - <file md5sum="19b6529e1582a3bfd7db5fb92fb4cacd" name="tests/Request2/CookieJarTest.php" role="test" /> - <file md5sum="5d393f4f096e86c65812d3ba83b8ea90" name="tests/Request2/MultipartBodyTest.php" role="test" /> - <file md5sum="bb47d95172897f978a9dff05d3f7ead9" name="tests/Request2/ResponseTest.php" role="test" /> - <file md5sum="0c7edbde7c996475869105ba7420b651" name="tests/AllTests.php" role="test" /> - <file md5sum="6a963b81da716fdfbcbdceca3f6301f5" name="tests/NetworkConfig.php.dist" role="test" /> - <file md5sum="0b4bf3cf231c76620dd0c901e23037ab" name="tests/ObserverTest.php" role="test" /> - <file md5sum="ce32dbbe9388d24887f6551fab4e04b1" name="tests/Request2Test.php" role="test" /> - <file md5sum="3bd1707165a33299b420c54237c02517" name="tests/TestHelper.php" role="test" /> - <file md5sum="7e6017dfdf042dbd443ce6c8c024f40d" name="docs/examples/upload-rapidshare.php" role="doc" /> - <file md5sum="389143b973e6c1d87926d803ca5fceec" name="data/generate-list.php" role="data" /> - <file md5sum="55f4d2d2200f240407db4a48eea6161e" name="data/public-suffix-list.php" role="data" /> + <file md5sum="5d7be2be4ea4f4686e63db3344444521" name="tests/_network/basicauth.php" role="test" /> + <file md5sum="7a09651cc3e345a873e9ff9038d5b93f" name="tests/_network/bug19934.php" role="test" /> + <file md5sum="4c2552990fe0be30e45ff6b2c0867b34" name="tests/_network/cookies.php" role="test" /> + <file md5sum="9fbfe7560f2e51a5e484b5bde507a8b9" name="tests/_network/digestauth.php" role="test" /> + <file md5sum="167a6d3191fc0670b92cbff48014286d" name="tests/_network/getparameters.php" role="test" /> + <file md5sum="313451f492a84414c278041acd8bb5f2" name="tests/_network/postparameters.php" role="test" /> + <file md5sum="1cd1a7554c5a6dc80e36f69fe6a2d934" name="tests/_network/rawpostdata.php" role="test" /> + <file md5sum="9da68a7fb62f5b6d438ee39a769807a7" name="tests/_network/redirects.php" role="test" /> + <file md5sum="ae942b0cff1736c989248688cb3d2e27" name="tests/_network/setcookie.php" role="test" /> + <file md5sum="58bee654f871d1e5d4c8faa8c9694aa2" name="tests/_network/timeout.php" role="test" /> + <file md5sum="57568f73d1635df5306e3b20cd00d634" name="tests/_network/uploads.php" role="test" /> + <file md5sum="348d708001cd8f4033db397aeead3341" name="tests/Request2/Adapter/AllTests.php" role="test" /> + <file md5sum="cb9b7b3bc4a97fecb804f16157fce2d0" name="tests/Request2/Adapter/CommonNetworkTest.php" role="test" /> + <file md5sum="e7c002ca9cd65e1602292fa1fd13a077" name="tests/Request2/Adapter/CurlTest.php" role="test" /> + <file md5sum="f9efb1ffab33433cf36782d145455507" name="tests/Request2/Adapter/MockTest.php" role="test" /> + <file md5sum="387399894c5552aeb0738686d7bde775" name="tests/Request2/Adapter/SkippedTests.php" role="test" /> + <file md5sum="5694db0fe0a09f83d77e80df09307b84" name="tests/Request2/Adapter/SocketProxyTest.php" role="test" /> + <file md5sum="cb6217732b166074a413ed6be89cc721" name="tests/Request2/Adapter/SocketTest.php" role="test" /> + <file md5sum="ad18fb5ebe8b3ad32494601fae96a033" name="tests/Request2/AllTests.php" role="test" /> + <file md5sum="654c071a6495dd15bb5d29eafa0e4b5d" name="tests/Request2/CookieJarTest.php" role="test" /> + <file md5sum="1e5fed8c28c177009baf3c6df39165a2" name="tests/Request2/MultipartBodyTest.php" role="test" /> + <file md5sum="7df6d56a07799cf2982fbfff5752d498" name="tests/Request2/ResponseTest.php" role="test" /> + <file md5sum="8a505a23e6b0805a9cf2fe28b299047e" name="tests/AllTests.php" role="test" /> + <file md5sum="5a303cfa389a834d4d6e5dea3417107c" name="tests/NetworkConfig.php.dist" role="test" /> + <file md5sum="6080b8718c9cf2304eb2482c88868e3a" name="tests/ObserverTest.php" role="test" /> + <file md5sum="97667f124ff1ca6473fcdcd765fa345e" name="tests/Request2Test.php" role="test" /> + <file md5sum="e9f1e8959cfbd21e4343e8a2e5eae32d" name="tests/TestHelper.php" role="test" /> + <file md5sum="03e697c2272d953c30a297d6b49aa2d9" name="docs/LICENSE" role="doc" /> + <file md5sum="4bf3cf43f9053b41181b9008c8f20c5a" name="docs/examples/upload-rapidshare.php" role="doc" /> + <file md5sum="a84e475029d10585b0dc2261e7750d6a" name="data/generate-list.php" role="data" /> + <file md5sum="87b4494932779faf0ee9d76fa14f8a21" name="data/public-suffix-list.php" role="data" /> </dir> </contents> <dependencies> @@ -147,6 +154,7 @@ </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" /> @@ -165,6 +173,7 @@ <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" /> @@ -189,6 +198,50 @@ </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>
View file
xml2changelog
Added
@@ -0,0 +1,43 @@ +<?php +$prog=array_shift($_SERVER['argv']); +if ($_SERVER['argc']<2) die ("usage : " . $prog . " path_to_package.xml [ --debug ]\n"); +$file=array_shift($_SERVER['argv']); + +($xml=simplexml_load_file($file)) || die ($file . " not found !\n"); +if (in_array("--debug", $_SERVER['argv'])) print_r($xml); + +if ($xml['version'] >= "2"){ // Package.xml V 2.0 + $new = ""; + if (strlen(trim($xml->notes))>1) { // Ignore too short descr. + printf("++*** Version %s (%s) - API %s (%s) - %s\n\n%s\n\n", + $xml->version->release, $xml->stability->release, + $xml->version->api, $xml->stability->api, + $xml->date, $xml->notes); + $new=$xml->version->release; + } + + if (isset($xml->changelog->release) && count($xml->changelog->release)) { + $tab = array(); + foreach($xml->changelog->release as $rel) { + $old=$rel->version->release; + if ("$old" != "$new") { + $tab[''.$rel->date] = $rel; + } + } + krsort($tab); + foreach($tab as $rel) { + printf("*** Version %s (%s) - API %s (%s) - %s\n\n%s\n\n", + $rel->version->release, $rel->stability->release, + $rel->version->api, $rel->stability->api, + $rel->date, $rel->notes); + } + } +} else { // Package.xml V 1.0 + printf("* Version %s (%s) - %s\n\n%s\n\n", + $xml->release->version, $xml->release->state, $xml->release->date, $xml->release->notes); + + foreach($xml->changelog->release as $rel) + printf("* Version %s (%s) - %s\n\n%s\n\n", + $rel->version, $rel->state, $rel->date, $rel->notes); +} +?>
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.