mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-30 00:29:58 +09:00
Update composer dependencies
This commit is contained in:
parent
49cc39e507
commit
cbd324c35b
428 changed files with 17862 additions and 5885 deletions
6
vendor/rmccue/requests/.gitignore
vendored
Normal file
6
vendor/rmccue/requests/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Ignore coverage report
|
||||
tests/coverage/*
|
||||
|
||||
# Ignore composer related files
|
||||
/composer.lock
|
||||
/vendor
|
||||
59
vendor/rmccue/requests/.travis.yml
vendored
Executable file → Normal file
59
vendor/rmccue/requests/.travis.yml
vendored
Executable file → Normal file
|
|
@ -1,19 +1,58 @@
|
|||
language: php
|
||||
before_script:
|
||||
- phpenv local 5.4
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.2
|
||||
- php: 5.3
|
||||
- php: 5.4
|
||||
- php: 5.5
|
||||
- php: 5.6
|
||||
env: TEST_COVERAGE=1
|
||||
- php: 7.0
|
||||
- php: hhvm
|
||||
|
||||
# Use new container infrastructure
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/pip
|
||||
- $HOME/.composer/cache
|
||||
- vendor
|
||||
|
||||
install:
|
||||
# Setup the test server
|
||||
- phpenv local 5.5
|
||||
- composer install --dev --no-interaction
|
||||
- TESTPHPBIN=$(phpenv which php)
|
||||
- phpenv local --unset
|
||||
|
||||
# Setup the proxy
|
||||
- pip install --user mitmproxy~=0.15
|
||||
|
||||
before_script:
|
||||
- PHPBIN=$TESTPHPBIN PORT=8080 vendor/bin/start.sh
|
||||
- export REQUESTS_TEST_HOST_HTTP="localhost:8080"
|
||||
|
||||
# Work out of the tests directory
|
||||
- cd tests
|
||||
- PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9002 utils/proxy/start.sh
|
||||
- PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9003 AUTH="test:pass" utils/proxy/start.sh
|
||||
- export REQUESTS_HTTP_PROXY="localhost:9002"
|
||||
- export REQUESTS_HTTP_PROXY_AUTH="localhost:9003"
|
||||
- export REQUESTS_HTTP_PROXY_AUTH_USER="test"
|
||||
- export REQUESTS_HTTP_PROXY_AUTH_PASS="pass"
|
||||
|
||||
# Ensure the HTTPS test instance on Heroku is spun up
|
||||
- curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null
|
||||
|
||||
script:
|
||||
- phpunit --coverage-clover clover.xml
|
||||
|
||||
after_script:
|
||||
- utils/proxy/stop.sh
|
||||
- cd ..
|
||||
- phpenv local 5.4
|
||||
- php vendor/bin/coveralls -v
|
||||
- phpenv local 5.5
|
||||
- PATH=$PATH vendor/bin/stop.sh
|
||||
- test $TEST_COVERAGE && bash <(curl -s https://codecov.io/bash)
|
||||
- phpenv local --unset
|
||||
php:
|
||||
- 5.2
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- hhvm
|
||||
|
|
|
|||
269
vendor/rmccue/requests/CHANGELOG.md
vendored
Executable file → Normal file
269
vendor/rmccue/requests/CHANGELOG.md
vendored
Executable file → Normal file
|
|
@ -1,13 +1,272 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
1.6.1
|
||||
1.7.0
|
||||
-----
|
||||
- [Fix compatibility with HHVM][#121] - Using HHVM with Requests would
|
||||
previously cause either exceptions with SSL or segfaults with the cURL
|
||||
handler. Props Ozh for his work here.
|
||||
|
||||
[#121]: https://github.com/rmccue/Requests/issues/121
|
||||
- Add support for HHVM and PHP 7
|
||||
|
||||
Requests is now tested against both HHVM and PHP 7, and they are supported as
|
||||
first-party platforms.
|
||||
|
||||
(props @rmccue, [#106][gh-106], [#176][gh-176])
|
||||
|
||||
- Transfer & connect timeouts, in seconds & milliseconds
|
||||
|
||||
cURL is unable to handle timeouts under a second in DNS lookups, so we round
|
||||
those up to ensure 1-999ms isn't counted as an instant failure.
|
||||
|
||||
(props @ozh, @rmccue, [#97][gh-97], [#216][gh-216])
|
||||
|
||||
- Rework cookie handling to be more thorough.
|
||||
|
||||
Cookies are now restricted to the same-origin by default, expiration is checked.
|
||||
|
||||
(props @catharsisjelly, @rmccue, [#120][gh-120], [#124][gh-124], [#130][gh-130], [#132][gh-132], [#156][gh-156])
|
||||
|
||||
- Improve testing
|
||||
|
||||
Tests are now run locally to speed them up, as well as further general
|
||||
improvements to the quality of the testing suite. There are now also
|
||||
comprehensive proxy tests to ensure coverage there.
|
||||
|
||||
(props @rmccue, [#75][gh-75], [#107][gh-107], [#170][gh-170], [#177][gh-177], [#181][gh-181], [#183][gh-183], [#185][gh-185], [#196][gh-196], [#202][gh-202], [#203][gh-203])
|
||||
|
||||
- Support custom HTTP methods
|
||||
|
||||
Previously, custom HTTP methods were only supported on sockets; they are now
|
||||
supported across all transports.
|
||||
|
||||
(props @ocean90, [#227][gh-227])
|
||||
|
||||
- Add byte limit option
|
||||
|
||||
(props @rmccue, [#172][gh-172])
|
||||
|
||||
- Support a Requests_Proxy_HTTP() instance for the proxy setting.
|
||||
|
||||
(props @ocean90, [#223][gh-223])
|
||||
|
||||
- Add progress hook
|
||||
|
||||
(props @rmccue, [#180][gh-180])
|
||||
|
||||
- Add a before_redirect hook to alter redirects
|
||||
|
||||
(props @rmccue, [#205][gh-205])
|
||||
|
||||
- Pass cURL info to after_request
|
||||
|
||||
(props @rmccue, [#206][gh-206])
|
||||
|
||||
- Remove explicit autoload in Composer installation instructions
|
||||
|
||||
(props @SlikNL, [#86][gh-86])
|
||||
|
||||
- Restrict CURLOPT_PROTOCOLS on `defined()` instead of `version_compare()`
|
||||
|
||||
(props @ozh, [#92][gh-92])
|
||||
|
||||
- Fix doc - typo in "Authentication"
|
||||
|
||||
(props @remik, [#99][gh-99])
|
||||
|
||||
- Contextually check for a valid transport
|
||||
|
||||
(props @ozh, [#101][gh-101])
|
||||
|
||||
- Follow relative redirects correctly
|
||||
|
||||
(props @ozh, [#103][gh-103])
|
||||
|
||||
- Use cURL's version_number
|
||||
|
||||
(props @mishan, [#104][gh-104])
|
||||
|
||||
- Removed duplicated option docs
|
||||
|
||||
(props @staabm, [#112][gh-112])
|
||||
|
||||
- code styling fixed
|
||||
|
||||
(props @imsaintx, [#113][gh-113])
|
||||
|
||||
- Fix IRI "normalization"
|
||||
|
||||
(props @ozh, [#128][gh-128])
|
||||
|
||||
- Mention two PHP extension dependencies in the README.
|
||||
|
||||
(props @orlitzky, [#136][gh-136])
|
||||
|
||||
- Ignore coverage report files
|
||||
|
||||
(props @ozh, [#148][gh-148])
|
||||
|
||||
- drop obsolete "return" after throw
|
||||
|
||||
(props @staabm, [#150][gh-150])
|
||||
|
||||
- Updated exception message to specify both http + https
|
||||
|
||||
(props @beutnagel, [#162][gh-162])
|
||||
|
||||
- Sets `stream_headers` method to public to allow calling it from other
|
||||
places.
|
||||
|
||||
(props @adri, [#158][gh-158])
|
||||
|
||||
- Remove duplicated stream_get_meta_data call
|
||||
|
||||
(props @rmccue, [#179][gh-179])
|
||||
|
||||
- Transmits $errno from stream_socket_client in exception
|
||||
|
||||
(props @laurentmartelli, [#174][gh-174])
|
||||
|
||||
- Correct methods to use snake_case
|
||||
|
||||
(props @rmccue, [#184][gh-184])
|
||||
|
||||
- Improve code quality
|
||||
|
||||
(props @rmccue, [#186][gh-186])
|
||||
|
||||
- Update Build Status image
|
||||
|
||||
(props @rmccue, [#187][gh-187])
|
||||
|
||||
- Fix/Rationalize transports (v2)
|
||||
|
||||
(props @rmccue, [#188][gh-188])
|
||||
|
||||
- Surface cURL errors
|
||||
|
||||
(props @ifwe, [#194][gh-194])
|
||||
|
||||
- Fix for memleak and curl_close() never being called
|
||||
|
||||
(props @kwuerl, [#200][gh-200])
|
||||
|
||||
- addex how to install with composer
|
||||
|
||||
(props @royopa, [#164][gh-164])
|
||||
|
||||
- Uppercase the method to ensure compatibility
|
||||
|
||||
(props @rmccue, [#207][gh-207])
|
||||
|
||||
- Store default certificate path
|
||||
|
||||
(props @rmccue, [#210][gh-210])
|
||||
|
||||
- Force closing keep-alive connections on old cURL
|
||||
|
||||
(props @rmccue, [#211][gh-211])
|
||||
|
||||
- Docs: Updated HTTP links with HTTPS links where applicable
|
||||
|
||||
(props @ntwb, [#215][gh-215])
|
||||
|
||||
- Remove the executable bit
|
||||
|
||||
(props @ocean90, [#224][gh-224])
|
||||
|
||||
- Change more links to HTTPS
|
||||
|
||||
(props @rmccue, [#217][gh-217])
|
||||
|
||||
- Bail from cURL when either `curl_init()` OR `curl_exec()` are unavailable
|
||||
|
||||
(props @dd32, [#230][gh-230])
|
||||
|
||||
- Disable OpenSSL's internal peer_name checking when `verifyname` is disabled.
|
||||
|
||||
(props @dd32, [#239][gh-239])
|
||||
|
||||
- Only include the port number in the `Host` header when it differs from
|
||||
default
|
||||
|
||||
(props @dd32, [#238][gh-238])
|
||||
|
||||
- Respect port if specified for HTTPS connections
|
||||
|
||||
(props @dd32, [#237][gh-237])
|
||||
|
||||
- Allow paths starting with a double-slash
|
||||
|
||||
(props @rmccue, [#240][gh-240])
|
||||
|
||||
- Fixes bug in rfc2616 #3.6.1 implementation.
|
||||
|
||||
(props @stephenharris, [#236][gh-236], [#3][gh-3])
|
||||
|
||||
- CURLOPT_HTTPHEADER在php7接受空数组导致php-fpm奔溃
|
||||
|
||||
(props @qibinghua, [#219][gh-219])
|
||||
|
||||
[gh-3]: https://github.com/rmccue/Requests/issues/3
|
||||
[gh-75]: https://github.com/rmccue/Requests/issues/75
|
||||
[gh-86]: https://github.com/rmccue/Requests/issues/86
|
||||
[gh-92]: https://github.com/rmccue/Requests/issues/92
|
||||
[gh-97]: https://github.com/rmccue/Requests/issues/97
|
||||
[gh-99]: https://github.com/rmccue/Requests/issues/99
|
||||
[gh-101]: https://github.com/rmccue/Requests/issues/101
|
||||
[gh-103]: https://github.com/rmccue/Requests/issues/103
|
||||
[gh-104]: https://github.com/rmccue/Requests/issues/104
|
||||
[gh-106]: https://github.com/rmccue/Requests/issues/106
|
||||
[gh-107]: https://github.com/rmccue/Requests/issues/107
|
||||
[gh-112]: https://github.com/rmccue/Requests/issues/112
|
||||
[gh-113]: https://github.com/rmccue/Requests/issues/113
|
||||
[gh-120]: https://github.com/rmccue/Requests/issues/120
|
||||
[gh-124]: https://github.com/rmccue/Requests/issues/124
|
||||
[gh-128]: https://github.com/rmccue/Requests/issues/128
|
||||
[gh-130]: https://github.com/rmccue/Requests/issues/130
|
||||
[gh-132]: https://github.com/rmccue/Requests/issues/132
|
||||
[gh-136]: https://github.com/rmccue/Requests/issues/136
|
||||
[gh-148]: https://github.com/rmccue/Requests/issues/148
|
||||
[gh-150]: https://github.com/rmccue/Requests/issues/150
|
||||
[gh-156]: https://github.com/rmccue/Requests/issues/156
|
||||
[gh-158]: https://github.com/rmccue/Requests/issues/158
|
||||
[gh-162]: https://github.com/rmccue/Requests/issues/162
|
||||
[gh-164]: https://github.com/rmccue/Requests/issues/164
|
||||
[gh-170]: https://github.com/rmccue/Requests/issues/170
|
||||
[gh-172]: https://github.com/rmccue/Requests/issues/172
|
||||
[gh-174]: https://github.com/rmccue/Requests/issues/174
|
||||
[gh-176]: https://github.com/rmccue/Requests/issues/176
|
||||
[gh-177]: https://github.com/rmccue/Requests/issues/177
|
||||
[gh-179]: https://github.com/rmccue/Requests/issues/179
|
||||
[gh-180]: https://github.com/rmccue/Requests/issues/180
|
||||
[gh-181]: https://github.com/rmccue/Requests/issues/181
|
||||
[gh-183]: https://github.com/rmccue/Requests/issues/183
|
||||
[gh-184]: https://github.com/rmccue/Requests/issues/184
|
||||
[gh-185]: https://github.com/rmccue/Requests/issues/185
|
||||
[gh-186]: https://github.com/rmccue/Requests/issues/186
|
||||
[gh-187]: https://github.com/rmccue/Requests/issues/187
|
||||
[gh-188]: https://github.com/rmccue/Requests/issues/188
|
||||
[gh-194]: https://github.com/rmccue/Requests/issues/194
|
||||
[gh-196]: https://github.com/rmccue/Requests/issues/196
|
||||
[gh-200]: https://github.com/rmccue/Requests/issues/200
|
||||
[gh-202]: https://github.com/rmccue/Requests/issues/202
|
||||
[gh-203]: https://github.com/rmccue/Requests/issues/203
|
||||
[gh-205]: https://github.com/rmccue/Requests/issues/205
|
||||
[gh-206]: https://github.com/rmccue/Requests/issues/206
|
||||
[gh-207]: https://github.com/rmccue/Requests/issues/207
|
||||
[gh-210]: https://github.com/rmccue/Requests/issues/210
|
||||
[gh-211]: https://github.com/rmccue/Requests/issues/211
|
||||
[gh-215]: https://github.com/rmccue/Requests/issues/215
|
||||
[gh-216]: https://github.com/rmccue/Requests/issues/216
|
||||
[gh-217]: https://github.com/rmccue/Requests/issues/217
|
||||
[gh-219]: https://github.com/rmccue/Requests/issues/219
|
||||
[gh-223]: https://github.com/rmccue/Requests/issues/223
|
||||
[gh-224]: https://github.com/rmccue/Requests/issues/224
|
||||
[gh-227]: https://github.com/rmccue/Requests/issues/227
|
||||
[gh-230]: https://github.com/rmccue/Requests/issues/230
|
||||
[gh-236]: https://github.com/rmccue/Requests/issues/236
|
||||
[gh-237]: https://github.com/rmccue/Requests/issues/237
|
||||
[gh-238]: https://github.com/rmccue/Requests/issues/238
|
||||
[gh-239]: https://github.com/rmccue/Requests/issues/239
|
||||
[gh-240]: https://github.com/rmccue/Requests/issues/240
|
||||
|
||||
1.6.0
|
||||
-----
|
||||
|
|
|
|||
0
vendor/rmccue/requests/LICENSE
vendored
Executable file → Normal file
0
vendor/rmccue/requests/LICENSE
vendored
Executable file → Normal file
22
vendor/rmccue/requests/README.md
vendored
Executable file → Normal file
22
vendor/rmccue/requests/README.md
vendored
Executable file → Normal file
|
|
@ -1,6 +1,9 @@
|
|||
Requests for PHP
|
||||
================
|
||||
|
||||
[](https://travis-ci.org/rmccue/Requests)
|
||||
[](http://codecov.io/github/rmccue/Requests?branch=master)
|
||||
|
||||
Requests is a HTTP library written in PHP, for human beings. It is roughly
|
||||
based on the API from the excellent [Requests Python
|
||||
library](http://python-requests.org/). Requests is [ISC
|
||||
|
|
@ -55,12 +58,15 @@ Installation
|
|||
If you're using [Composer](https://github.com/composer/composer) to manage
|
||||
dependencies, you can add Requests with it.
|
||||
|
||||
```sh
|
||||
composer require rmccue/requests
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
{
|
||||
"require": {
|
||||
"rmccue/requests": ">=1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {"Requests": "library/"}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,15 +123,15 @@ issue](https://github.com/rmccue/Requests/issues/new)!
|
|||
|
||||
Testing
|
||||
-------
|
||||
[](http://travis-ci.org/rmccue/Requests)
|
||||
[][coveralls]
|
||||
|
||||
Requests strives to have 100% code-coverage of the library with an extensive
|
||||
set of tests. We're not quite there yet, but [we're getting close][coveralls].
|
||||
set of tests. We're not quite there yet, but [we're getting close][codecov].
|
||||
|
||||
[coveralls]: https://coveralls.io/r/rmccue/Requests?branch=master
|
||||
[codecov]: http://codecov.io/github/rmccue/Requests
|
||||
|
||||
To run the test suite, simply:
|
||||
To run the test suite, first check that you have the [PHP
|
||||
JSON extension ](http://php.net/manual/en/book.json.php) enabled. Then
|
||||
simply:
|
||||
|
||||
$ cd tests
|
||||
$ phpunit
|
||||
|
|
|
|||
2
vendor/rmccue/requests/composer.json
vendored
2
vendor/rmccue/requests/composer.json
vendored
|
|
@ -14,7 +14,7 @@
|
|||
"php": ">=5.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
"requests/test-server": "dev-master"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
|
|
|||
0
vendor/rmccue/requests/docs/README.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/README.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/authentication-custom.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/authentication-custom.md
vendored
Executable file → Normal file
4
vendor/rmccue/requests/docs/authentication.md
vendored
Executable file → Normal file
4
vendor/rmccue/requests/docs/authentication.md
vendored
Executable file → Normal file
|
|
@ -27,5 +27,5 @@ Note that POST/PUT can also take a data parameter, so you also need that
|
|||
before `$options`:
|
||||
|
||||
```php
|
||||
Requests::get('http://httpbin.org/basic-auth/user/password', array(), null, $options);
|
||||
```
|
||||
Requests::post('http://httpbin.org/basic-auth/user/password', array(), null, $options);
|
||||
```
|
||||
|
|
|
|||
0
vendor/rmccue/requests/docs/goals.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/goals.md
vendored
Executable file → Normal file
10
vendor/rmccue/requests/docs/hooks.md
vendored
Executable file → Normal file
10
vendor/rmccue/requests/docs/hooks.md
vendored
Executable file → Normal file
|
|
@ -45,7 +45,9 @@ Available Hooks
|
|||
|
||||
Alter the raw HTTP response before returning for parsing
|
||||
|
||||
Parameters: `string &$response`
|
||||
Parameters: `string &$response, array &$info`
|
||||
|
||||
`$info` contains the associated array as defined in [curl-getinfo-returnvalues](http://php.net/manual/en/function.curl-getinfo.php#refsect1-function.curl-getinfo-returnvalues)
|
||||
|
||||
* `fsockopen.before_request`
|
||||
|
||||
|
|
@ -71,7 +73,9 @@ Available Hooks
|
|||
|
||||
Alter the raw HTTP response before returning for parsing
|
||||
|
||||
Parameters: `string &$response`
|
||||
Parameters: `string &$response, array &$info`
|
||||
|
||||
`$info` contains the associated array as defined in [stream-get-meta-data-returnvalues](http://php.net/manual/en/function.stream-get-meta-data.php#refsect1-function.stream-get-meta-data-returnvalues)
|
||||
|
||||
|
||||
Registering Hooks
|
||||
|
|
@ -89,4 +93,4 @@ $hooks = new Requests_Hooks();
|
|||
$hooks->register('requests.after_request', 'mycallback');
|
||||
|
||||
$request = Requests::get('http://httpbin.org/get', array(), array('hooks' => $hooks));
|
||||
```
|
||||
```
|
||||
|
|
|
|||
0
vendor/rmccue/requests/docs/usage-advanced.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/usage-advanced.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/usage.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/usage.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/why-requests.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/docs/why-requests.md
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/basic-auth.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/basic-auth.php
vendored
Executable file → Normal file
16
vendor/rmccue/requests/examples/cookie.php
vendored
Normal file
16
vendor/rmccue/requests/examples/cookie.php
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
// First, include Requests
|
||||
include('../library/Requests.php');
|
||||
|
||||
// Next, make sure Requests can load internal classes
|
||||
Requests::register_autoloader();
|
||||
|
||||
// Say you need to fake a login cookie
|
||||
$c = new Requests_Cookie('login_uid', 'something');
|
||||
|
||||
// Now let's make a request!
|
||||
$request = Requests::get('http://httpbin.org/cookies', array('Cookie' => $c->formatForHeader()));
|
||||
|
||||
// Check what we received
|
||||
var_dump($request);
|
||||
20
vendor/rmccue/requests/examples/cookie_jar.php
vendored
Normal file
20
vendor/rmccue/requests/examples/cookie_jar.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
// First, include Requests
|
||||
include('../library/Requests.php');
|
||||
|
||||
// Next, make sure Requests can load internal classes
|
||||
Requests::register_autoloader();
|
||||
|
||||
// Say you need to fake a login cookie
|
||||
$c = new Requests_Cookie_Jar(['login_uid' => 'something']);
|
||||
|
||||
// Now let's make a request!
|
||||
$request = Requests::get(
|
||||
'http://httpbin.org/cookies', // Url
|
||||
[], // No need to set the headers the Jar does this for us
|
||||
['cookies' => $c] // Pass in the Jar as an option
|
||||
);
|
||||
|
||||
// Check what we received
|
||||
var_dump($request);
|
||||
0
vendor/rmccue/requests/examples/get.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/get.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/multiple.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/multiple.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/post.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/post.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/session.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/examples/session.php
vendored
Executable file → Normal file
17
vendor/rmccue/requests/examples/timeout.php
vendored
Normal file
17
vendor/rmccue/requests/examples/timeout.php
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
// First, include Requests
|
||||
include('../library/Requests.php');
|
||||
|
||||
// Next, make sure Requests can load internal classes
|
||||
Requests::register_autoloader();
|
||||
|
||||
// Define a timeout of 2.5 seconds
|
||||
$options = array(
|
||||
'timeout' => 2.5,
|
||||
);
|
||||
|
||||
// Now let's make a request to a page that will delay its response by 3 seconds
|
||||
$request = Requests::get('http://httpbin.org/delay/3', array(), $options);
|
||||
|
||||
// An exception will be thrown, stating a timeout of the request !
|
||||
255
vendor/rmccue/requests/library/Requests.php
vendored
Executable file → Normal file
255
vendor/rmccue/requests/library/Requests.php
vendored
Executable file → Normal file
|
|
@ -54,20 +54,41 @@ class Requests {
|
|||
*/
|
||||
const DELETE = 'DELETE';
|
||||
|
||||
/**
|
||||
* OPTIONS method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OPTIONS = 'OPTIONS';
|
||||
|
||||
/**
|
||||
* TRACE method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TRACE = 'TRACE';
|
||||
|
||||
/**
|
||||
* PATCH method
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5789
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
* @var string
|
||||
*/
|
||||
const PATCH = 'PATCH';
|
||||
|
||||
/**
|
||||
* Default size of buffer size to read streams
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const BUFFER_SIZE = 1160;
|
||||
|
||||
/**
|
||||
* Current version of Requests
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '1.6.1';
|
||||
const VERSION = '1.7';
|
||||
|
||||
/**
|
||||
* Registered transport classes
|
||||
|
|
@ -81,9 +102,19 @@ class Requests {
|
|||
*
|
||||
* Use {@see get_transport()} instead
|
||||
*
|
||||
* @var string|null
|
||||
* @var array
|
||||
*/
|
||||
public static $transport = null;
|
||||
public static $transport = array();
|
||||
|
||||
/**
|
||||
* Default certificate path.
|
||||
*
|
||||
* @see Requests::get_certificate_path()
|
||||
* @see Requests::set_certificate_path()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $certificate_path;
|
||||
|
||||
/**
|
||||
* This is a static class, do not instantiate it
|
||||
|
|
@ -147,11 +178,16 @@ class Requests {
|
|||
* @throws Requests_Exception If no valid transport is found (`notransport`)
|
||||
* @return Requests_Transport
|
||||
*/
|
||||
protected static function get_transport() {
|
||||
protected static function get_transport($capabilities = array()) {
|
||||
// Caching code, don't bother testing coverage
|
||||
// @codeCoverageIgnoreStart
|
||||
if (self::$transport !== null) {
|
||||
return new self::$transport();
|
||||
// array of capabilities as a string to be used as an array key
|
||||
ksort($capabilities);
|
||||
$cap_string = serialize($capabilities);
|
||||
|
||||
// Don't search for a transport if it's already been done for these $capabilities
|
||||
if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
|
||||
return new self::$transport[$cap_string]();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
|
|
@ -164,20 +200,21 @@ class Requests {
|
|||
|
||||
// Find us a working transport
|
||||
foreach (self::$transports as $class) {
|
||||
if (!class_exists($class))
|
||||
if (!class_exists($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = call_user_func(array($class, 'test'));
|
||||
$result = call_user_func(array($class, 'test'), $capabilities);
|
||||
if ($result) {
|
||||
self::$transport = $class;
|
||||
self::$transport[$cap_string] = $class;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (self::$transport === null) {
|
||||
if (self::$transport[$cap_string] === null) {
|
||||
throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
|
||||
}
|
||||
|
||||
return new self::$transport();
|
||||
return new self::$transport[$cap_string]();
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
|
@ -207,6 +244,13 @@ class Requests {
|
|||
public static function delete($url, $headers = array(), $options = array()) {
|
||||
return self::request($url, $headers, null, self::DELETE, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a TRACE request
|
||||
*/
|
||||
public static function trace($url, $headers = array(), $options = array()) {
|
||||
return self::request($url, $headers, null, self::TRACE, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
|
|
@ -230,13 +274,20 @@ class Requests {
|
|||
return self::request($url, $headers, $data, self::PUT, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an OPTIONS request
|
||||
*/
|
||||
public static function options($url, $headers = array(), $data = array(), $options = array()) {
|
||||
return self::request($url, $headers, $data, self::OPTIONS, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PATCH request
|
||||
*
|
||||
* Note: Unlike {@see post} and {@see put}, `$headers` is required, as the
|
||||
* specification recommends that should send an ETag
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5789
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
*/
|
||||
public static function patch($url, $headers, $data = array(), $options = array()) {
|
||||
return self::request($url, $headers, $data, self::PATCH, $options);
|
||||
|
|
@ -253,7 +304,11 @@ class Requests {
|
|||
* options:
|
||||
*
|
||||
* - `timeout`: How long should we wait for a response?
|
||||
* (integer, seconds, default: 10)
|
||||
* Note: for cURL, a minimum of 1 second applies, as DNS resolution
|
||||
* operates at second-resolution only.
|
||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||
* - `connect_timeout`: How long should we wait while trying to connect?
|
||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||
* - `useragent`: Useragent to send to the server
|
||||
* (string, default: php-requests/$version)
|
||||
* - `follow_redirects`: Should we follow 3xx redirects?
|
||||
|
|
@ -268,7 +323,9 @@ class Requests {
|
|||
* for Basic authentication
|
||||
* (Requests_Auth|array|boolean, default: false)
|
||||
* - `proxy`: Proxy details to use for proxy by-passing and authentication
|
||||
* (Requests_Proxy|array|boolean, default: false)
|
||||
* (Requests_Proxy|array|string|boolean, default: false)
|
||||
* - `max_bytes`: Limit for the response body size.
|
||||
* (integer|boolean, default: false)
|
||||
* - `idn`: Enable IDN parsing
|
||||
* (boolean, default: true)
|
||||
* - `transport`: Custom transport. Either a class name, or a
|
||||
|
|
@ -284,12 +341,15 @@ class Requests {
|
|||
* (string|boolean, default: library/Requests/Transport/cacert.pem)
|
||||
* - `verifyname`: Should we verify the common name in the SSL certificate?
|
||||
* (boolean: default, true)
|
||||
* - `data_format`: How should we send the `$data` parameter?
|
||||
* (string, one of 'query' or 'body', default: 'query' for
|
||||
* HEAD/GET/DELETE, 'body' for POST/PUT/OPTIONS/PATCH)
|
||||
*
|
||||
* @throws Requests_Exception On invalid URLs (`nonhttp`)
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type (use Requests constants)
|
||||
* @param array $options Options for the request (see description for more information)
|
||||
* @return Requests_Response
|
||||
|
|
@ -312,7 +372,9 @@ class Requests {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$transport = self::get_transport();
|
||||
$need_ssl = (0 === stripos($url, 'https://'));
|
||||
$capabilities = array('ssl' => $need_ssl);
|
||||
$transport = self::get_transport($capabilities);
|
||||
}
|
||||
$response = $transport->request($url, $headers, $data, $options);
|
||||
|
||||
|
|
@ -343,9 +405,6 @@ class Requests {
|
|||
* - `type`: HTTP request type (use Requests constants). Same as the `$type`
|
||||
* parameter to {@see Requests::request}
|
||||
* (string, default: `Requests::GET`)
|
||||
* - `data`: Associative array of options. Same as the `$options` parameter
|
||||
* to {@see Requests::request}
|
||||
* (array, default: see {@see Requests::request})
|
||||
* - `cookies`: Associative array of cookie name to value, or cookie jar.
|
||||
* (array|Requests_Cookie_Jar)
|
||||
*
|
||||
|
|
@ -443,7 +502,9 @@ class Requests {
|
|||
protected static function get_default_options($multirequest = false) {
|
||||
$defaults = array(
|
||||
'timeout' => 10,
|
||||
'connect_timeout' => 10,
|
||||
'useragent' => 'php-requests/' . self::VERSION,
|
||||
'protocol_version' => 1.1,
|
||||
'redirected' => 0,
|
||||
'redirects' => 10,
|
||||
'follow_redirects' => true,
|
||||
|
|
@ -453,10 +514,11 @@ class Requests {
|
|||
'auth' => false,
|
||||
'proxy' => false,
|
||||
'cookies' => false,
|
||||
'max_bytes' => false,
|
||||
'idn' => true,
|
||||
'hooks' => null,
|
||||
'transport' => null,
|
||||
'verify' => dirname( __FILE__ ) . '/Requests/Transport/cacert.pem',
|
||||
'verify' => Requests::get_certificate_path(),
|
||||
'verifyname' => true,
|
||||
);
|
||||
if ($multirequest !== false) {
|
||||
|
|
@ -465,19 +527,41 @@ class Requests {
|
|||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default certificate path.
|
||||
*
|
||||
* @return string Default certificate path.
|
||||
*/
|
||||
public static function get_certificate_path() {
|
||||
if ( ! empty( Requests::$certificate_path ) ) {
|
||||
return Requests::$certificate_path;
|
||||
}
|
||||
|
||||
return dirname(__FILE__) . '/Requests/Transport/cacert.pem';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default certificate path.
|
||||
*
|
||||
* @param string $path Certificate path, pointing to a PEM file.
|
||||
*/
|
||||
public static function set_certificate_path( $path ) {
|
||||
Requests::$certificate_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default values
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type
|
||||
* @param array $options Options for the request
|
||||
* @return array $options
|
||||
*/
|
||||
protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
|
||||
if (!preg_match('/^http(s)?:\/\//i', $url)) {
|
||||
throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
|
||||
if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
|
||||
throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
|
||||
}
|
||||
|
||||
if (empty($options['hooks'])) {
|
||||
|
|
@ -491,7 +575,7 @@ class Requests {
|
|||
$options['auth']->register($options['hooks']);
|
||||
}
|
||||
|
||||
if (!empty($options['proxy'])) {
|
||||
if (is_string($options['proxy']) || is_array($options['proxy'])) {
|
||||
$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
|
||||
}
|
||||
if ($options['proxy'] !== false) {
|
||||
|
|
@ -513,6 +597,18 @@ class Requests {
|
|||
$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
|
||||
$url = $iri->uri;
|
||||
}
|
||||
|
||||
// Massage the type to ensure we support it.
|
||||
$type = strtoupper($type);
|
||||
|
||||
if (!isset($options['data_format'])) {
|
||||
if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) {
|
||||
$options['data_format'] = 'query';
|
||||
}
|
||||
else {
|
||||
$options['data_format'] = 'body';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -555,11 +651,12 @@ class Requests {
|
|||
// Unfold headers (replace [CRLF] 1*( SP | HT ) with SP) as per RFC 2616 (section 2.2)
|
||||
$headers = preg_replace('/\n[ \t]/', ' ', $headers);
|
||||
$headers = explode("\n", $headers);
|
||||
preg_match('#^HTTP/1\.\d[ \t]+(\d+)#i', array_shift($headers), $matches);
|
||||
preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches);
|
||||
if (empty($matches)) {
|
||||
throw new Requests_Exception('Response could not be parsed', 'noversion', $headers);
|
||||
}
|
||||
$return->status_code = (int) $matches[1];
|
||||
$return->protocol_version = (float) $matches[1];
|
||||
$return->status_code = (int) $matches[2];
|
||||
if ($return->status_code >= 200 && $return->status_code < 300) {
|
||||
$return->success = true;
|
||||
}
|
||||
|
|
@ -585,19 +682,28 @@ class Requests {
|
|||
|
||||
$options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options));
|
||||
|
||||
if ((in_array($return->status_code, array(300, 301, 302, 303, 307)) || $return->status_code > 307 && $return->status_code < 400) && $options['follow_redirects'] === true) {
|
||||
if ($return->is_redirect() && $options['follow_redirects'] === true) {
|
||||
if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
|
||||
if ($return->status_code === 303) {
|
||||
$options['type'] = Requests::GET;
|
||||
$options['type'] = self::GET;
|
||||
}
|
||||
$options['redirected']++;
|
||||
$location = $return->headers['location'];
|
||||
if (strpos ($location, '/') === 0) {
|
||||
if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
|
||||
// relative redirect, for compatibility make it absolute
|
||||
$location = Requests_IRI::absolutize($url, $location);
|
||||
$location = $location->uri;
|
||||
}
|
||||
$redirected = self::request($location, $req_headers, $req_data, false, $options);
|
||||
|
||||
$hook_args = array(
|
||||
&$location,
|
||||
&$req_headers,
|
||||
&$req_data,
|
||||
&$options,
|
||||
$return
|
||||
);
|
||||
$options['hooks']->dispatch('requests.before_redirect', $hook_args);
|
||||
$redirected = self::request($location, $req_headers, $req_data, $options['type'], $options);
|
||||
$redirected->history[] = $return;
|
||||
return $redirected;
|
||||
}
|
||||
|
|
@ -618,13 +724,17 @@ class Requests {
|
|||
* Internal use only. Converts a raw HTTP response to a Requests_Response
|
||||
* while still executing a multiple request.
|
||||
*
|
||||
* @param string $headers Full response text including headers and body
|
||||
* @param string $response Full response text including headers and body (will be overwritten with Response instance)
|
||||
* @param array $request Request data as passed into {@see Requests::request_multiple()}
|
||||
* @return null `$response` is either set to a Requests_Response instance, or a Requests_Exception object
|
||||
*/
|
||||
public static function parse_multiple(&$response, $request) {
|
||||
try {
|
||||
$response = self::parse_response($response, $request['url'], $request['headers'], $request['data'], $request['options']);
|
||||
$url = $request['url'];
|
||||
$headers = $request['headers'];
|
||||
$data = $request['data'];
|
||||
$options = $request['options'];
|
||||
$response = self::parse_response($response, $url, $headers, $data, $options);
|
||||
}
|
||||
catch (Requests_Exception $e) {
|
||||
$response = $e;
|
||||
|
|
@ -634,20 +744,22 @@ class Requests {
|
|||
/**
|
||||
* Decoded a chunked body as per RFC 2616
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2616#section-3.6.1
|
||||
* @see https://tools.ietf.org/html/rfc2616#section-3.6.1
|
||||
* @param string $data Chunked body
|
||||
* @return string Decoded body
|
||||
*/
|
||||
protected static function decode_chunked($data) {
|
||||
if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($data))) {
|
||||
if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$decoded = '';
|
||||
$encoded = $data;
|
||||
|
||||
while (true) {
|
||||
$is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
|
||||
$is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
|
||||
if (!$is_chunked) {
|
||||
// Looks like it's not chunked after all
|
||||
return $data;
|
||||
|
|
@ -660,7 +772,7 @@ class Requests {
|
|||
}
|
||||
|
||||
$chunk_length = strlen($matches[0]);
|
||||
$decoded .= $part = substr($encoded, $chunk_length, $length);
|
||||
$decoded .= substr($encoded, $chunk_length, $length);
|
||||
$encoded = substr($encoded, $chunk_length + $length + 2);
|
||||
|
||||
if (trim($encoded) === '0' || empty($encoded)) {
|
||||
|
|
@ -682,7 +794,7 @@ class Requests {
|
|||
public static function flatten($array) {
|
||||
$return = array();
|
||||
foreach ($array as $key => $value) {
|
||||
$return[] = "$key: $value";
|
||||
$return[] = sprintf('%s: %s', $key, $value);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
|
@ -690,6 +802,7 @@ class Requests {
|
|||
/**
|
||||
* Convert a key => value array to a 'key: value' array for headers
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Misspelling of {@see Requests::flatten}
|
||||
* @param array $array Dictionary of header values
|
||||
* @return array List of headers
|
||||
|
|
@ -704,7 +817,6 @@ class Requests {
|
|||
* Implements gzip, compress and deflate. Guesses which it is by attempting
|
||||
* to decode.
|
||||
*
|
||||
* @todo Make this smarter by defaulting to whatever the headers say first
|
||||
* @param string $data Compressed data in one of the above formats
|
||||
* @return string Decompressed string
|
||||
*/
|
||||
|
|
@ -740,12 +852,12 @@ class Requests {
|
|||
* Warning: Magic numbers within. Due to the potential different formats that the compressed
|
||||
* data may be returned in, some "magic offsets" are needed to ensure proper decompression
|
||||
* takes place. For a simple progmatic way to determine the magic offset in use, see:
|
||||
* http://core.trac.wordpress.org/ticket/18273
|
||||
* https://core.trac.wordpress.org/ticket/18273
|
||||
*
|
||||
* @since 2.8.1
|
||||
* @link http://core.trac.wordpress.org/ticket/18273
|
||||
* @link http://au2.php.net/manual/en/function.gzinflate.php#70875
|
||||
* @link http://au2.php.net/manual/en/function.gzinflate.php#77336
|
||||
* @link https://core.trac.wordpress.org/ticket/18273
|
||||
* @link https://secure.php.net/manual/en/function.gzinflate.php#70875
|
||||
* @link https://secure.php.net/manual/en/function.gzinflate.php#77336
|
||||
*
|
||||
* @param string $gzData String to decompress.
|
||||
* @return string|bool False on failure.
|
||||
|
|
@ -753,23 +865,26 @@ class Requests {
|
|||
public static function compatible_gzinflate($gzData) {
|
||||
// Compressed data might contain a full zlib header, if so strip it for
|
||||
// gzinflate()
|
||||
if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
|
||||
if (substr($gzData, 0, 3) == "\x1f\x8b\x08") {
|
||||
$i = 10;
|
||||
$flg = ord( substr($gzData, 3, 1) );
|
||||
if ( $flg > 0 ) {
|
||||
if ( $flg & 4 ) {
|
||||
list($xlen) = unpack('v', substr($gzData, $i, 2) );
|
||||
$flg = ord(substr($gzData, 3, 1));
|
||||
if ($flg > 0) {
|
||||
if ($flg & 4) {
|
||||
list($xlen) = unpack('v', substr($gzData, $i, 2));
|
||||
$i = $i + 2 + $xlen;
|
||||
}
|
||||
if ( $flg & 8 )
|
||||
if ($flg & 8) {
|
||||
$i = strpos($gzData, "\0", $i) + 1;
|
||||
if ( $flg & 16 )
|
||||
}
|
||||
if ($flg & 16) {
|
||||
$i = strpos($gzData, "\0", $i) + 1;
|
||||
if ( $flg & 2 )
|
||||
}
|
||||
if ($flg & 2) {
|
||||
$i = $i + 2;
|
||||
}
|
||||
}
|
||||
$decompressed = self::compatible_gzinflate( substr( $gzData, $i ) );
|
||||
if ( false !== $decompressed ) {
|
||||
$decompressed = self::compatible_gzinflate(substr($gzData, $i));
|
||||
if (false !== $decompressed) {
|
||||
return $decompressed;
|
||||
}
|
||||
}
|
||||
|
|
@ -780,60 +895,62 @@ class Requests {
|
|||
// java.util.zip.Deflater, Ruby’s Zlib::Deflate, and .NET's
|
||||
// System.IO.Compression.DeflateStream.
|
||||
//
|
||||
// See http://decompres.blogspot.com/ for a quick explanation of this
|
||||
// See https://decompres.blogspot.com/ for a quick explanation of this
|
||||
// data type
|
||||
$huffman_encoded = false;
|
||||
|
||||
// low nibble of first byte should be 0x08
|
||||
list( , $first_nibble ) = unpack( 'h', $gzData );
|
||||
list(, $first_nibble) = unpack('h', $gzData);
|
||||
|
||||
// First 2 bytes should be divisible by 0x1F
|
||||
list( , $first_two_bytes ) = unpack( 'n', $gzData );
|
||||
list(, $first_two_bytes) = unpack('n', $gzData);
|
||||
|
||||
if ( 0x08 == $first_nibble && 0 == ( $first_two_bytes % 0x1F ) )
|
||||
if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
|
||||
$huffman_encoded = true;
|
||||
|
||||
if ( $huffman_encoded ) {
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) )
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
if ( "\x50\x4b\x03\x04" == substr( $gzData, 0, 4 ) ) {
|
||||
if ($huffman_encoded) {
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
}
|
||||
|
||||
if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {
|
||||
// ZIP file format header
|
||||
// Offset 6: 2 bytes, General-purpose field
|
||||
// Offset 26: 2 bytes, filename length
|
||||
// Offset 28: 2 bytes, optional field length
|
||||
// Offset 30: Filename field, followed by optional field, followed
|
||||
// immediately by data
|
||||
list( , $general_purpose_flag ) = unpack( 'v', substr( $gzData, 6, 2 ) );
|
||||
list(, $general_purpose_flag) = unpack('v', substr($gzData, 6, 2));
|
||||
|
||||
// If the file has been compressed on the fly, 0x08 bit is set of
|
||||
// the general purpose field. We can use this to differentiate
|
||||
// between a compressed document, and a ZIP file
|
||||
$zip_compressed_on_the_fly = ( 0x08 == (0x08 & $general_purpose_flag ) );
|
||||
$zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag));
|
||||
|
||||
if ( ! $zip_compressed_on_the_fly ) {
|
||||
if (!$zip_compressed_on_the_fly) {
|
||||
// Don't attempt to decode a compressed zip file
|
||||
return $gzData;
|
||||
}
|
||||
|
||||
// Determine the first byte of data, based on the above ZIP header
|
||||
// offsets:
|
||||
$first_file_start = array_sum( unpack( 'v2', substr( $gzData, 26, 4 ) ) );
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 30 + $first_file_start ) ) ) ) {
|
||||
$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finally fall back to straight gzinflate
|
||||
if ( false !== ( $decompressed = @gzinflate( $gzData ) ) ) {
|
||||
if (false !== ($decompressed = @gzinflate($gzData))) {
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
// Fallback for all above failing, not expected, but included for
|
||||
// debugging and preventing regressions and to track stats
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) ) {
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
|
|
|
|||
0
vendor/rmccue/requests/library/Requests/Auth.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Auth.php
vendored
Executable file → Normal file
2
vendor/rmccue/requests/library/Requests/Auth/Basic.php
vendored
Executable file → Normal file
2
vendor/rmccue/requests/library/Requests/Auth/Basic.php
vendored
Executable file → Normal file
|
|
@ -74,7 +74,7 @@ class Requests_Auth_Basic implements Requests_Auth {
|
|||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= "Authorization: Basic " . base64_encode($this->getAuthString()) . "\r\n";
|
||||
$out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
355
vendor/rmccue/requests/library/Requests/Cookie.php
vendored
355
vendor/rmccue/requests/library/Requests/Cookie.php
vendored
|
|
@ -14,37 +14,290 @@
|
|||
*/
|
||||
class Requests_Cookie {
|
||||
/**
|
||||
*
|
||||
* Cookie name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Cookie value.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Cookie attributes
|
||||
*
|
||||
*
|
||||
* Valid keys are (currently) path, domain, expires, max-age, secure and
|
||||
* httponly.
|
||||
*
|
||||
* @var array
|
||||
* @var Requests_Utility_CaseInsensitiveDictionary|array Array-like object
|
||||
*/
|
||||
public $attributes = array();
|
||||
|
||||
/**
|
||||
* Cookie flags
|
||||
*
|
||||
* Valid keys are (currently) creation, last-access, persistent and
|
||||
* host-only.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $flags = array();
|
||||
|
||||
/**
|
||||
* Reference time for relative calculations
|
||||
*
|
||||
* This is used in place of `time()` when calculating Max-Age expiration and
|
||||
* checking time validity.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $reference_time = 0;
|
||||
|
||||
/**
|
||||
* Create a new cookie object
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param array $attributes Associative array of attribute data
|
||||
* @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
|
||||
*/
|
||||
public function __construct($name, $value, $attributes = array()) {
|
||||
public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) {
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->attributes = $attributes;
|
||||
$default_flags = array(
|
||||
'creation' => time(),
|
||||
'last-access' => time(),
|
||||
'persistent' => false,
|
||||
'host-only' => true,
|
||||
);
|
||||
$this->flags = array_merge($default_flags, $flags);
|
||||
|
||||
$this->reference_time = time();
|
||||
if ($reference_time !== null) {
|
||||
$this->reference_time = $reference_time;
|
||||
}
|
||||
|
||||
$this->normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie is expired.
|
||||
*
|
||||
* Checks the age against $this->reference_time to determine if the cookie
|
||||
* is expired.
|
||||
*
|
||||
* @return boolean True if expired, false if time is valid.
|
||||
*/
|
||||
public function is_expired() {
|
||||
// RFC6265, s. 4.1.2.2:
|
||||
// If a cookie has both the Max-Age and the Expires attribute, the Max-
|
||||
// Age attribute has precedence and controls the expiration date of the
|
||||
// cookie.
|
||||
if (isset($this->attributes['max-age'])) {
|
||||
$max_age = $this->attributes['max-age'];
|
||||
return $max_age < $this->reference_time;
|
||||
}
|
||||
|
||||
if (isset($this->attributes['expires'])) {
|
||||
$expires = $this->attributes['expires'];
|
||||
return $expires < $this->reference_time;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie is valid for a given URI
|
||||
*
|
||||
* @param Requests_IRI $uri URI to check
|
||||
* @return boolean Whether the cookie is valid for the given URI
|
||||
*/
|
||||
public function uri_matches(Requests_IRI $uri) {
|
||||
if (!$this->domain_matches($uri->host)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->path_matches($uri->path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return empty($this->attributes['secure']) || $uri->scheme === 'https';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie is valid for a given domain
|
||||
*
|
||||
* @param string $string Domain to check
|
||||
* @return boolean Whether the cookie is valid for the given domain
|
||||
*/
|
||||
public function domain_matches($string) {
|
||||
if (!isset($this->attributes['domain'])) {
|
||||
// Cookies created manually; cookies created by Requests will set
|
||||
// the domain to the requested domain
|
||||
return true;
|
||||
}
|
||||
|
||||
$domain_string = $this->attributes['domain'];
|
||||
if ($domain_string === $string) {
|
||||
// The domain string and the string are identical.
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the cookie is marked as host-only and we don't have an exact
|
||||
// match, reject the cookie
|
||||
if ($this->flags['host-only'] === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen($string) <= strlen($domain_string)) {
|
||||
// For obvious reasons, the string cannot be a suffix if the domain
|
||||
// is shorter than the domain string
|
||||
return false;
|
||||
}
|
||||
|
||||
if (substr($string, -1 * strlen($domain_string)) !== $domain_string) {
|
||||
// The domain string should be a suffix of the string.
|
||||
return false;
|
||||
}
|
||||
|
||||
$prefix = substr($string, 0, strlen($string) - strlen($domain_string));
|
||||
if (substr($prefix, -1) !== '.') {
|
||||
// The last character of the string that is not included in the
|
||||
// domain string should be a %x2E (".") character.
|
||||
return false;
|
||||
}
|
||||
|
||||
// The string should be a host name (i.e., not an IP address).
|
||||
return !preg_match('#^(.+\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cookie is valid for a given path
|
||||
*
|
||||
* From the path-match check in RFC 6265 section 5.1.4
|
||||
*
|
||||
* @param string $request_path Path to check
|
||||
* @return boolean Whether the cookie is valid for the given path
|
||||
*/
|
||||
public function path_matches($request_path) {
|
||||
if (empty($request_path)) {
|
||||
// Normalize empty path to root
|
||||
$request_path = '/';
|
||||
}
|
||||
|
||||
if (!isset($this->attributes['path'])) {
|
||||
// Cookies created manually; cookies created by Requests will set
|
||||
// the path to the requested path
|
||||
return true;
|
||||
}
|
||||
|
||||
$cookie_path = $this->attributes['path'];
|
||||
|
||||
if ($cookie_path === $request_path) {
|
||||
// The cookie-path and the request-path are identical.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) {
|
||||
if (substr($cookie_path, -1) === '/') {
|
||||
// The cookie-path is a prefix of the request-path, and the last
|
||||
// character of the cookie-path is %x2F ("/").
|
||||
return true;
|
||||
}
|
||||
|
||||
if (substr($request_path, strlen($cookie_path), 1) === '/') {
|
||||
// The cookie-path is a prefix of the request-path, and the
|
||||
// first character of the request-path that is not included in
|
||||
// the cookie-path is a %x2F ("/") character.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize cookie and attributes
|
||||
*
|
||||
* @return boolean Whether the cookie was successfully normalized
|
||||
*/
|
||||
public function normalize() {
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
$orig_value = $value;
|
||||
$value = $this->normalize_attribute($key, $value);
|
||||
if ($value === null) {
|
||||
unset($this->attributes[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value !== $orig_value) {
|
||||
$this->attributes[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an individual cookie attribute
|
||||
*
|
||||
* Handles parsing individual attributes from the cookie values.
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
* @param string|boolean $value Attribute value (string value, or true if empty/flag)
|
||||
* @return mixed Value if available, or null if the attribute value is invalid (and should be skipped)
|
||||
*/
|
||||
protected function normalize_attribute($name, $value) {
|
||||
switch (strtolower($name)) {
|
||||
case 'expires':
|
||||
// Expiration parsing, as per RFC 6265 section 5.2.1
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$expiry_time = strtotime($value);
|
||||
if ($expiry_time === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $expiry_time;
|
||||
|
||||
case 'max-age':
|
||||
// Expiration parsing, as per RFC 6265 section 5.2.2
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Check that we have a valid age
|
||||
if (!preg_match('/^-?\d+$/', $value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$delta_seconds = (int) $value;
|
||||
if ($delta_seconds <= 0) {
|
||||
$expiry_time = 0;
|
||||
}
|
||||
else {
|
||||
$expiry_time = $this->reference_time + $delta_seconds;
|
||||
}
|
||||
|
||||
return $expiry_time;
|
||||
|
||||
case 'domain':
|
||||
// Domain normalization, as per RFC 6265 section 5.2.3
|
||||
if ($value[0] === '.') {
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
default:
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,10 +307,21 @@ class Requests_Cookie {
|
|||
*
|
||||
* @return string Cookie formatted for Cookie header
|
||||
*/
|
||||
public function formatForHeader() {
|
||||
public function format_for_header() {
|
||||
return sprintf('%s=%s', $this->name, $this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a cookie for a Cookie header
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see Requests_Cookie::format_for_header}
|
||||
* @return string
|
||||
*/
|
||||
public function formatForHeader() {
|
||||
return $this->format_for_header();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a cookie for a Set-Cookie header
|
||||
*
|
||||
|
|
@ -66,8 +330,8 @@ class Requests_Cookie {
|
|||
*
|
||||
* @return string Cookie formatted for Set-Cookie header
|
||||
*/
|
||||
public function formatForSetCookie() {
|
||||
$header_value = $this->formatForHeader();
|
||||
public function format_for_set_cookie() {
|
||||
$header_value = $this->format_for_header();
|
||||
if (!empty($this->attributes)) {
|
||||
$parts = array();
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
|
|
@ -85,6 +349,17 @@ class Requests_Cookie {
|
|||
return $header_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a cookie for a Set-Cookie header
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see Requests_Cookie::format_for_set_cookie}
|
||||
* @return string
|
||||
*/
|
||||
public function formatForSetCookie() {
|
||||
return $this->format_for_set_cookie();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cookie value
|
||||
*
|
||||
|
|
@ -104,7 +379,7 @@ class Requests_Cookie {
|
|||
* @param string Cookie header value (from a Set-Cookie header)
|
||||
* @return Requests_Cookie Parsed cookie object
|
||||
*/
|
||||
public static function parse($string, $name = '') {
|
||||
public static function parse($string, $name = '', $reference_time = null) {
|
||||
$parts = explode(';', $string);
|
||||
$kvparts = array_shift($parts);
|
||||
|
||||
|
|
@ -145,16 +420,18 @@ class Requests_Cookie {
|
|||
}
|
||||
}
|
||||
|
||||
return new Requests_Cookie($name, $value, $attributes);
|
||||
return new Requests_Cookie($name, $value, $attributes, array(), $reference_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse all Set-Cookie headers from request headers
|
||||
*
|
||||
* @param Requests_Response_Headers $headers
|
||||
* @param Requests_Response_Headers $headers Headers to parse from
|
||||
* @param Requests_IRI|null $origin URI for comparing cookie origins
|
||||
* @param int|null $time Reference time for expiration calculation
|
||||
* @return array
|
||||
*/
|
||||
public static function parseFromHeaders(Requests_Response_Headers $headers) {
|
||||
public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) {
|
||||
$cookie_headers = $headers->getValues('Set-Cookie');
|
||||
if (empty($cookie_headers)) {
|
||||
return array();
|
||||
|
|
@ -162,10 +439,62 @@ class Requests_Cookie {
|
|||
|
||||
$cookies = array();
|
||||
foreach ($cookie_headers as $header) {
|
||||
$parsed = self::parse($header);
|
||||
$parsed = self::parse($header, '', $time);
|
||||
|
||||
// Default domain/path attributes
|
||||
if (empty($parsed->attributes['domain']) && !empty($origin)) {
|
||||
$parsed->attributes['domain'] = $origin->host;
|
||||
$parsed->flags['host-only'] = true;
|
||||
}
|
||||
else {
|
||||
$parsed->flags['host-only'] = false;
|
||||
}
|
||||
|
||||
$path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/');
|
||||
if (!$path_is_valid && !empty($origin)) {
|
||||
$path = $origin->path;
|
||||
|
||||
// Default path normalization as per RFC 6265 section 5.1.4
|
||||
if (substr($path, 0, 1) !== '/') {
|
||||
// If the uri-path is empty or if the first character of
|
||||
// the uri-path is not a %x2F ("/") character, output
|
||||
// %x2F ("/") and skip the remaining steps.
|
||||
$path = '/';
|
||||
}
|
||||
elseif (substr_count($path, '/') === 1) {
|
||||
// If the uri-path contains no more than one %x2F ("/")
|
||||
// character, output %x2F ("/") and skip the remaining
|
||||
// step.
|
||||
$path = '/';
|
||||
}
|
||||
else {
|
||||
// Output the characters of the uri-path from the first
|
||||
// character up to, but not including, the right-most
|
||||
// %x2F ("/").
|
||||
$path = substr($path, 0, strrpos($path, '/'));
|
||||
}
|
||||
$parsed->attributes['path'] = $path;
|
||||
}
|
||||
|
||||
// Reject invalid cookie domains
|
||||
if (!empty($origin) && !$parsed->domain_matches($origin->host)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cookies[$parsed->name] = $parsed;
|
||||
}
|
||||
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse all Set-Cookie headers from request headers
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see Requests_Cookie::parse_from_headers}
|
||||
* @return string
|
||||
*/
|
||||
public static function parseFromHeaders(Requests_Response_Headers $headers) {
|
||||
return self::parse_from_headers($headers);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
|
|||
* @param string|Requests_Cookie $cookie
|
||||
* @return Requests_Cookie
|
||||
*/
|
||||
public function normalizeCookie($cookie, $key = null) {
|
||||
public function normalize_cookie($cookie, $key = null) {
|
||||
if ($cookie instanceof Requests_Cookie) {
|
||||
return $cookie;
|
||||
}
|
||||
|
|
@ -43,6 +43,17 @@ class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
|
|||
return Requests_Cookie::parse($cookie, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise cookie data into a Requests_Cookie
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie}
|
||||
* @return Requests_Cookie
|
||||
*/
|
||||
public function normalizeCookie($cookie, $key = null) {
|
||||
return $this->normalize_cookie($cookie, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
|
|
@ -60,8 +71,9 @@ class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
|
|||
* @return string Item value
|
||||
*/
|
||||
public function offsetGet($key) {
|
||||
if (!isset($this->cookies[$key]))
|
||||
if (!isset($this->cookies[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cookies[$key];
|
||||
}
|
||||
|
|
@ -121,12 +133,24 @@ class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
|
|||
* @param string $type
|
||||
* @param array $options
|
||||
*/
|
||||
public function before_request(&$url, &$headers, &$data, &$type, &$options) {
|
||||
public function before_request($url, &$headers, &$data, &$type, &$options) {
|
||||
if (!$url instanceof Requests_IRI) {
|
||||
$url = new Requests_IRI($url);
|
||||
}
|
||||
|
||||
if (!empty($this->cookies)) {
|
||||
$cookies = array();
|
||||
foreach ($this->cookies as $key => $cookie) {
|
||||
$cookie = $this->normalizeCookie($cookie, $key);
|
||||
$cookies[] = $cookie->formatForHeader();
|
||||
$cookie = $this->normalize_cookie($cookie, $key);
|
||||
|
||||
// Skip expired cookies
|
||||
if ($cookie->is_expired()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cookie->domain_matches($url->host)) {
|
||||
$cookies[] = $cookie->format_for_header();
|
||||
}
|
||||
}
|
||||
|
||||
$headers['Cookie'] = implode('; ', $cookies);
|
||||
|
|
@ -139,7 +163,12 @@ class Requests_Cookie_Jar implements ArrayAccess, IteratorAggregate {
|
|||
* @var Requests_Response $response
|
||||
*/
|
||||
public function before_redirect_check(Requests_Response &$return) {
|
||||
$cookies = Requests_Cookie::parseFromHeaders($return->headers);
|
||||
$url = $return->url;
|
||||
if (!$url instanceof Requests_IRI) {
|
||||
$url = new Requests_IRI($url);
|
||||
}
|
||||
|
||||
$cookies = Requests_Cookie::parse_from_headers($return->headers, $url);
|
||||
$this->cookies = array_merge($this->cookies, $cookies);
|
||||
$return->cookies = $this;
|
||||
}
|
||||
|
|
|
|||
0
vendor/rmccue/requests/library/Requests/Exception.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception.php
vendored
Executable file → Normal file
8
vendor/rmccue/requests/library/Requests/Exception/HTTP.php
vendored
Executable file → Normal file
8
vendor/rmccue/requests/library/Requests/Exception/HTTP.php
vendored
Executable file → Normal file
|
|
@ -31,7 +31,7 @@ class Requests_Exception_HTTP extends Requests_Exception {
|
|||
* There is no mechanism to pass in the status code, as this is set by the
|
||||
* subclass used. Reason phrases can vary, however.
|
||||
*
|
||||
* @param string $reason Reason phrase
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
|
|
@ -53,10 +53,14 @@ class Requests_Exception_HTTP extends Requests_Exception {
|
|||
/**
|
||||
* Get the correct exception class for a given error code
|
||||
*
|
||||
* @param int $code HTTP status code
|
||||
* @param int|bool $code HTTP status code, or false if unavailable
|
||||
* @return string Exception class name to use
|
||||
*/
|
||||
public static function get_class($code) {
|
||||
if (!$code) {
|
||||
return 'Requests_Exception_HTTP_Unknown';
|
||||
}
|
||||
|
||||
$class = sprintf('Requests_Exception_HTTP_%d', $code);
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
|
|
|
|||
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/304.php
vendored
Normal file
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/304.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_304 extends Requests_Exception_HTTP {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 304;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Modified';
|
||||
}
|
||||
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/305.php
vendored
Normal file
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/305.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_305 extends Requests_Exception_HTTP {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 305;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Use Proxy';
|
||||
}
|
||||
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/306.php
vendored
Normal file
27
vendor/rmccue/requests/library/Requests/Exception/HTTP/306.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_306 extends Requests_Exception_HTTP {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 306;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Switch Proxy';
|
||||
}
|
||||
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/400.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/400.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/401.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/401.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/402.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/402.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/403.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/403.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/404.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/404.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/405.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/405.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/406.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/406.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/407.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/407.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/408.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/408.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/409.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/409.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/410.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/410.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/411.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/411.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/412.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/412.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/413.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/413.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/414.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/414.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/415.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/415.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/416.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/416.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/417.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/417.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/418.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/418.php
vendored
Executable file → Normal file
|
|
@ -2,14 +2,14 @@
|
|||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2324
|
||||
* @see https://tools.ietf.org/html/rfc2324
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2324
|
||||
* @see https://tools.ietf.org/html/rfc2324
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_418 extends Requests_Exception_HTTP {
|
||||
|
|
|
|||
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/428.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/428.php
vendored
Executable file → Normal file
|
|
@ -2,14 +2,14 @@
|
|||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_428 extends Requests_Exception_HTTP {
|
||||
|
|
|
|||
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/429.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/429.php
vendored
Executable file → Normal file
|
|
@ -2,14 +2,14 @@
|
|||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
* @see https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
* @see https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_429 extends Requests_Exception_HTTP {
|
||||
|
|
|
|||
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/431.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/431.php
vendored
Executable file → Normal file
|
|
@ -2,14 +2,14 @@
|
|||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_431 extends Requests_Exception_HTTP {
|
||||
|
|
|
|||
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/500.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/500.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/501.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/501.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/502.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/502.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/503.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/503.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/504.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/504.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/505.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Exception/HTTP/505.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/511.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/511.php
vendored
Executable file → Normal file
|
|
@ -2,14 +2,14 @@
|
|||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc6585
|
||||
* @see https://tools.ietf.org/html/rfc6585
|
||||
* @package Requests
|
||||
*/
|
||||
class Requests_Exception_HTTP_511 extends Requests_Exception_HTTP {
|
||||
|
|
|
|||
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/Unknown.php
vendored
Executable file → Normal file
4
vendor/rmccue/requests/library/Requests/Exception/HTTP/Unknown.php
vendored
Executable file → Normal file
|
|
@ -14,7 +14,7 @@ class Requests_Exception_HTTP_Unknown extends Requests_Exception_HTTP {
|
|||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
* @var integer|bool Code if available, false if an error occurred
|
||||
*/
|
||||
protected $code = 0;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class Requests_Exception_HTTP_Unknown extends Requests_Exception_HTTP {
|
|||
* If `$data` is an instance of {@see Requests_Response}, uses the status
|
||||
* code from it. Otherwise, sets as 0
|
||||
*
|
||||
* @param string $reason Reason phrase
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
|
|
|
|||
5
vendor/rmccue/requests/library/Requests/Exception/Transport.php
vendored
Normal file
5
vendor/rmccue/requests/library/Requests/Exception/Transport.php
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
class Requests_Exception_Transport extends Requests_Exception {
|
||||
|
||||
}
|
||||
56
vendor/rmccue/requests/library/Requests/Exception/Transport/cURL.php
vendored
Normal file
56
vendor/rmccue/requests/library/Requests/Exception/Transport/cURL.php
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class Requests_Exception_Transport_cURL extends Requests_Exception_Transport {
|
||||
|
||||
const EASY = 'cURLEasy';
|
||||
const MULTI = 'cURLMulti';
|
||||
const SHARE = 'cURLShare';
|
||||
|
||||
/**
|
||||
* cURL error code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = -1;
|
||||
|
||||
/**
|
||||
* Which type of cURL error
|
||||
*
|
||||
* EASY|MULTI|SHARE
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Unknown';
|
||||
|
||||
/**
|
||||
* Clear text error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
public function __construct($message, $type, $data = null, $code = 0) {
|
||||
if ($type !== null) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
if ($code !== null) {
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
if ($message !== null) {
|
||||
$this->reason = $message;
|
||||
}
|
||||
|
||||
$message = sprintf('%d %s', $this->code, $this->reason);
|
||||
parent::__construct($message, $this->type, $data, $this->code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error message
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
}
|
||||
0
vendor/rmccue/requests/library/Requests/Hooker.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Hooker.php
vendored
Executable file → Normal file
7
vendor/rmccue/requests/library/Requests/Hooks.php
vendored
Executable file → Normal file
7
vendor/rmccue/requests/library/Requests/Hooks.php
vendored
Executable file → Normal file
|
|
@ -13,6 +13,13 @@
|
|||
* @subpackage Utilities
|
||||
*/
|
||||
class Requests_Hooks implements Requests_Hooker {
|
||||
/**
|
||||
* Registered callbacks for each hook
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hooks = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
|
|
|||
16
vendor/rmccue/requests/library/Requests/IDNAEncoder.php
vendored
Executable file → Normal file
16
vendor/rmccue/requests/library/Requests/IDNAEncoder.php
vendored
Executable file → Normal file
|
|
@ -7,14 +7,14 @@
|
|||
*
|
||||
* @package Requests
|
||||
* @subpackage Utilities
|
||||
* @see http://tools.ietf.org/html/rfc3490 IDNA specification
|
||||
* @see http://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
|
||||
* @see https://tools.ietf.org/html/rfc3490 IDNA specification
|
||||
* @see https://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
|
||||
*/
|
||||
class Requests_IDNAEncoder {
|
||||
/**
|
||||
* ACE prefix used for IDNA
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc3490#section-5
|
||||
* @see https://tools.ietf.org/html/rfc3490#section-5
|
||||
* @var string
|
||||
*/
|
||||
const ACE_PREFIX = 'xn--';
|
||||
|
|
@ -22,7 +22,7 @@ class Requests_IDNAEncoder {
|
|||
/**#@+
|
||||
* Bootstrap constant for Punycode
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc3492#section-5
|
||||
* @see https://tools.ietf.org/html/rfc3492#section-5
|
||||
* @var int
|
||||
*/
|
||||
const BOOTSTRAP_BASE = 36;
|
||||
|
|
@ -237,6 +237,7 @@ class Requests_IDNAEncoder {
|
|||
$h = $b = 0; // see loop
|
||||
# copy them to the output in order
|
||||
$codepoints = self::utf8_to_codepoints($input);
|
||||
$extended = array();
|
||||
|
||||
foreach ($codepoints as $char) {
|
||||
if ($char < 128) {
|
||||
|
|
@ -303,7 +304,6 @@ class Requests_IDNAEncoder {
|
|||
}
|
||||
# output the code point for digit t + ((q - t) mod (base - t))
|
||||
$digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));
|
||||
//printf('needed delta is %d, encodes as "%s"' . PHP_EOL, $delta, self::digit_to_char($digit));
|
||||
$output .= self::digit_to_char($digit);
|
||||
# let q = (q - t) div (base - t)
|
||||
$q = floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
|
||||
|
|
@ -311,10 +311,8 @@ class Requests_IDNAEncoder {
|
|||
}
|
||||
# output the code point for digit q
|
||||
$output .= self::digit_to_char($q);
|
||||
//printf('needed delta is %d, encodes as "%s"' . PHP_EOL, $delta, self::digit_to_char($q));
|
||||
# let bias = adapt(delta, h + 1, test h equals b?)
|
||||
$bias = self::adapt($delta, $h + 1, $h === $b);
|
||||
//printf('bias becomes %d' . PHP_EOL, $bias);
|
||||
# let delta = 0
|
||||
$delta = 0;
|
||||
# increment h
|
||||
|
|
@ -335,7 +333,7 @@ class Requests_IDNAEncoder {
|
|||
/**
|
||||
* Convert a digit to its respective character
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc3492#section-5
|
||||
* @see https://tools.ietf.org/html/rfc3492#section-5
|
||||
* @throws Requests_Exception On invalid digit (`idna.invalid_digit`)
|
||||
*
|
||||
* @param int $digit Digit in the range 0-35
|
||||
|
|
@ -355,7 +353,7 @@ class Requests_IDNAEncoder {
|
|||
/**
|
||||
* Adapt the bias
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc3492#section-6.1
|
||||
* @see https://tools.ietf.org/html/rfc3492#section-6.1
|
||||
* @param int $delta
|
||||
* @param int $numpoints
|
||||
* @param bool $firsttime
|
||||
|
|
|
|||
355
vendor/rmccue/requests/library/Requests/IPv6.php
vendored
Executable file → Normal file
355
vendor/rmccue/requests/library/Requests/IPv6.php
vendored
Executable file → Normal file
|
|
@ -15,207 +15,176 @@
|
|||
* @package Requests
|
||||
* @subpackage Utilities
|
||||
*/
|
||||
class Requests_IPv6
|
||||
{
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
||||
* the required number of zero pieces.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*/
|
||||
public static function uncompress($ip)
|
||||
{
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (substr_count($ip, '::') === 1)
|
||||
{
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
if ($ip1 === '')
|
||||
{
|
||||
$c1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c1 = substr_count($ip1, ':');
|
||||
}
|
||||
if ($ip2 === '')
|
||||
{
|
||||
$c2 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c2 = substr_count($ip2, ':');
|
||||
}
|
||||
if (strpos($ip2, '.') !== false)
|
||||
{
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ($c1 === -1 && $c2 === -1)
|
||||
{
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
}
|
||||
// ::xxx
|
||||
else if ($c1 === -1)
|
||||
{
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::
|
||||
else if ($c2 === -1)
|
||||
{
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::xxx
|
||||
else
|
||||
{
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
class Requests_IPv6 {
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
||||
* the required number of zero pieces.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*/
|
||||
public static function uncompress($ip) {
|
||||
if (substr_count($ip, '::') !== 1) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
||||
* zero pieces to '::'.
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @see uncompress()
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip)
|
||||
{
|
||||
// Prepare the IP to be compressed
|
||||
$ip = self::uncompress($ip);
|
||||
$ip_parts = self::split_v6_v4($ip);
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
|
||||
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
|
||||
|
||||
// Replace all leading zeros
|
||||
$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
|
||||
if (strpos($ip2, '.') !== false) {
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ($c1 === -1 && $c2 === -1) {
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
}
|
||||
// ::xxx
|
||||
else if ($c1 === -1) {
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::
|
||||
else if ($c2 === -1) {
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::xxx
|
||||
else {
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
// Find bunches of zeros
|
||||
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
|
||||
{
|
||||
$max = 0;
|
||||
$pos = null;
|
||||
foreach ($matches[0] as $match)
|
||||
{
|
||||
if (strlen($match[0]) > $max)
|
||||
{
|
||||
$max = strlen($match[0]);
|
||||
$pos = $match[1];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
||||
* zero pieces to '::'.
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @see uncompress()
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip) {
|
||||
// Prepare the IP to be compressed
|
||||
$ip = self::uncompress($ip);
|
||||
$ip_parts = self::split_v6_v4($ip);
|
||||
|
||||
$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
|
||||
}
|
||||
// Replace all leading zeros
|
||||
$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
|
||||
|
||||
if ($ip_parts[1] !== '')
|
||||
{
|
||||
return implode(':', $ip_parts);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ip_parts[0];
|
||||
}
|
||||
}
|
||||
// Find bunches of zeros
|
||||
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
|
||||
$max = 0;
|
||||
$pos = null;
|
||||
foreach ($matches[0] as $match) {
|
||||
if (strlen($match[0]) > $max) {
|
||||
$max = strlen($match[0]);
|
||||
$pos = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
||||
*
|
||||
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
||||
* using the standard IPv4 representation
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return array [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
||||
*/
|
||||
private static function split_v6_v4($ip)
|
||||
{
|
||||
if (strpos($ip, '.') !== false)
|
||||
{
|
||||
$pos = strrpos($ip, ':');
|
||||
$ipv6_part = substr($ip, 0, $pos);
|
||||
$ipv4_part = substr($ip, $pos + 1);
|
||||
return array($ipv6_part, $ipv4_part);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array($ip, '');
|
||||
}
|
||||
}
|
||||
$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function check_ipv6($ip)
|
||||
{
|
||||
$ip = self::uncompress($ip);
|
||||
list($ipv6, $ipv4) = self::split_v6_v4($ip);
|
||||
$ipv6 = explode(':', $ipv6);
|
||||
$ipv4 = explode('.', $ipv4);
|
||||
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
|
||||
{
|
||||
foreach ($ipv6 as $ipv6_part)
|
||||
{
|
||||
// The section can't be empty
|
||||
if ($ipv6_part === '')
|
||||
return false;
|
||||
if ($ip_parts[1] !== '') {
|
||||
return implode(':', $ip_parts);
|
||||
}
|
||||
else {
|
||||
return $ip_parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Nor can it be over four characters
|
||||
if (strlen($ipv6_part) > 4)
|
||||
return false;
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
||||
*
|
||||
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
||||
* using the standard IPv4 representation
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
||||
*/
|
||||
protected static function split_v6_v4($ip) {
|
||||
if (strpos($ip, '.') !== false) {
|
||||
$pos = strrpos($ip, ':');
|
||||
$ipv6_part = substr($ip, 0, $pos);
|
||||
$ipv4_part = substr($ip, $pos + 1);
|
||||
return array($ipv6_part, $ipv4_part);
|
||||
}
|
||||
else {
|
||||
return array($ip, '');
|
||||
}
|
||||
}
|
||||
|
||||
// Remove leading zeros (this is safe because of the above)
|
||||
$ipv6_part = ltrim($ipv6_part, '0');
|
||||
if ($ipv6_part === '')
|
||||
$ipv6_part = '0';
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function check_ipv6($ip) {
|
||||
$ip = self::uncompress($ip);
|
||||
list($ipv6, $ipv4) = self::split_v6_v4($ip);
|
||||
$ipv6 = explode(':', $ipv6);
|
||||
$ipv4 = explode('.', $ipv4);
|
||||
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
|
||||
foreach ($ipv6 as $ipv6_part) {
|
||||
// The section can't be empty
|
||||
if ($ipv6_part === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the value is valid
|
||||
$value = hexdec($ipv6_part);
|
||||
if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
|
||||
return false;
|
||||
}
|
||||
if (count($ipv4) === 4)
|
||||
{
|
||||
foreach ($ipv4 as $ipv4_part)
|
||||
{
|
||||
$value = (int) $ipv4_part;
|
||||
if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Nor can it be over four characters
|
||||
if (strlen($ipv6_part) > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove leading zeros (this is safe because of the above)
|
||||
$ipv6_part = ltrim($ipv6_part, '0');
|
||||
if ($ipv6_part === '') {
|
||||
$ipv6_part = '0';
|
||||
}
|
||||
|
||||
// Check the value is valid
|
||||
$value = hexdec($ipv6_part);
|
||||
if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count($ipv4) === 4) {
|
||||
foreach ($ipv4 as $ipv4_part) {
|
||||
$value = (int) $ipv4_part;
|
||||
if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2206
vendor/rmccue/requests/library/Requests/IRI.php
vendored
Executable file → Normal file
2206
vendor/rmccue/requests/library/Requests/IRI.php
vendored
Executable file → Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -67,7 +67,7 @@ class Requests_Proxy_HTTP implements Requests_Proxy {
|
|||
$this->use_authentication = true;
|
||||
}
|
||||
else {
|
||||
throw new Requests_Exception( 'Invalid number of arguments', 'proxyhttpbadargs');
|
||||
throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ class Requests_Proxy_HTTP implements Requests_Proxy {
|
|||
|
||||
$hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket'));
|
||||
$hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path'));
|
||||
if( $this->use_authentication ) {
|
||||
if ($this->use_authentication) {
|
||||
$hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
|
||||
}
|
||||
}
|
||||
|
|
@ -112,9 +112,9 @@ class Requests_Proxy_HTTP implements Requests_Proxy {
|
|||
* Alter remote socket information before opening socket connection
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $out HTTP header string
|
||||
* @param string $remote_socket Socket connection string
|
||||
*/
|
||||
public function fsockopen_remote_socket( &$remote_socket ) {
|
||||
public function fsockopen_remote_socket(&$remote_socket) {
|
||||
$remote_socket = $this->proxy;
|
||||
}
|
||||
|
||||
|
|
@ -122,9 +122,10 @@ class Requests_Proxy_HTTP implements Requests_Proxy {
|
|||
* Alter remote path before getting stream data
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $out HTTP header string
|
||||
* @param string $path Path to send in HTTP request string ("GET ...")
|
||||
* @param string $url Full URL we're requesting
|
||||
*/
|
||||
public function fsockopen_remote_host_path( &$path, $url ) {
|
||||
public function fsockopen_remote_host_path(&$path, $url) {
|
||||
$path = $url;
|
||||
}
|
||||
|
||||
|
|
@ -134,8 +135,8 @@ class Requests_Proxy_HTTP implements Requests_Proxy {
|
|||
* @since 1.6
|
||||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header( &$out ) {
|
||||
$out .= "Proxy-Authorization: Basic " . base64_encode($this->get_auth_string()) . "\r\n";
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
34
vendor/rmccue/requests/library/Requests/Response.php
vendored
Executable file → Normal file
34
vendor/rmccue/requests/library/Requests/Response.php
vendored
Executable file → Normal file
|
|
@ -18,61 +18,88 @@ class Requests_Response {
|
|||
*/
|
||||
public function __construct() {
|
||||
$this->headers = new Requests_Response_Headers();
|
||||
$this->cookies = new Requests_Cookie_Jar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Response body
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Raw HTTP data from the transport
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $raw = '';
|
||||
|
||||
/**
|
||||
* Headers, as an associative array
|
||||
* @var array
|
||||
*
|
||||
* @var Requests_Response_Headers Array-like object representing headers
|
||||
*/
|
||||
public $headers = array();
|
||||
|
||||
/**
|
||||
* Status code, false if non-blocking
|
||||
*
|
||||
* @var integer|boolean
|
||||
*/
|
||||
public $status_code = false;
|
||||
|
||||
/**
|
||||
* Protocol version, false if non-blocking
|
||||
* @var float|boolean
|
||||
*/
|
||||
public $protocol_version = false;
|
||||
|
||||
/**
|
||||
* Whether the request succeeded or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $success = false;
|
||||
|
||||
/**
|
||||
* Number of redirects the request used
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $redirects = 0;
|
||||
|
||||
/**
|
||||
* URL requested
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url = '';
|
||||
|
||||
/**
|
||||
* Previous requests (from redirects)
|
||||
*
|
||||
* @var array Array of Requests_Response objects
|
||||
*/
|
||||
public $history = array();
|
||||
|
||||
/**
|
||||
* Cookies from the request
|
||||
*
|
||||
* @var Requests_Cookie_Jar Array-like object representing a cookie jar
|
||||
*/
|
||||
public $cookies = array();
|
||||
|
||||
/**
|
||||
* Is the response a redirect?
|
||||
*
|
||||
* @return boolean True if redirect (3xx status), false if not.
|
||||
*/
|
||||
public function is_redirect() {
|
||||
$code = $this->status_code;
|
||||
return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the request was not successful
|
||||
*
|
||||
|
|
@ -81,15 +108,14 @@ class Requests_Response {
|
|||
* @param boolean $allow_redirects Set to false to throw on a 3xx as well
|
||||
*/
|
||||
public function throw_for_status($allow_redirects = true) {
|
||||
if ($this->status_code >= 300 && $this->status_code < 400) {
|
||||
if ($this->is_redirect()) {
|
||||
if (!$allow_redirects) {
|
||||
throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
|
||||
}
|
||||
}
|
||||
|
||||
elseif (!$this->success) {
|
||||
$exception = Requests_Exception_HTTP::get_class($this->status_code);
|
||||
throw new $exception(null, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
vendor/rmccue/requests/library/Requests/Response/Headers.php
vendored
Executable file → Normal file
9
vendor/rmccue/requests/library/Requests/Response/Headers.php
vendored
Executable file → Normal file
|
|
@ -25,8 +25,9 @@ class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictiona
|
|||
*/
|
||||
public function offsetGet($key) {
|
||||
$key = strtolower($key);
|
||||
if (!isset($this->data[$key]))
|
||||
if (!isset($this->data[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->flatten($this->data[$key]);
|
||||
}
|
||||
|
|
@ -61,8 +62,9 @@ class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictiona
|
|||
*/
|
||||
public function getValues($key) {
|
||||
$key = strtolower($key);
|
||||
if (!isset($this->data[$key]))
|
||||
if (!isset($this->data[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
|
@ -77,8 +79,9 @@ class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictiona
|
|||
* @return string Flattened value
|
||||
*/
|
||||
public function flatten($value) {
|
||||
if (is_array($value))
|
||||
if (is_array($value)) {
|
||||
$value = implode(',', $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
|
|
|||
7
vendor/rmccue/requests/library/Requests/SSL.php
vendored
Executable file → Normal file
7
vendor/rmccue/requests/library/Requests/SSL.php
vendored
Executable file → Normal file
|
|
@ -22,11 +22,11 @@ class Requests_SSL {
|
|||
* names, leading things like 'https://www.github.com/' to be invalid.
|
||||
* Instead
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
* @see https://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
*
|
||||
* @throws Requests_Exception On not obtaining a match for the host (`fsockopen.ssl.no_match`)
|
||||
* @param string $host Host name to verify against
|
||||
* @param resource $context Stream context
|
||||
* @param array $cert Certificate data from openssl_x509_parse()
|
||||
* @return bool
|
||||
*/
|
||||
public static function verify_certificate($host, $cert) {
|
||||
|
|
@ -44,8 +44,9 @@ class Requests_SSL {
|
|||
$altnames = explode(',', $cert['extensions']['subjectAltName']);
|
||||
foreach ($altnames as $altname) {
|
||||
$altname = trim($altname);
|
||||
if (strpos($altname, 'DNS:') !== 0)
|
||||
if (strpos($altname, 'DNS:') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_dns_alt = true;
|
||||
|
||||
|
|
|
|||
25
vendor/rmccue/requests/library/Requests/Session.php
vendored
Executable file → Normal file
25
vendor/rmccue/requests/library/Requests/Session.php
vendored
Executable file → Normal file
|
|
@ -81,8 +81,9 @@ class Requests_Session {
|
|||
* @return mixed|null Property value, null if none found
|
||||
*/
|
||||
public function __get($key) {
|
||||
if (isset($this->options[$key]))
|
||||
if (isset($this->options[$key])) {
|
||||
return $this->options[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -112,7 +113,9 @@ class Requests_Session {
|
|||
* @param string $key Property key
|
||||
*/
|
||||
public function __unset($key) {
|
||||
$this->options[$key] = null;
|
||||
if (isset($this->options[$key])) {
|
||||
unset($this->options[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
|
@ -172,7 +175,7 @@ class Requests_Session {
|
|||
* Note: Unlike {@see post} and {@see put}, `$headers` is required, as the
|
||||
* specification recommends that should send an ETag
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5789
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
*/
|
||||
public function patch($url, $headers, $data = array(), $options = array()) {
|
||||
return $this->request($url, $headers, $data, Requests::PATCH, $options);
|
||||
|
|
@ -191,7 +194,7 @@ class Requests_Session {
|
|||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type (use Requests constants)
|
||||
* @param array $options Options for the request (see {@see Requests::request})
|
||||
* @return Requests_Response
|
||||
|
|
@ -236,9 +239,18 @@ class Requests_Session {
|
|||
$request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
|
||||
$request['url'] = $request['url']->uri;
|
||||
}
|
||||
|
||||
if (empty($request['headers'])) {
|
||||
$request['headers'] = array();
|
||||
}
|
||||
$request['headers'] = array_merge($this->headers, $request['headers']);
|
||||
|
||||
if (is_array($request['data']) && is_array($this->data)) {
|
||||
if (empty($request['data'])) {
|
||||
if (is_array($this->data)) {
|
||||
$request['data'] = $this->data;
|
||||
}
|
||||
}
|
||||
elseif (is_array($request['data']) && is_array($this->data)) {
|
||||
$request['data'] = array_merge($this->data, $request['data']);
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +260,7 @@ class Requests_Session {
|
|||
// Disallow forcing the type, as that's a per request setting
|
||||
unset($request['options']['type']);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
vendor/rmccue/requests/library/Requests/Transport.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Transport.php
vendored
Executable file → Normal file
313
vendor/rmccue/requests/library/Requests/Transport/cURL.php
vendored
Executable file → Normal file
313
vendor/rmccue/requests/library/Requests/Transport/cURL.php
vendored
Executable file → Normal file
|
|
@ -13,6 +13,9 @@
|
|||
* @subpackage Transport
|
||||
*/
|
||||
class Requests_Transport_cURL implements Requests_Transport {
|
||||
const CURL_7_10_5 = 0x070A05;
|
||||
const CURL_7_16_2 = 0x071002;
|
||||
|
||||
/**
|
||||
* Raw HTTP data
|
||||
*
|
||||
|
|
@ -20,17 +23,24 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*/
|
||||
public $headers = '';
|
||||
|
||||
/**
|
||||
* Raw body data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $response_data = '';
|
||||
|
||||
/**
|
||||
* Information on the current request
|
||||
*
|
||||
* @var array cURL information array, see {@see http://php.net/curl_getinfo}
|
||||
* @var array cURL information array, see {@see https://secure.php.net/curl_getinfo}
|
||||
*/
|
||||
public $info;
|
||||
|
||||
/**
|
||||
* Version string
|
||||
*
|
||||
* @var string
|
||||
* @var long
|
||||
*/
|
||||
public $version;
|
||||
|
||||
|
|
@ -39,7 +49,14 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $fp;
|
||||
protected $handle;
|
||||
|
||||
/**
|
||||
* Hook dispatcher instance
|
||||
*
|
||||
* @var Requests_Hooks
|
||||
*/
|
||||
protected $hooks;
|
||||
|
||||
/**
|
||||
* Have we finished the headers yet?
|
||||
|
|
@ -55,24 +72,47 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
*/
|
||||
protected $stream_handle;
|
||||
|
||||
/**
|
||||
* How many bytes are in the response body?
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $response_bytes;
|
||||
|
||||
/**
|
||||
* What's the maximum number of bytes we should keep?
|
||||
*
|
||||
* @var int|bool Byte count, or false if no limit.
|
||||
*/
|
||||
protected $response_byte_limit;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$curl = curl_version();
|
||||
$this->version = $curl['version'];
|
||||
$this->fp = curl_init();
|
||||
$this->version = $curl['version_number'];
|
||||
$this->handle = curl_init();
|
||||
|
||||
curl_setopt($this->fp, CURLOPT_HEADER, false);
|
||||
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER, 1);
|
||||
if (version_compare($this->version, '7.10.5', '>=')) {
|
||||
curl_setopt($this->fp, CURLOPT_ENCODING, '');
|
||||
curl_setopt($this->handle, CURLOPT_HEADER, false);
|
||||
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
|
||||
if ($this->version >= self::CURL_7_10_5) {
|
||||
curl_setopt($this->handle, CURLOPT_ENCODING, '');
|
||||
}
|
||||
if (defined('CURLOPT_PROTOCOLS')) {
|
||||
curl_setopt($this->fp, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
if (defined('CURLOPT_REDIR_PROTOCOLS')) {
|
||||
curl_setopt($this->fp, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
if (is_resource($this->handle)) {
|
||||
curl_close($this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,40 +128,59 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @return string Raw HTTP result
|
||||
*/
|
||||
public function request($url, $headers = array(), $data = array(), $options = array()) {
|
||||
$this->hooks = $options['hooks'];
|
||||
|
||||
$this->setup_handle($url, $headers, $data, $options);
|
||||
|
||||
$options['hooks']->dispatch('curl.before_send', array(&$this->fp));
|
||||
$options['hooks']->dispatch('curl.before_send', array(&$this->handle));
|
||||
|
||||
if ($options['filename'] !== false) {
|
||||
$this->stream_handle = fopen($options['filename'], 'wb');
|
||||
curl_setopt($this->fp, CURLOPT_FILE, $this->stream_handle);
|
||||
}
|
||||
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
$this->response_byte_limit = false;
|
||||
if ($options['max_bytes'] !== false) {
|
||||
$this->response_byte_limit = $options['max_bytes'];
|
||||
}
|
||||
|
||||
if (isset($options['verify'])) {
|
||||
if ($options['verify'] === false) {
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
|
||||
} elseif (is_string($options['verify'])) {
|
||||
curl_setopt($this->fp, CURLOPT_CAINFO, $options['verify']);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
}
|
||||
elseif (is_string($options['verify'])) {
|
||||
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['verifyname']) && $options['verifyname'] === false) {
|
||||
curl_setopt($this->fp, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
$response = curl_exec($this->fp);
|
||||
curl_exec($this->handle);
|
||||
$response = $this->response_data;
|
||||
|
||||
$options['hooks']->dispatch('curl.after_send', array(&$fake_headers));
|
||||
$options['hooks']->dispatch('curl.after_send', array());
|
||||
|
||||
if (curl_errno($this->fp) === 23 || curl_errno($this->fp) === 61) {
|
||||
curl_setopt($this->fp, CURLOPT_ENCODING, 'none');
|
||||
$response = curl_exec($this->fp);
|
||||
if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) {
|
||||
// Reset encoding and try again
|
||||
curl_setopt($this->handle, CURLOPT_ENCODING, 'none');
|
||||
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
curl_exec($this->handle);
|
||||
$response = $this->response_data;
|
||||
}
|
||||
|
||||
$this->process_response($response, $options);
|
||||
curl_close($this->fp);
|
||||
|
||||
// Need to remove the $this reference from the curl handle.
|
||||
// Otherwise Requests_Transport_cURL wont be garbage collected and the curl_close() will never be called.
|
||||
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, null);
|
||||
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, null);
|
||||
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
|
|
@ -133,6 +192,11 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
|
||||
*/
|
||||
public function request_multiple($requests, $options) {
|
||||
// If you're not requesting, we can't get any responses ¯\_(ツ)_/¯
|
||||
if (empty($requests)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$multihandle = curl_multi_init();
|
||||
$subrequests = array();
|
||||
$subhandles = array();
|
||||
|
|
@ -171,9 +235,23 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
// Parse the finished requests before we start getting the new ones
|
||||
foreach ($to_process as $key => $done) {
|
||||
$options = $requests[$key]['options'];
|
||||
$responses[$key] = $subrequests[$key]->process_response(curl_multi_getcontent($done['handle']), $options);
|
||||
if (CURLE_OK !== $done['result']) {
|
||||
//get error string for handle.
|
||||
$reason = curl_error($done['handle']);
|
||||
$exception = new Requests_Exception_Transport_cURL(
|
||||
$reason,
|
||||
Requests_Exception_Transport_cURL::EASY,
|
||||
$done['handle'],
|
||||
$done['result']
|
||||
);
|
||||
$responses[$key] = $exception;
|
||||
$options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key]));
|
||||
}
|
||||
else {
|
||||
$responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options);
|
||||
|
||||
$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
|
||||
$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
|
||||
}
|
||||
|
||||
curl_multi_remove_handle($multihandle, $done['handle']);
|
||||
curl_close($done['handle']);
|
||||
|
|
@ -207,10 +285,17 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
|
||||
if ($options['filename'] !== false) {
|
||||
$this->stream_handle = fopen($options['filename'], 'wb');
|
||||
curl_setopt($this->fp, CURLOPT_FILE, $this->stream_handle);
|
||||
}
|
||||
|
||||
return $this->fp;
|
||||
$this->response_data = '';
|
||||
$this->response_bytes = 0;
|
||||
$this->response_byte_limit = false;
|
||||
if ($options['max_bytes'] !== false) {
|
||||
$this->response_byte_limit = $options['max_bytes'];
|
||||
}
|
||||
$this->hooks = $options['hooks'];
|
||||
|
||||
return $this->handle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,46 +307,98 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @param array $options Request options, see {@see Requests::response()} for documentation
|
||||
*/
|
||||
protected function setup_handle($url, $headers, $data, $options) {
|
||||
$options['hooks']->dispatch('curl.before_request', array(&$this->fp));
|
||||
$options['hooks']->dispatch('curl.before_request', array(&$this->handle));
|
||||
|
||||
// Force closing the connection for old versions of cURL (<7.22).
|
||||
if ( ! isset( $headers['Connection'] ) ) {
|
||||
$headers['Connection'] = 'close';
|
||||
}
|
||||
|
||||
$headers = Requests::flatten($headers);
|
||||
if (in_array($options['type'], array(Requests::HEAD, Requests::GET, Requests::DELETE)) & !empty($data)) {
|
||||
$url = self::format_get($url, $data);
|
||||
}
|
||||
elseif (!empty($data) && !is_string($data)) {
|
||||
$data = http_build_query($data, null, '&');
|
||||
|
||||
if (!empty($data)) {
|
||||
$data_format = $options['data_format'];
|
||||
|
||||
if ($data_format === 'query') {
|
||||
$url = self::format_get($url, $data);
|
||||
$data = '';
|
||||
}
|
||||
elseif (!is_string($data)) {
|
||||
$data = http_build_query($data, null, '&');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($options['type']) {
|
||||
case Requests::POST:
|
||||
curl_setopt($this->fp, CURLOPT_POST, true);
|
||||
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($this->handle, CURLOPT_POST, true);
|
||||
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
|
||||
break;
|
||||
case Requests::HEAD:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
curl_setopt($this->handle, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case Requests::TRACE:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
break;
|
||||
case Requests::PATCH:
|
||||
case Requests::PUT:
|
||||
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
|
||||
break;
|
||||
case Requests::DELETE:
|
||||
curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
break;
|
||||
case Requests::HEAD:
|
||||
curl_setopt($this->fp, CURLOPT_NOBODY, true);
|
||||
break;
|
||||
case Requests::OPTIONS:
|
||||
default:
|
||||
curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
|
||||
if (!empty($data)) {
|
||||
curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
}
|
||||
|
||||
curl_setopt($this->fp, CURLOPT_URL, $url);
|
||||
curl_setopt($this->fp, CURLOPT_TIMEOUT, $options['timeout']);
|
||||
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT, $options['timeout']);
|
||||
curl_setopt($this->fp, CURLOPT_REFERER, $url);
|
||||
curl_setopt($this->fp, CURLOPT_USERAGENT, $options['useragent']);
|
||||
curl_setopt($this->fp, CURLOPT_HTTPHEADER, $headers);
|
||||
// cURL requires a minimum timeout of 1 second when using the system
|
||||
// DNS resolver, as it uses `alarm()`, which is second resolution only.
|
||||
// There's no way to detect which DNS resolver is being used from our
|
||||
// end, so we need to round up regardless of the supplied timeout.
|
||||
//
|
||||
// https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
|
||||
$timeout = max($options['timeout'], 1);
|
||||
|
||||
if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
|
||||
curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
|
||||
}
|
||||
|
||||
if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
|
||||
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
|
||||
}
|
||||
curl_setopt($this->handle, CURLOPT_URL, $url);
|
||||
curl_setopt($this->handle, CURLOPT_REFERER, $url);
|
||||
curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
|
||||
if (!empty($headers)) {
|
||||
curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
if ($options['protocol_version'] === 1.1) {
|
||||
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
}
|
||||
|
||||
if (true === $options['blocking']) {
|
||||
curl_setopt($this->fp, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
|
||||
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
|
||||
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
|
||||
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a response
|
||||
*
|
||||
* @param string $response Response data from the body
|
||||
* @param array $options Request options
|
||||
* @return string HTTP response data including headers
|
||||
*/
|
||||
public function process_response($response, $options) {
|
||||
if ($options['blocking'] === false) {
|
||||
$fake_headers = '';
|
||||
|
|
@ -276,13 +413,17 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
$this->headers .= $response;
|
||||
}
|
||||
|
||||
if (curl_errno($this->fp)) {
|
||||
throw new Requests_Exception('cURL error ' . curl_errno($this->fp) . ': ' . curl_error($this->fp), 'curlerror', $this->fp);
|
||||
return;
|
||||
if (curl_errno($this->handle)) {
|
||||
$error = sprintf(
|
||||
'cURL error %s: %s',
|
||||
curl_errno($this->handle),
|
||||
curl_error($this->handle)
|
||||
);
|
||||
throw new Requests_Exception($error, 'curlerror', $this->handle);
|
||||
}
|
||||
$this->info = curl_getinfo($this->fp);
|
||||
$this->info = curl_getinfo($this->handle);
|
||||
|
||||
$options['hooks']->dispatch('curl.after_request', array(&$this->headers));
|
||||
$options['hooks']->dispatch('curl.after_request', array(&$this->headers, &$this->info));
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +434,7 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @param string $headers Header string
|
||||
* @return integer Length of provided header
|
||||
*/
|
||||
protected function stream_headers($handle, $headers) {
|
||||
public function stream_headers($handle, $headers) {
|
||||
// Why do we do this? cURL will send both the final response and any
|
||||
// interim responses, such as a 100 Continue. We don't need that.
|
||||
// (We may want to keep this somewhere just in case)
|
||||
|
|
@ -309,11 +450,49 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
return strlen($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data as it's received
|
||||
*
|
||||
* @since 1.6.1
|
||||
*
|
||||
* @param resource $handle cURL resource
|
||||
* @param string $data Body data
|
||||
* @return integer Length of provided data
|
||||
*/
|
||||
public function stream_body($handle, $data) {
|
||||
$this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit));
|
||||
$data_length = strlen($data);
|
||||
|
||||
// Are we limiting the response size?
|
||||
if ($this->response_byte_limit) {
|
||||
if ($this->response_bytes === $this->response_byte_limit) {
|
||||
// Already at maximum, move on
|
||||
return $data_length;
|
||||
}
|
||||
|
||||
if (($this->response_bytes + $data_length) > $this->response_byte_limit) {
|
||||
// Limit the length
|
||||
$limited_length = ($this->response_byte_limit - $this->response_bytes);
|
||||
$data = substr($data, 0, $limited_length);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->stream_handle) {
|
||||
fwrite($this->stream_handle, $data);
|
||||
}
|
||||
else {
|
||||
$this->response_data .= $data;
|
||||
}
|
||||
|
||||
$this->response_bytes += strlen($data);
|
||||
return $data_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a URL given GET data
|
||||
*
|
||||
* @param string $url
|
||||
* @param array|object $data Data to build query using, see {@see http://php.net/http_build_query}
|
||||
* @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
|
||||
* @return string URL with data
|
||||
*/
|
||||
protected static function format_get($url, $data) {
|
||||
|
|
@ -345,7 +524,19 @@ class Requests_Transport_cURL implements Requests_Transport {
|
|||
* @codeCoverageIgnore
|
||||
* @return boolean True if the transport is valid, false otherwise.
|
||||
*/
|
||||
public static function test() {
|
||||
return (function_exists('curl_init') && function_exists('curl_exec'));
|
||||
public static function test($capabilities = array()) {
|
||||
if (!function_exists('curl_init') || !function_exists('curl_exec')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If needed, check that our installed curl version supports SSL
|
||||
if (isset($capabilities['ssl']) && $capabilities['ssl']) {
|
||||
$curl_version = curl_version();
|
||||
if (!(CURL_VERSION_SSL & $curl_version['features'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
vendor/rmccue/requests/library/Requests/Transport/cacert.pem
vendored
Executable file → Normal file
0
vendor/rmccue/requests/library/Requests/Transport/cacert.pem
vendored
Executable file → Normal file
248
vendor/rmccue/requests/library/Requests/Transport/fsockopen.php
vendored
Executable file → Normal file
248
vendor/rmccue/requests/library/Requests/Transport/fsockopen.php
vendored
Executable file → Normal file
|
|
@ -13,6 +13,13 @@
|
|||
* @subpackage Transport
|
||||
*/
|
||||
class Requests_Transport_fsockopen implements Requests_Transport {
|
||||
/**
|
||||
* Second to microsecond conversion
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const SECOND_IN_MICROSECONDS = 1000000;
|
||||
|
||||
/**
|
||||
* Raw HTTP data
|
||||
*
|
||||
|
|
@ -23,10 +30,17 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
/**
|
||||
* Stream metadata
|
||||
*
|
||||
* @var array Associative array of properties, see {@see http://php.net/stream_get_meta_data}
|
||||
* @var array Associative array of properties, see {@see https://secure.php.net/stream_get_meta_data}
|
||||
*/
|
||||
public $info;
|
||||
|
||||
/**
|
||||
* What's the maximum number of bytes we should keep?
|
||||
*
|
||||
* @var int|bool Byte count, or false if no limit.
|
||||
*/
|
||||
protected $max_bytes = false;
|
||||
|
||||
protected $connect_error = '';
|
||||
|
||||
/**
|
||||
|
|
@ -45,14 +59,20 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
$options['hooks']->dispatch('fsockopen.before_request');
|
||||
|
||||
$url_parts = parse_url($url);
|
||||
if (empty($url_parts)) {
|
||||
throw new Requests_Exception('Invalid URL.', 'invalidurl', $url);
|
||||
}
|
||||
$host = $url_parts['host'];
|
||||
$context = stream_context_create();
|
||||
$verifyname = false;
|
||||
$case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers);
|
||||
|
||||
// HTTPS support
|
||||
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
|
||||
$remote_socket = 'ssl://' . $host;
|
||||
$url_parts['port'] = 443;
|
||||
if (!isset($url_parts['port'])) {
|
||||
$url_parts['port'] = 443;
|
||||
}
|
||||
|
||||
$context_options = array(
|
||||
'verify_peer' => true,
|
||||
|
|
@ -72,12 +92,14 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
if (isset($options['verify'])) {
|
||||
if ($options['verify'] === false) {
|
||||
$context_options['verify_peer'] = false;
|
||||
} elseif (is_string($options['verify'])) {
|
||||
}
|
||||
elseif (is_string($options['verify'])) {
|
||||
$context_options['cafile'] = $options['verify'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['verifyname']) && $options['verifyname'] === false) {
|
||||
$context_options['verify_peer_name'] = false;
|
||||
$verifyname = false;
|
||||
}
|
||||
|
||||
|
|
@ -87,8 +109,7 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
$remote_socket = 'tcp://' . $host;
|
||||
}
|
||||
|
||||
$proxy = isset( $options['proxy'] );
|
||||
$proxy_auth = $proxy && isset( $options['proxy_username'] ) && isset( $options['proxy_password'] );
|
||||
$this->max_bytes = $options['max_bytes'];
|
||||
|
||||
if (!isset($url_parts['port'])) {
|
||||
$url_parts['port'] = 80;
|
||||
|
|
@ -99,78 +120,73 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
|
||||
$options['hooks']->dispatch('fsockopen.remote_socket', array(&$remote_socket));
|
||||
|
||||
$fp = stream_socket_client($remote_socket, $errno, $errstr, $options['timeout'], STREAM_CLIENT_CONNECT, $context);
|
||||
$socket = stream_socket_client($remote_socket, $errno, $errstr, ceil($options['connect_timeout']), STREAM_CLIENT_CONNECT, $context);
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
if ($verifyname) {
|
||||
if (!$this->verify_certificate_from_context($host, $context)) {
|
||||
throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match');
|
||||
}
|
||||
if ($verifyname && !$this->verify_certificate_from_context($host, $context)) {
|
||||
throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match');
|
||||
}
|
||||
|
||||
if (!$fp) {
|
||||
if (!$socket) {
|
||||
if ($errno === 0) {
|
||||
// Connection issue
|
||||
throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error');
|
||||
}
|
||||
|
||||
throw new Requests_Exception($errstr, 'fsockopenerror', null, $errno);
|
||||
}
|
||||
|
||||
$data_format = $options['data_format'];
|
||||
|
||||
if ($data_format === 'query') {
|
||||
$path = self::format_get($url_parts, $data);
|
||||
$data = '';
|
||||
}
|
||||
else {
|
||||
$path = self::format_get($url_parts, array());
|
||||
}
|
||||
|
||||
$options['hooks']->dispatch('fsockopen.remote_host_path', array(&$path, $url));
|
||||
|
||||
$request_body = '';
|
||||
$out = sprintf("%s %s HTTP/%.1f\r\n", $options['type'], $path, $options['protocol_version']);
|
||||
|
||||
if ($options['type'] !== Requests::TRACE) {
|
||||
if (is_array($data)) {
|
||||
$request_body = http_build_query($data, null, '&');
|
||||
}
|
||||
else {
|
||||
throw new Requests_Exception($errstr, 'fsockopenerror');
|
||||
return;
|
||||
$request_body = $data;
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
if (!isset($case_insensitive_headers['Content-Length'])) {
|
||||
$headers['Content-Length'] = strlen($request_body);
|
||||
}
|
||||
|
||||
if (!isset($case_insensitive_headers['Content-Type'])) {
|
||||
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$request_body = '';
|
||||
$out = '';
|
||||
switch ($options['type']) {
|
||||
case Requests::POST:
|
||||
case Requests::PUT:
|
||||
case Requests::PATCH:
|
||||
if (isset($url_parts['path'])) {
|
||||
$path = $url_parts['path'];
|
||||
if (isset($url_parts['query'])) {
|
||||
$path .= '?' . $url_parts['query'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$path = '/';
|
||||
}
|
||||
if (!isset($case_insensitive_headers['Host'])) {
|
||||
$out .= sprintf('Host: %s', $url_parts['host']);
|
||||
|
||||
$options['hooks']->dispatch( 'fsockopen.remote_host_path', array( &$path, $url ) );
|
||||
$out = $options['type'] . " $path HTTP/1.0\r\n";
|
||||
|
||||
if (is_array($data)) {
|
||||
$request_body = http_build_query($data, null, '&');
|
||||
}
|
||||
else {
|
||||
$request_body = $data;
|
||||
}
|
||||
if (empty($headers['Content-Length'])) {
|
||||
$headers['Content-Length'] = strlen($request_body);
|
||||
}
|
||||
if (empty($headers['Content-Type'])) {
|
||||
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
}
|
||||
break;
|
||||
case Requests::HEAD:
|
||||
case Requests::GET:
|
||||
case Requests::DELETE:
|
||||
$path = self::format_get($url_parts, $data);
|
||||
$options['hooks']->dispatch('fsockopen.remote_host_path', array(&$path, $url));
|
||||
$out = $options['type'] . " $path HTTP/1.0\r\n";
|
||||
break;
|
||||
if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 )) {
|
||||
$out .= ':' . $url_parts['port'];
|
||||
}
|
||||
$out .= "\r\n";
|
||||
}
|
||||
$out .= "Host: {$url_parts['host']}";
|
||||
|
||||
if ($url_parts['port'] !== 80) {
|
||||
$out .= ":{$url_parts['port']}";
|
||||
if (!isset($case_insensitive_headers['User-Agent'])) {
|
||||
$out .= sprintf("User-Agent: %s\r\n", $options['useragent']);
|
||||
}
|
||||
$out .= "\r\n";
|
||||
|
||||
$out .= "User-Agent: {$options['useragent']}\r\n";
|
||||
$accept_encoding = $this->accept_encoding();
|
||||
if (!empty($accept_encoding)) {
|
||||
$out .= "Accept-Encoding: $accept_encoding\r\n";
|
||||
if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) {
|
||||
$out .= sprintf("Accept-Encoding: %s\r\n", $accept_encoding);
|
||||
}
|
||||
|
||||
$headers = Requests::flatten($headers);
|
||||
|
|
@ -185,63 +201,93 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
$out .= "\r\n";
|
||||
}
|
||||
|
||||
$out .= "Connection: Close\r\n\r\n" . $request_body;
|
||||
if (!isset($case_insensitive_headers['Connection'])) {
|
||||
$out .= "Connection: Close\r\n";
|
||||
}
|
||||
|
||||
$out .= "\r\n" . $request_body;
|
||||
|
||||
$options['hooks']->dispatch('fsockopen.before_send', array(&$out));
|
||||
|
||||
fwrite($fp, $out);
|
||||
$options['hooks']->dispatch('fsockopen.after_send', array(&$fake_headers));
|
||||
fwrite($socket, $out);
|
||||
$options['hooks']->dispatch('fsockopen.after_send', array($out));
|
||||
|
||||
if (!$options['blocking']) {
|
||||
fclose($fp);
|
||||
fclose($socket);
|
||||
$fake_headers = '';
|
||||
$options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers));
|
||||
return '';
|
||||
}
|
||||
stream_set_timeout($fp, $options['timeout']);
|
||||
|
||||
$this->info = stream_get_meta_data($fp);
|
||||
|
||||
$this->headers = '';
|
||||
$this->info = stream_get_meta_data($fp);
|
||||
if (!$options['filename']) {
|
||||
while (!feof($fp)) {
|
||||
$this->info = stream_get_meta_data($fp);
|
||||
if ($this->info['timed_out']) {
|
||||
throw new Requests_Exception('fsocket timed out', 'timeout');
|
||||
}
|
||||
|
||||
$this->headers .= fread($fp, 1160);
|
||||
}
|
||||
$timeout_sec = (int) floor($options['timeout']);
|
||||
if ($timeout_sec == $options['timeout']) {
|
||||
$timeout_msec = 0;
|
||||
}
|
||||
else {
|
||||
$timeout_msec = self::SECOND_IN_MICROSECONDS * $options['timeout'] % self::SECOND_IN_MICROSECONDS;
|
||||
}
|
||||
stream_set_timeout($socket, $timeout_sec, $timeout_msec);
|
||||
|
||||
$response = $body = $headers = '';
|
||||
$this->info = stream_get_meta_data($socket);
|
||||
$size = 0;
|
||||
$doingbody = false;
|
||||
$download = false;
|
||||
if ($options['filename']) {
|
||||
$download = fopen($options['filename'], 'wb');
|
||||
$doingbody = false;
|
||||
$response = '';
|
||||
while (!feof($fp)) {
|
||||
$this->info = stream_get_meta_data($fp);
|
||||
if ($this->info['timed_out']) {
|
||||
throw new Requests_Exception('fsocket timed out', 'timeout');
|
||||
}
|
||||
|
||||
while (!feof($socket)) {
|
||||
$this->info = stream_get_meta_data($socket);
|
||||
if ($this->info['timed_out']) {
|
||||
throw new Requests_Exception('fsocket timed out', 'timeout');
|
||||
}
|
||||
|
||||
$block = fread($socket, Requests::BUFFER_SIZE);
|
||||
if (!$doingbody) {
|
||||
$response .= $block;
|
||||
if (strpos($response, "\r\n\r\n")) {
|
||||
list($headers, $block) = explode("\r\n\r\n", $response, 2);
|
||||
$doingbody = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Are we in body mode now?
|
||||
if ($doingbody) {
|
||||
$options['hooks']->dispatch('request.progress', array($block, $size, $this->max_bytes));
|
||||
$data_length = strlen($block);
|
||||
if ($this->max_bytes) {
|
||||
// Have we already hit a limit?
|
||||
if ($size === $this->max_bytes) {
|
||||
continue;
|
||||
}
|
||||
if (($size + $data_length) > $this->max_bytes) {
|
||||
// Limit the length
|
||||
$limited_length = ($this->max_bytes - $size);
|
||||
$block = substr($block, 0, $limited_length);
|
||||
}
|
||||
}
|
||||
|
||||
$block = fread($fp, 1160);
|
||||
if ($doingbody) {
|
||||
$size += strlen($block);
|
||||
if ($download) {
|
||||
fwrite($download, $block);
|
||||
}
|
||||
else {
|
||||
$response .= $block;
|
||||
if (strpos($response, "\r\n\r\n")) {
|
||||
list($this->headers, $block) = explode("\r\n\r\n", $response, 2);
|
||||
$doingbody = true;
|
||||
fwrite($download, $block);
|
||||
}
|
||||
$body .= $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->headers = $headers;
|
||||
|
||||
if ($download) {
|
||||
fclose($download);
|
||||
}
|
||||
fclose($fp);
|
||||
else {
|
||||
$this->headers .= "\r\n\r\n" . $body;
|
||||
}
|
||||
fclose($socket);
|
||||
|
||||
$options['hooks']->dispatch('fsockopen.after_request', array(&$this->headers));
|
||||
$options['hooks']->dispatch('fsockopen.after_request', array(&$this->headers, &$this->info));
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
|
|
@ -298,13 +344,14 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
* Format a URL given GET data
|
||||
*
|
||||
* @param array $url_parts
|
||||
* @param array|object $data Data to build query using, see {@see http://php.net/http_build_query}
|
||||
* @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
|
||||
* @return string URL with data
|
||||
*/
|
||||
protected static function format_get($url_parts, $data) {
|
||||
if (!empty($data)) {
|
||||
if (empty($url_parts['query']))
|
||||
if (empty($url_parts['query'])) {
|
||||
$url_parts['query'] = '';
|
||||
}
|
||||
|
||||
$url_parts['query'] .= '&' . http_build_query($data, null, '&');
|
||||
$url_parts['query'] = trim($url_parts['query'], '&');
|
||||
|
|
@ -347,7 +394,7 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
* names, leading things like 'https://www.github.com/' to be invalid.
|
||||
* Instead
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
* @see https://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
*
|
||||
* @throws Requests_Exception On failure to connect via TLS (`fsockopen.ssl.connect_error`)
|
||||
* @throws Requests_Exception On not obtaining a match for the host (`fsockopen.ssl.no_match`)
|
||||
|
|
@ -376,17 +423,20 @@ class Requests_Transport_fsockopen implements Requests_Transport {
|
|||
* @return boolean True if the transport is valid, false otherwise.
|
||||
*/
|
||||
public static function test($capabilities = array()) {
|
||||
if (!function_exists('fsockopen'))
|
||||
if (!function_exists('fsockopen')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If needed, check that streams support SSL
|
||||
if (isset( $capabilities['ssl'] ) && $capabilities['ssl']) {
|
||||
if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse'))
|
||||
if (isset($capabilities['ssl']) && $capabilities['ssl']) {
|
||||
if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156
|
||||
if (defined('HHVM_VERSION'))
|
||||
if (defined('HHVM_VERSION')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,17 @@ class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, Iterato
|
|||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Creates a case insensitive dictionary.
|
||||
*
|
||||
* @param array $data Dictionary/map to convert to case-insensitive
|
||||
*/
|
||||
public function __construct(array $data = array()) {
|
||||
foreach ($data as $key => $value) {
|
||||
$this->offsetSet($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
|
|
@ -39,8 +50,9 @@ class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, Iterato
|
|||
*/
|
||||
public function offsetGet($key) {
|
||||
$key = strtolower($key);
|
||||
if (!isset($this->data[$key]))
|
||||
if (!isset($this->data[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@
|
|||
* @subpackage Utilities
|
||||
*/
|
||||
class Requests_Utility_FilteredIterator extends ArrayIterator {
|
||||
/**
|
||||
* Callback to run as a filter
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* Create a new iterator
|
||||
*
|
||||
|
|
|
|||
0
vendor/rmccue/requests/package.xml.tpl
vendored
Executable file → Normal file
0
vendor/rmccue/requests/package.xml.tpl
vendored
Executable file → Normal file
6
vendor/rmccue/requests/tests/Auth/Basic.php
vendored
Executable file → Normal file
6
vendor/rmccue/requests/tests/Auth/Basic.php
vendored
Executable file → Normal file
|
|
@ -22,7 +22,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
|
|||
'auth' => array('user', 'passwd'),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
|
||||
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body);
|
||||
|
|
@ -43,7 +43,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
|
|||
'auth' => new Requests_Auth_Basic(array('user', 'passwd')),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
|
||||
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body);
|
||||
|
|
@ -65,7 +65,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
|
|||
'transport' => $transport,
|
||||
);
|
||||
$data = 'test';
|
||||
$request = Requests::post('http://httpbin.org/post', array(), $data, $options);
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $options);
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body);
|
||||
|
|
|
|||
29
vendor/rmccue/requests/tests/ChunkedEncoding.php
vendored
Executable file → Normal file
29
vendor/rmccue/requests/tests/ChunkedEncoding.php
vendored
Executable file → Normal file
|
|
@ -15,6 +15,18 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
|
|||
"02\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
|
||||
"abra\ncadabra\nall we got\n"
|
||||
),
|
||||
array(
|
||||
"02;foo=bar;hello=world\r\nab\r\n04;foo=baz\r\nra\nc\r\n06;justfoo\r\nadabra\r\n0c\r\n\nall we got\n",
|
||||
"abra\ncadabra\nall we got\n"
|
||||
),
|
||||
array(
|
||||
"02;foo=\"quoted value\"\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
|
||||
"abra\ncadabra\nall we got\n"
|
||||
),
|
||||
array(
|
||||
"02;foo-bar=baz\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
|
||||
"abra\ncadabra\nall we got\n"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -34,12 +46,24 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals($expected, $response->body);
|
||||
}
|
||||
|
||||
public static function notChunkedProvider() {
|
||||
return array(
|
||||
'invalid chunk size' => array( 'Hello! This is a non-chunked response!' ),
|
||||
'invalid chunk extension' => array( '1BNot chunked\r\nLooks chunked but it is not\r\n' ),
|
||||
'unquoted chunk-ext-val with space' => array( "02;foo=unquoted with space\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
|
||||
'unquoted chunk-ext-val with forbidden character' => array( "02;foo={unquoted}\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
|
||||
'invalid chunk-ext-name' => array( "02;{foo}=bar\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
|
||||
'incomplete quote for chunk-ext-value' => array( "02;foo=\"no end quote\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Response says it's chunked, but actually isn't
|
||||
* @dataProvider notChunkedProvider
|
||||
*/
|
||||
public function testNotActuallyChunked() {
|
||||
public function testNotActuallyChunked($body) {
|
||||
$transport = new MockTransport();
|
||||
$transport->body = 'Hello! This is a non-chunked response!';
|
||||
$transport->body = $body;
|
||||
$transport->chunked = true;
|
||||
|
||||
$options = array(
|
||||
|
|
@ -50,6 +74,7 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals($transport->body, $response->body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Response says it's chunked and starts looking like it is, but turns out
|
||||
* that they're lying to us
|
||||
|
|
|
|||
482
vendor/rmccue/requests/tests/Cookies.php
vendored
Executable file → Normal file
482
vendor/rmccue/requests/tests/Cookies.php
vendored
Executable file → Normal file
|
|
@ -8,8 +8,8 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals('testvalue', $cookie->value);
|
||||
$this->assertEquals('testvalue', (string) $cookie);
|
||||
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForHeader());
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForSetCookie());
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_set_cookie());
|
||||
}
|
||||
|
||||
public function testCookieWithAttributes() {
|
||||
|
|
@ -19,8 +19,8 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
);
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
|
||||
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForHeader());
|
||||
$this->assertEquals('requests-testcookie=testvalue; httponly; path=/', $cookie->formatForSetCookie());
|
||||
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
|
||||
$this->assertEquals('requests-testcookie=testvalue; httponly; path=/', $cookie->format_for_set_cookie());
|
||||
}
|
||||
|
||||
public function testEmptyCookieName() {
|
||||
|
|
@ -79,7 +79,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'follow_redirects' => false,
|
||||
);
|
||||
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
|
||||
$url = httpbin('/cookies/set?requests-testcookie=testvalue');
|
||||
|
||||
$response = Requests::get($url, array(), $options);
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'follow_redirects' => true,
|
||||
);
|
||||
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
|
||||
$url = httpbin('/cookies/set?requests-testcookie=testvalue');
|
||||
|
||||
$response = Requests::get($url, array(), $options);
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'cookies' => $cookies,
|
||||
);
|
||||
$response = Requests::get('http://httpbin.org/cookies/set', array(), $options);
|
||||
$response = Requests::get(httpbin('/cookies/set'), array(), $options);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertInternalType('array', $data);
|
||||
|
|
@ -124,6 +124,23 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSendingCookie
|
||||
*/
|
||||
public function testCookieExpiration() {
|
||||
$options = array(
|
||||
'follow_redirects' => true,
|
||||
);
|
||||
$url = httpbin('/cookies/set/testcookie/testvalue');
|
||||
$url .= '?expiry=1';
|
||||
|
||||
$response = Requests::get($url, array(), $options);
|
||||
$response->throw_for_status();
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertEmpty($data['cookies']);
|
||||
}
|
||||
|
||||
public function testSendingCookieWithJar() {
|
||||
$cookies = new Requests_Cookie_Jar(array(
|
||||
'requests-testcookie1' => 'testvalue1',
|
||||
|
|
@ -171,4 +188,455 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
|
|||
$this->assertArrayHasKey('requests-testcookie', $data);
|
||||
$this->assertEquals('testvalue', $data['requests-testcookie']);
|
||||
}
|
||||
|
||||
public function domainMatchProvider() {
|
||||
return array(
|
||||
array('example.com', 'example.com', true, true),
|
||||
array('example.com', 'www.example.com', false, true),
|
||||
array('example.com', 'example.net', false, false),
|
||||
|
||||
// Leading period
|
||||
array('.example.com', 'example.com', true, true),
|
||||
array('.example.com', 'www.example.com', false, true),
|
||||
array('.example.com', 'example.net', false, false),
|
||||
|
||||
// Prefix, but not subdomain
|
||||
array('example.com', 'notexample.com', false, false),
|
||||
array('example.com', 'notexample.net', false, false),
|
||||
|
||||
// Reject IP address prefixes
|
||||
array('127.0.0.1', '127.0.0.1', true, true),
|
||||
array('127.0.0.1', 'abc.127.0.0.1', false, false),
|
||||
array('127.0.0.1', 'example.com', false, false),
|
||||
|
||||
// Check that we're checking the actual length
|
||||
array('127.com', 'test.127.com', false, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider domainMatchProvider
|
||||
*/
|
||||
public function testDomainExactMatch($original, $check, $matches, $domain_matches) {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['domain'] = $original;
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
|
||||
$this->assertEquals($matches, $cookie->domain_matches($check));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider domainMatchProvider
|
||||
*/
|
||||
public function testDomainMatch($original, $check, $matches, $domain_matches) {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['domain'] = $original;
|
||||
$flags = array(
|
||||
'host-only' => false
|
||||
);
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
|
||||
$this->assertEquals($domain_matches, $cookie->domain_matches($check));
|
||||
}
|
||||
|
||||
public function pathMatchProvider() {
|
||||
return array(
|
||||
array('/', '', true),
|
||||
array('/', '/', true),
|
||||
|
||||
array('/', '/test', true),
|
||||
array('/', '/test/', true),
|
||||
|
||||
array('/test', '/', false),
|
||||
array('/test', '/test', true),
|
||||
array('/test', '/testing', false),
|
||||
array('/test', '/test/', true),
|
||||
array('/test', '/test/ing', true),
|
||||
array('/test', '/test/ing/', true),
|
||||
|
||||
array('/test/', '/test/', true),
|
||||
array('/test/', '/', false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider pathMatchProvider
|
||||
*/
|
||||
public function testPathMatch($original, $check, $matches) {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['path'] = $original;
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
|
||||
$this->assertEquals($matches, $cookie->path_matches($check));
|
||||
}
|
||||
|
||||
public function urlMatchProvider() {
|
||||
return array(
|
||||
// Domain handling
|
||||
array( 'example.com', '/', 'http://example.com/', true, true ),
|
||||
array( 'example.com', '/', 'http://www.example.com/', false, true ),
|
||||
array( 'example.com', '/', 'http://example.net/', false, false ),
|
||||
array( 'example.com', '/', 'http://www.example.net/', false, false ),
|
||||
|
||||
// /test
|
||||
array( 'example.com', '/test', 'http://example.com/', false, false ),
|
||||
array( 'example.com', '/test', 'http://www.example.com/', false, false ),
|
||||
|
||||
array( 'example.com', '/test', 'http://example.com/test', true, true ),
|
||||
array( 'example.com', '/test', 'http://www.example.com/test', false, true ),
|
||||
|
||||
array( 'example.com', '/test', 'http://example.com/testing', false, false ),
|
||||
array( 'example.com', '/test', 'http://www.example.com/testing', false, false ),
|
||||
|
||||
array( 'example.com', '/test', 'http://example.com/test/', true, true ),
|
||||
array( 'example.com', '/test', 'http://www.example.com/test/', false, true ),
|
||||
|
||||
// /test/
|
||||
array( 'example.com', '/test/', 'http://example.com/', false, false ),
|
||||
array( 'example.com', '/test/', 'http://www.example.com/', false, false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDomainExactMatch
|
||||
* @depends testPathMatch
|
||||
* @dataProvider urlMatchProvider
|
||||
*/
|
||||
public function testUrlExactMatch($domain, $path, $check, $matches, $domain_matches) {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['domain'] = $domain;
|
||||
$attributes['path'] = $path;
|
||||
$check = new Requests_IRI($check);
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
|
||||
$this->assertEquals($matches, $cookie->uri_matches($check));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDomainMatch
|
||||
* @depends testPathMatch
|
||||
* @dataProvider urlMatchProvider
|
||||
*/
|
||||
public function testUrlMatch($domain, $path, $check, $matches, $domain_matches) {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['domain'] = $domain;
|
||||
$attributes['path'] = $path;
|
||||
$flags = array(
|
||||
'host-only' => false
|
||||
);
|
||||
$check = new Requests_IRI($check);
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
|
||||
$this->assertEquals($domain_matches, $cookie->uri_matches($check));
|
||||
}
|
||||
|
||||
public function testUrlMatchSecure() {
|
||||
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
|
||||
$attributes['domain'] = 'example.com';
|
||||
$attributes['path'] = '/';
|
||||
$attributes['secure'] = true;
|
||||
$flags = array(
|
||||
'host-only' => false,
|
||||
);
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
|
||||
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('https://example.com/')));
|
||||
$this->assertFalse($cookie->uri_matches(new Requests_IRI('http://example.com/')));
|
||||
|
||||
// Double-check host-only
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('https://www.example.com/')));
|
||||
$this->assertFalse($cookie->uri_matches(new Requests_IRI('http://www.example.com/')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually set cookies without a domain/path set should always be valid
|
||||
*
|
||||
* Cookies parsed from headers internally in Requests will always have a
|
||||
* domain/path set, but those created manually will not. Manual cookies
|
||||
* should be regarded as "global" cookies (that is, set for `.`)
|
||||
*/
|
||||
public function testUrlMatchManuallySet() {
|
||||
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue');
|
||||
$this->assertTrue($cookie->domain_matches('example.com'));
|
||||
$this->assertTrue($cookie->domain_matches('example.net'));
|
||||
$this->assertTrue($cookie->path_matches('/'));
|
||||
$this->assertTrue($cookie->path_matches('/test'));
|
||||
$this->assertTrue($cookie->path_matches('/test/'));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/')));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/test')));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/test/')));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/')));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/test')));
|
||||
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/test/')));
|
||||
}
|
||||
|
||||
public static function parseResultProvider() {
|
||||
return array(
|
||||
// Basic parsing
|
||||
array(
|
||||
'foo=bar',
|
||||
array( 'name' => 'foo', 'value' => 'bar' ),
|
||||
),
|
||||
array(
|
||||
'bar',
|
||||
array( 'name' => '', 'value' => 'bar' ),
|
||||
),
|
||||
|
||||
// Expiration
|
||||
// RFC 822, updated by RFC 1123
|
||||
array(
|
||||
'foo=bar; Expires=Thu, 5-Dec-2013 04:50:12 GMT',
|
||||
array( 'expired' => true ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Expires=Fri, 5-Dec-2014 04:50:12 GMT',
|
||||
array( 'expired' => false ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
|
||||
),
|
||||
// RFC 850, obsoleted by RFC 1036
|
||||
array(
|
||||
'foo=bar; Expires=Thursday, 5-Dec-2013 04:50:12 GMT',
|
||||
array( 'expired' => true ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Expires=Friday, 5-Dec-2014 04:50:12 GMT',
|
||||
array( 'expired' => false ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
|
||||
),
|
||||
// asctime()
|
||||
array(
|
||||
'foo=bar; Expires=Thu Dec 5 04:50:12 2013',
|
||||
array( 'expired' => true ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Expires=Fri Dec 5 04:50:12 2014',
|
||||
array( 'expired' => false ),
|
||||
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
|
||||
),
|
||||
array(
|
||||
// Invalid
|
||||
'foo=bar; Expires=never',
|
||||
array(),
|
||||
array( 'expires' => null ),
|
||||
),
|
||||
|
||||
// Max-Age
|
||||
array(
|
||||
'foo=bar; Max-Age=10',
|
||||
array( 'expired' => false ),
|
||||
array( 'max-age' => gmmktime( 0, 0, 10, 1, 1, 2014 ) ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Max-Age=3660',
|
||||
array( 'expired' => false ),
|
||||
array( 'max-age' => gmmktime( 1, 1, 0, 1, 1, 2014 ) ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Max-Age=0',
|
||||
array( 'expired' => true ),
|
||||
array( 'max-age' => 0 ),
|
||||
),
|
||||
array(
|
||||
'foo=bar; Max-Age=-1000',
|
||||
array( 'expired' => true ),
|
||||
array( 'max-age' => 0 ),
|
||||
),
|
||||
array(
|
||||
// Invalid (non-digit character)
|
||||
'foo=bar; Max-Age=1e6',
|
||||
array( 'expired' => false ),
|
||||
array( 'max-age' => null ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags = array()) {
|
||||
if (isset($expected['name'])) {
|
||||
$this->assertEquals($expected['name'], $cookie->name);
|
||||
}
|
||||
if (isset($expected['value'])) {
|
||||
$this->assertEquals($expected['value'], $cookie->value);
|
||||
}
|
||||
if (isset($expected['expired'])) {
|
||||
$this->assertEquals($expected['expired'], $cookie->is_expired());
|
||||
}
|
||||
if (isset($expected_attributes)) {
|
||||
foreach ($expected_attributes as $attr_key => $attr_val) {
|
||||
$this->assertEquals($attr_val, $cookie->attributes[$attr_key], "$attr_key should match supplied");
|
||||
}
|
||||
}
|
||||
if (isset($expected_flags)) {
|
||||
foreach ($expected_flags as $flag_key => $flag_val) {
|
||||
$this->assertEquals($flag_val, $cookie->flags[$flag_key], "$flag_key should match supplied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider parseResultProvider
|
||||
*/
|
||||
public function testParsingHeader($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
|
||||
// Set the reference time to 2014-01-01 00:00:00
|
||||
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
|
||||
|
||||
$cookie = Requests_Cookie::parse($header, null, $reference_time);
|
||||
$this->check_parsed_cookie($cookie, $expected, $expected_attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Double-normalizes the cookie data to ensure we catch any issues there
|
||||
*
|
||||
* @dataProvider parseResultProvider
|
||||
*/
|
||||
public function testParsingHeaderDouble($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
|
||||
// Set the reference time to 2014-01-01 00:00:00
|
||||
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
|
||||
|
||||
$cookie = Requests_Cookie::parse($header, null, $reference_time);
|
||||
|
||||
// Normalize the value again
|
||||
$cookie->normalize();
|
||||
|
||||
$this->check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider parseResultProvider
|
||||
*/
|
||||
public function testParsingHeaderObject($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
|
||||
$headers = new Requests_Response_Headers();
|
||||
$headers['Set-Cookie'] = $header;
|
||||
|
||||
// Set the reference time to 2014-01-01 00:00:00
|
||||
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
|
||||
|
||||
$parsed = Requests_Cookie::parse_from_headers($headers, null, $reference_time);
|
||||
$this->assertCount(1, $parsed);
|
||||
|
||||
$cookie = reset($parsed);
|
||||
$this->check_parsed_cookie($cookie, $expected, $expected_attributes);
|
||||
}
|
||||
|
||||
public function parseFromHeadersProvider() {
|
||||
return array(
|
||||
# Varying origin path
|
||||
array(
|
||||
'name=value',
|
||||
'http://example.com/',
|
||||
array(),
|
||||
array( 'path' => '/' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value',
|
||||
'http://example.com/test',
|
||||
array(),
|
||||
array( 'path' => '/' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value',
|
||||
'http://example.com/test/',
|
||||
array(),
|
||||
array( 'path' => '/test' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value',
|
||||
'http://example.com/test/abc',
|
||||
array(),
|
||||
array( 'path' => '/test' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value',
|
||||
'http://example.com/test/abc/',
|
||||
array(),
|
||||
array( 'path' => '/test/abc' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
|
||||
# With specified path
|
||||
array(
|
||||
'name=value; path=/',
|
||||
'http://example.com/',
|
||||
array(),
|
||||
array( 'path' => '/' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value; path=/test',
|
||||
'http://example.com/',
|
||||
array(),
|
||||
array( 'path' => '/test' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value; path=/test/',
|
||||
'http://example.com/',
|
||||
array(),
|
||||
array( 'path' => '/test/' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
|
||||
# Invalid path
|
||||
array(
|
||||
'name=value; path=yolo',
|
||||
'http://example.com/',
|
||||
array(),
|
||||
array( 'path' => '/' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
array(
|
||||
'name=value; path=yolo',
|
||||
'http://example.com/test/',
|
||||
array(),
|
||||
array( 'path' => '/test' ),
|
||||
array( 'host-only' => true ),
|
||||
),
|
||||
|
||||
# Cross-origin cookies, reject!
|
||||
array(
|
||||
'name=value; domain=example.org',
|
||||
'http://example.com/',
|
||||
array( 'invalid' => false ),
|
||||
),
|
||||
|
||||
# Subdomain cookies
|
||||
array(
|
||||
'name=value; domain=test.example.com',
|
||||
'http://test.example.com/',
|
||||
array(),
|
||||
array( 'domain' => 'test.example.com' ),
|
||||
array( 'host-only' => false )
|
||||
),
|
||||
array(
|
||||
'name=value; domain=example.com',
|
||||
'http://test.example.com/',
|
||||
array(),
|
||||
array( 'domain' => 'example.com' ),
|
||||
array( 'host-only' => false )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider parseFromHeadersProvider
|
||||
*/
|
||||
public function testParsingHeaderWithOrigin($header, $origin, $expected, $expected_attributes = array(), $expected_flags = array()) {
|
||||
$origin = new Requests_IRI($origin);
|
||||
$headers = new Requests_Response_Headers();
|
||||
$headers['Set-Cookie'] = $header;
|
||||
|
||||
// Set the reference time to 2014-01-01 00:00:00
|
||||
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
|
||||
|
||||
$parsed = Requests_Cookie::parse_from_headers($headers, $origin, $reference_time);
|
||||
if (isset($expected['invalid'])) {
|
||||
$this->assertCount(0, $parsed);
|
||||
return;
|
||||
}
|
||||
$this->assertCount(1, $parsed);
|
||||
|
||||
$cookie = reset($parsed);
|
||||
$this->check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags);
|
||||
}
|
||||
}
|
||||
0
vendor/rmccue/requests/tests/IDNAEncoder.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/IDNAEncoder.php
vendored
Executable file → Normal file
87
vendor/rmccue/requests/tests/IRI.php
vendored
Executable file → Normal file
87
vendor/rmccue/requests/tests/IRI.php
vendored
Executable file → Normal file
|
|
@ -51,7 +51,7 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array('./g', 'http://a/b/c/g'),
|
||||
array('g/', 'http://a/b/c/g/'),
|
||||
array('/g', 'http://a/g'),
|
||||
array('//g', 'http://g'),
|
||||
array('//g', 'http://g/'),
|
||||
array('?y', 'http://a/b/c/d;p?y'),
|
||||
array('g?y', 'http://a/b/c/g?y'),
|
||||
array('#s', 'http://a/b/c/d;p?q#s'),
|
||||
|
|
@ -66,8 +66,8 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array('..', 'http://a/b/'),
|
||||
array('../', 'http://a/b/'),
|
||||
array('../g', 'http://a/b/g'),
|
||||
array('../..', 'http://a'),
|
||||
array('../../', 'http://a'),
|
||||
array('../..', 'http://a/'),
|
||||
array('../../', 'http://a/'),
|
||||
array('../../g', 'http://a/g'),
|
||||
// Abnormal
|
||||
array('../../../g', 'http://a/g'),
|
||||
|
|
@ -132,14 +132,14 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array('http://a/b', 'c', 'http://a/c'),
|
||||
array('http://a/b/', "c\x0Ad", 'http://a/b/c%0Ad'),
|
||||
array('http://a/b/', "c\x0A\x0B", 'http://a/b/c%0A%0B'),
|
||||
array('http://a/b/c', '//0', 'http://0'),
|
||||
array('http://a/b/c', '//0', 'http://0/'),
|
||||
array('http://a/b/c', '0', 'http://a/b/0'),
|
||||
array('http://a/b/c', '?0', 'http://a/b/c?0'),
|
||||
array('http://a/b/c', '#0', 'http://a/b/c#0'),
|
||||
array('http://0/b/c', 'd', 'http://0/b/d'),
|
||||
array('http://a/b/c?0', 'd', 'http://a/b/d'),
|
||||
array('http://a/b/c#0', 'd', 'http://a/b/d'),
|
||||
array('http://example.com', '//example.net', 'http://example.net'),
|
||||
array('http://example.com', '//example.net', 'http://example.net/'),
|
||||
array('http:g', 'a', 'http:a'),
|
||||
);
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
return array(
|
||||
array('http://example.com/', 'foo/111:bar', 'http://example.com/foo/111:bar'),
|
||||
array('http://example.com/#foo', '', 'http://example.com'),
|
||||
array('http://example.com/#foo', '', 'http://example.com/'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -201,38 +201,38 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array('example://A/', 'example://a/'),
|
||||
array('example://a/', 'example://a/'),
|
||||
array('example://%25A/', 'example://%25a/'),
|
||||
array('HTTP://EXAMPLE.com/', 'http://example.com'),
|
||||
array('http://example.com/', 'http://example.com'),
|
||||
array('http://example.com:', 'http://example.com'),
|
||||
array('http://example.com:80', 'http://example.com'),
|
||||
array('http://@example.com', 'http://@example.com'),
|
||||
array('http://', 'http://'),
|
||||
array('http://example.com?', 'http://example.com?'),
|
||||
array('http://example.com#', 'http://example.com#'),
|
||||
array('https://example.com/', 'https://example.com'),
|
||||
array('https://example.com:', 'https://example.com'),
|
||||
array('https://@example.com', 'https://@example.com'),
|
||||
array('https://example.com?', 'https://example.com?'),
|
||||
array('https://example.com#', 'https://example.com#'),
|
||||
array('HTTP://EXAMPLE.com/', 'http://example.com/'),
|
||||
array('http://example.com/', 'http://example.com/'),
|
||||
array('http://example.com:', 'http://example.com/'),
|
||||
array('http://example.com:80', 'http://example.com/'),
|
||||
array('http://@example.com', 'http://@example.com/'),
|
||||
array('http://', 'http:///'),
|
||||
array('http://example.com?', 'http://example.com/?'),
|
||||
array('http://example.com#', 'http://example.com/#'),
|
||||
array('https://example.com/', 'https://example.com/'),
|
||||
array('https://example.com:', 'https://example.com/'),
|
||||
array('https://@example.com', 'https://@example.com/'),
|
||||
array('https://example.com?', 'https://example.com/?'),
|
||||
array('https://example.com#', 'https://example.com/#'),
|
||||
array('file://localhost/foobar', 'file:/foobar'),
|
||||
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]'),
|
||||
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]'),
|
||||
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]'),
|
||||
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]'),
|
||||
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]'),
|
||||
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]/'),
|
||||
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]/'),
|
||||
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]/'),
|
||||
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]/'),
|
||||
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]/'),
|
||||
array('http://[invalid]', 'http:'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]/'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]/'),
|
||||
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234/'),
|
||||
// Punycode decoding helps with normalisation of IRIs, but is not
|
||||
// needed for URIs, so we don't really care about it for Requests
|
||||
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv'),
|
||||
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv'),
|
||||
array('http://Aa@example.com', 'http://Aa@example.com'),
|
||||
array('http://example.com?Aa', 'http://example.com?Aa'),
|
||||
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv/'),
|
||||
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv/'),
|
||||
array('http://Aa@example.com', 'http://Aa@example.com/'),
|
||||
array('http://example.com?Aa', 'http://example.com/?Aa'),
|
||||
array('http://example.com/Aa', 'http://example.com/Aa'),
|
||||
array('http://example.com#Aa', 'http://example.com#Aa'),
|
||||
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]'),
|
||||
array('http://example.com#Aa', 'http://example.com/#Aa'),
|
||||
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]/'),
|
||||
array('http:.', 'http:'),
|
||||
array('http:..', 'http:'),
|
||||
array('http:./', 'http:'),
|
||||
|
|
@ -249,15 +249,15 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array("http://example.com/\xF3\xB0\x80\x80", 'http://example.com/%F3%B0%80%80'),
|
||||
array("http://example.com/\xF3\xB0\x80\x80%00", 'http://example.com/%F3%B0%80%80%00'),
|
||||
array("http://example.com/\xF3\xB0\x80\x80a", 'http://example.com/%F3%B0%80%80a'),
|
||||
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com?\xF3\xB0\x80\x80"),
|
||||
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com?\xF3\xB0\x80\x80%00"),
|
||||
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com?\xF3\xB0\x80\x80a"),
|
||||
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com/?\xF3\xB0\x80\x80"),
|
||||
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com/?\xF3\xB0\x80\x80%00"),
|
||||
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com/?\xF3\xB0\x80\x80a"),
|
||||
array("http://example.com/\xEE\x80\x80", 'http://example.com/%EE%80%80'),
|
||||
array("http://example.com/\xEE\x80\x80%00", 'http://example.com/%EE%80%80%00'),
|
||||
array("http://example.com/\xEE\x80\x80a", 'http://example.com/%EE%80%80a'),
|
||||
array("http://example.com?\xEE\x80\x80", "http://example.com?\xEE\x80\x80"),
|
||||
array("http://example.com?\xEE\x80\x80%00", "http://example.com?\xEE\x80\x80%00"),
|
||||
array("http://example.com?\xEE\x80\x80a", "http://example.com?\xEE\x80\x80a"),
|
||||
array("http://example.com?\xEE\x80\x80", "http://example.com/?\xEE\x80\x80"),
|
||||
array("http://example.com?\xEE\x80\x80%00", "http://example.com/?\xEE\x80\x80%00"),
|
||||
array("http://example.com?\xEE\x80\x80a", "http://example.com/?\xEE\x80\x80a"),
|
||||
array("http://example.com/\xC2", 'http://example.com/%C2'),
|
||||
array("http://example.com/\xC2a", 'http://example.com/%C2a'),
|
||||
array("http://example.com/\xC2\x00", 'http://example.com/%C2%00'),
|
||||
|
|
@ -268,8 +268,8 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
array("http://example.com/\xFF%00", 'http://example.com/%FF%00'),
|
||||
array("http://example.com/\xFFa", 'http://example.com/%FFa'),
|
||||
array('http://example.com/%61', 'http://example.com/a'),
|
||||
array('http://example.com?%26', 'http://example.com?%26'),
|
||||
array('http://example.com?%61', 'http://example.com?a'),
|
||||
array('http://example.com?%26', 'http://example.com/?%26'),
|
||||
array('http://example.com?%61', 'http://example.com/?a'),
|
||||
array('///', '///'),
|
||||
);
|
||||
}
|
||||
|
|
@ -333,11 +333,6 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
|
|||
$this->assertFalse(Requests_IRI::absolutize('://not a URL', '../'));
|
||||
}
|
||||
|
||||
public function testInvalidAbsolutizeRelative()
|
||||
{
|
||||
$this->assertFalse(Requests_IRI::absolutize('http://example.com/', 'http://example.com//not a URL'));
|
||||
}
|
||||
|
||||
public function testFullGamut()
|
||||
{
|
||||
$iri = new Requests_IRI();
|
||||
|
|
|
|||
131
vendor/rmccue/requests/tests/Proxy/HTTP.php
vendored
Normal file
131
vendor/rmccue/requests/tests/Proxy/HTTP.php
vendored
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
class RequestsTest_Proxy_HTTP extends PHPUnit_Framework_TestCase {
|
||||
protected function checkProxyAvailable($type = '') {
|
||||
switch ($type) {
|
||||
case 'auth':
|
||||
$has_proxy = defined('REQUESTS_HTTP_PROXY_AUTH') && REQUESTS_HTTP_PROXY_AUTH;
|
||||
break;
|
||||
|
||||
default:
|
||||
$has_proxy = defined('REQUESTS_HTTP_PROXY') && REQUESTS_HTTP_PROXY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$has_proxy) {
|
||||
$this->markTestSkipped('Proxy not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function transportProvider() {
|
||||
return array(
|
||||
array('Requests_Transport_cURL'),
|
||||
array('Requests_Transport_fsockopen'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
*/
|
||||
public function testConnectWithString($transport) {
|
||||
$this->checkProxyAvailable();
|
||||
|
||||
$options = array(
|
||||
'proxy' => REQUESTS_HTTP_PROXY,
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
$this->assertEquals('http', $response->headers['x-requests-proxied']);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
*/
|
||||
public function testConnectWithArray($transport) {
|
||||
$this->checkProxyAvailable();
|
||||
|
||||
$options = array(
|
||||
'proxy' => array(REQUESTS_HTTP_PROXY),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
$this->assertEquals('http', $response->headers['x-requests-proxied']);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
* @expectedException Requests_Exception
|
||||
*/
|
||||
public function testConnectInvalidParameters($transport) {
|
||||
$this->checkProxyAvailable();
|
||||
|
||||
$options = array(
|
||||
'proxy' => array(REQUESTS_HTTP_PROXY, 'testuser', 'password', 'something'),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
*/
|
||||
public function testConnectWithInstance($transport) {
|
||||
$this->checkProxyAvailable();
|
||||
|
||||
$options = array(
|
||||
'proxy' => new Requests_Proxy_HTTP(REQUESTS_HTTP_PROXY),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
$this->assertEquals('http', $response->headers['x-requests-proxied']);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
*/
|
||||
public function testConnectWithAuth($transport) {
|
||||
$this->checkProxyAvailable('auth');
|
||||
|
||||
$options = array(
|
||||
'proxy' => array(
|
||||
REQUESTS_HTTP_PROXY_AUTH,
|
||||
REQUESTS_HTTP_PROXY_AUTH_USER,
|
||||
REQUESTS_HTTP_PROXY_AUTH_PASS
|
||||
),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
$this->assertEquals('http', $response->headers['x-requests-proxied']);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider transportProvider
|
||||
*/
|
||||
public function testConnectWithInvalidAuth($transport) {
|
||||
$this->checkProxyAvailable('auth');
|
||||
|
||||
$options = array(
|
||||
'proxy' => array(
|
||||
REQUESTS_HTTP_PROXY_AUTH,
|
||||
REQUESTS_HTTP_PROXY_AUTH_USER . '!',
|
||||
REQUESTS_HTTP_PROXY_AUTH_PASS . '!'
|
||||
),
|
||||
'transport' => $transport,
|
||||
);
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
$this->assertEquals(407, $response->status_code);
|
||||
}
|
||||
}
|
||||
26
vendor/rmccue/requests/tests/Requests.php
vendored
Executable file → Normal file
26
vendor/rmccue/requests/tests/Requests.php
vendored
Executable file → Normal file
|
|
@ -9,7 +9,7 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
public function testDefaultTransport() {
|
||||
$request = Requests::get('http://httpbin.org/get');
|
||||
$request = Requests::get(httpbin('/get'));
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +51,20 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function testProtocolVersionParsing() {
|
||||
$transport = new RawTransport();
|
||||
$transport->data =
|
||||
"HTTP/1.0 200 OK\r\n".
|
||||
"Host: localhost\r\n\r\n";
|
||||
|
||||
$options = array(
|
||||
'transport' => $transport
|
||||
);
|
||||
|
||||
$response = Requests::get('http://example.com/', array(), $options);
|
||||
$this->assertEquals(1.0, $response->protocol_version);
|
||||
}
|
||||
|
||||
public function testRawAccess() {
|
||||
$transport = new RawTransport();
|
||||
$transport->data =
|
||||
|
|
@ -137,4 +151,12 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals(302, $response->status_code);
|
||||
$this->assertEquals(0, $response->redirects);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Requests_Exception
|
||||
*/
|
||||
public function testTimeoutException() {
|
||||
$options = array('timeout' => 0.5);
|
||||
$response = Requests::get(httpbin('/delay/3'), array(), $options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
vendor/rmccue/requests/tests/Response/Headers.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/Response/Headers.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/SSL.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/SSL.php
vendored
Executable file → Normal file
157
vendor/rmccue/requests/tests/Session.php
vendored
Executable file → Normal file
157
vendor/rmccue/requests/tests/Session.php
vendored
Executable file → Normal file
|
|
@ -1,6 +1,147 @@
|
|||
<?php
|
||||
|
||||
class RequestsTest_Session extends PHPUnit_Framework_TestCase {
|
||||
public function testURLResolution() {
|
||||
$session = new Requests_Session(httpbin('/'));
|
||||
|
||||
// Set the cookies up
|
||||
$response = $session->get('/get');
|
||||
$this->assertTrue($response->success);
|
||||
$this->assertEquals(httpbin('/get'), $response->url);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertNotNull($data);
|
||||
$this->assertArrayHasKey('url', $data);
|
||||
$this->assertEquals(httpbin('/get'), $data['url']);
|
||||
}
|
||||
|
||||
public function testBasicGET() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicGET',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->get('/get', array('X-Requests-Request' => 'GET'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
|
||||
$this->assertEquals('BasicGET', $data['headers']['X-Requests-Session']);
|
||||
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
|
||||
$this->assertEquals('GET', $data['headers']['X-Requests-Request']);
|
||||
}
|
||||
|
||||
public function testBasicHEAD() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicHEAD',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->head('/get', array('X-Requests-Request' => 'HEAD'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
}
|
||||
|
||||
public function testBasicDELETE() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicDELETE',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->delete('/delete', array('X-Requests-Request' => 'DELETE'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
|
||||
$this->assertEquals('BasicDELETE', $data['headers']['X-Requests-Session']);
|
||||
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
|
||||
$this->assertEquals('DELETE', $data['headers']['X-Requests-Request']);
|
||||
}
|
||||
|
||||
public function testBasicPOST() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicPOST',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->post('/post', array('X-Requests-Request' => 'POST'), array('postdata' => 'exists'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
|
||||
$this->assertEquals('BasicPOST', $data['headers']['X-Requests-Session']);
|
||||
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
|
||||
$this->assertEquals('POST', $data['headers']['X-Requests-Request']);
|
||||
}
|
||||
|
||||
public function testBasicPUT() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicPUT',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->put('/put', array('X-Requests-Request' => 'PUT'), array('postdata' => 'exists'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
|
||||
$this->assertEquals('BasicPUT', $data['headers']['X-Requests-Session']);
|
||||
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
|
||||
$this->assertEquals('PUT', $data['headers']['X-Requests-Request']);
|
||||
}
|
||||
|
||||
public function testBasicPATCH() {
|
||||
$session_headers = array(
|
||||
'X-Requests-Session' => 'BasicPATCH',
|
||||
'X-Requests-Request' => 'notset',
|
||||
);
|
||||
$session = new Requests_Session(httpbin('/'), $session_headers);
|
||||
$response = $session->patch('/patch', array('X-Requests-Request' => 'PATCH'), array('postdata' => 'exists'));
|
||||
$response->throw_for_status(false);
|
||||
$this->assertEquals(200, $response->status_code);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
|
||||
$this->assertEquals('BasicPATCH', $data['headers']['X-Requests-Session']);
|
||||
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
|
||||
$this->assertEquals('PATCH', $data['headers']['X-Requests-Request']);
|
||||
}
|
||||
|
||||
public function testMultiple() {
|
||||
$session = new Requests_Session(httpbin('/'), array('X-Requests-Session' => 'Multiple'));
|
||||
$requests = array(
|
||||
'test1' => array(
|
||||
'url' => httpbin('/get')
|
||||
),
|
||||
'test2' => array(
|
||||
'url' => httpbin('/get')
|
||||
),
|
||||
);
|
||||
$responses = $session->request_multiple($requests);
|
||||
|
||||
// test1
|
||||
$this->assertNotEmpty($responses['test1']);
|
||||
$this->assertInstanceOf('Requests_Response', $responses['test1']);
|
||||
$this->assertEquals(200, $responses['test1']->status_code);
|
||||
|
||||
$result = json_decode($responses['test1']->body, true);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
|
||||
// test2
|
||||
$this->assertNotEmpty($responses['test2']);
|
||||
$this->assertInstanceOf('Requests_Response', $responses['test2']);
|
||||
$this->assertEquals(200, $responses['test2']->status_code);
|
||||
|
||||
$result = json_decode($responses['test2']->body, true);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
public function testPropertyUsage() {
|
||||
$headers = array(
|
||||
'X-TestHeader' => 'testing',
|
||||
|
|
@ -46,22 +187,8 @@ class RequestsTest_Session extends PHPUnit_Framework_TestCase {
|
|||
$this->assertNull($session->invalidoption);
|
||||
}
|
||||
|
||||
public function testURLResolution() {
|
||||
$session = new Requests_Session('http://httpbin.org/');
|
||||
|
||||
// Set the cookies up
|
||||
$response = $session->get('/get');
|
||||
$this->assertTrue($response->success);
|
||||
$this->assertEquals('http://httpbin.org/get', $response->url);
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
$this->assertNotNull($data);
|
||||
$this->assertArrayHasKey('url', $data);
|
||||
$this->assertEquals('http://httpbin.org/get', $data['url']);
|
||||
}
|
||||
|
||||
public function testSharedCookies() {
|
||||
$session = new Requests_Session('http://httpbin.org/');
|
||||
$session = new Requests_Session(httpbin('/'));
|
||||
|
||||
$options = array(
|
||||
'follow_redirects' => false
|
||||
|
|
|
|||
315
vendor/rmccue/requests/tests/Transport/Base.php
vendored
Executable file → Normal file
315
vendor/rmccue/requests/tests/Transport/Base.php
vendored
Executable file → Normal file
|
|
@ -25,21 +25,42 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
return $options;
|
||||
}
|
||||
|
||||
public function testResponseByteLimit() {
|
||||
$limit = 104;
|
||||
$options = array(
|
||||
'max_bytes' => $limit,
|
||||
);
|
||||
$response = Requests::get(httpbin('/bytes/325'), array(), $this->getOptions($options));
|
||||
$this->assertEquals($limit, strlen($response->body));
|
||||
}
|
||||
|
||||
public function testResponseByteLimitWithFile() {
|
||||
$limit = 300;
|
||||
$options = array(
|
||||
'max_bytes' => $limit,
|
||||
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
|
||||
);
|
||||
$response = Requests::get(httpbin('/bytes/482'), array(), $this->getOptions($options));
|
||||
$this->assertEmpty($response->body);
|
||||
$this->assertEquals($limit, filesize($options['filename']));
|
||||
unlink($options['filename']);
|
||||
}
|
||||
|
||||
public function testSimpleGET() {
|
||||
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/get'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
public function testGETWithArgs() {
|
||||
$request = Requests::get('http://httpbin.org/get?test=true&test2=test', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/get?test=true&test2=test'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
|
||||
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
|
||||
}
|
||||
|
||||
|
|
@ -48,16 +69,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::request('http://httpbin.org/get', array(), $data, Requests::GET, $this->getOptions());
|
||||
$request = Requests::request(httpbin('/get'), array(), $data, Requests::GET, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
|
||||
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
|
||||
}
|
||||
|
||||
public function testGETWithNestedData() {
|
||||
$this->markTestSkipped('httpbin changed their data format; this test will now fail');
|
||||
$data = array(
|
||||
'test' => 'true',
|
||||
'test2' => array(
|
||||
|
|
@ -65,11 +85,11 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test4' => 'test-too',
|
||||
),
|
||||
);
|
||||
$request = Requests::request('http://httpbin.org/get', array(), $data, Requests::GET, $this->getOptions());
|
||||
$request = Requests::request(httpbin('/get'), array(), $data, Requests::GET, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too', $result['url']);
|
||||
$this->assertEquals(httpbin('/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2[test3]' => 'test', 'test2[test4]' => 'test-too'), $result['args']);
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +97,11 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$data = array(
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::request('http://httpbin.org/get?test=true', array(), $data, Requests::GET, $this->getOptions());
|
||||
$request = Requests::request(httpbin('/get?test=true'), array(), $data, Requests::GET, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
|
||||
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +109,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$headers = array(
|
||||
'Requested-At' => time(),
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/get', $headers, $this->getOptions());
|
||||
$request = Requests::get(httpbin('/get'), $headers, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -97,23 +117,28 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
public function testChunked() {
|
||||
$request = Requests::get('http://httpbin.org/stream/1', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/stream/1'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/stream/1', $result['url']);
|
||||
$this->assertEquals(httpbin('/stream/1'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
public function testHEAD() {
|
||||
$request = Requests::head('http://httpbin.org/get', array(), $this->getOptions());
|
||||
$request = Requests::head(httpbin('/get'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
$this->assertEquals('', $request->body);
|
||||
}
|
||||
|
||||
public function testTRACE() {
|
||||
$request = Requests::trace(httpbin('/trace'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
public function testRawPOST() {
|
||||
$data = 'test';
|
||||
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -122,7 +147,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testFormPost() {
|
||||
$data = 'test=true&test2=test';
|
||||
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -134,7 +159,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -149,7 +174,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test4' => 'test-too',
|
||||
),
|
||||
);
|
||||
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -158,7 +183,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testRawPUT() {
|
||||
$data = 'test';
|
||||
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
|
||||
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -167,7 +192,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testFormPUT() {
|
||||
$data = 'test=true&test2=test';
|
||||
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
|
||||
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -179,7 +204,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
|
||||
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -188,7 +213,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testRawPATCH() {
|
||||
$data = 'test';
|
||||
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
|
||||
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -197,7 +222,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testFormPATCH() {
|
||||
$data = 'test=true&test2=test';
|
||||
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
|
||||
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code, $request->body);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
|
|
@ -209,19 +234,24 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
|
||||
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
|
||||
}
|
||||
|
||||
public function testOPTIONS() {
|
||||
$request = Requests::options(httpbin('/options'), array(), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
public function testDELETE() {
|
||||
$request = Requests::delete('http://httpbin.org/delete', array(), $this->getOptions());
|
||||
$request = Requests::delete(httpbin('/delete'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/delete', $result['url']);
|
||||
$this->assertEquals(httpbin('/delete'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
|
|
@ -230,23 +260,40 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::request('http://httpbin.org/delete', array(), $data, Requests::DELETE, $this->getOptions());
|
||||
$request = Requests::request(httpbin('/delete'), array(), $data, Requests::DELETE, $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/delete?test=true&test2=test', $result['url']);
|
||||
$this->assertEquals(httpbin('/delete?test=true&test2=test'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
|
||||
}
|
||||
|
||||
public function testLOCK() {
|
||||
$request = Requests::request(httpbin('/lock'), array(), array(), 'LOCK', $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
public function testLOCKWithData() {
|
||||
$data = array(
|
||||
'test' => 'true',
|
||||
'test2' => 'test',
|
||||
);
|
||||
$request = Requests::request(httpbin('/lock'), array(), $data, 'LOCK', $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
|
||||
}
|
||||
|
||||
public function testRedirects() {
|
||||
$request = Requests::get('http://httpbin.org/redirect/6', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/redirect/6'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$this->assertEquals(6, $request->redirects);
|
||||
}
|
||||
|
||||
public function testRelativeRedirects() {
|
||||
$request = Requests::get('http://httpbin.org/relative-redirect/6', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/relative-redirect/6'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$this->assertEquals(6, $request->redirects);
|
||||
|
|
@ -260,7 +307,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'redirects' => 10, // default, but force just in case
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/redirect/11', array(), $this->getOptions($options));
|
||||
$request = Requests::get(httpbin('/redirect/11'), array(), $this->getOptions($options));
|
||||
}
|
||||
|
||||
public static function statusCodeSuccessProvider() {
|
||||
|
|
@ -316,11 +363,16 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
* @dataProvider statusCodeSuccessProvider
|
||||
*/
|
||||
public function testStatusCode($code, $success) {
|
||||
$url = sprintf('http://httpbin.org/status/%d', $code);
|
||||
$transport = new MockTransport();
|
||||
$transport->code = $code;
|
||||
|
||||
$url = sprintf(httpbin('/status/%d'), $code);
|
||||
|
||||
$options = array(
|
||||
'follow_redirects' => false,
|
||||
'transport' => $transport,
|
||||
);
|
||||
$request = Requests::get($url, array(), $this->getOptions($options));
|
||||
$request = Requests::get($url, array(), $options);
|
||||
$this->assertEquals($code, $request->status_code);
|
||||
$this->assertEquals($success, $request->success);
|
||||
}
|
||||
|
|
@ -329,20 +381,24 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
* @dataProvider statusCodeSuccessProvider
|
||||
*/
|
||||
public function testStatusCodeThrow($code, $success) {
|
||||
$url = sprintf('http://httpbin.org/status/%d', $code);
|
||||
$transport = new MockTransport();
|
||||
$transport->code = $code;
|
||||
|
||||
$url = sprintf(httpbin('/status/%d'), $code);
|
||||
$options = array(
|
||||
'follow_redirects' => false,
|
||||
'transport' => $transport,
|
||||
);
|
||||
|
||||
if (!$success) {
|
||||
if ($code >= 400) {
|
||||
$this->setExpectedException('Requests_Exception_HTTP_' . $code, $code);
|
||||
$this->setExpectedException('Requests_Exception_HTTP_' . $code, '', $code);
|
||||
}
|
||||
elseif ($code >= 300 && $code < 400) {
|
||||
$this->setExpectedException('Requests_Exception');
|
||||
}
|
||||
}
|
||||
$request = Requests::get($url, array(), $this->getOptions($options));
|
||||
$request = Requests::get($url, array(), $options);
|
||||
$request->throw_for_status(false);
|
||||
}
|
||||
|
||||
|
|
@ -350,22 +406,33 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
* @dataProvider statusCodeSuccessProvider
|
||||
*/
|
||||
public function testStatusCodeThrowAllowRedirects($code, $success) {
|
||||
$url = sprintf('http://httpbin.org/status/%d', $code);
|
||||
$transport = new MockTransport();
|
||||
$transport->code = $code;
|
||||
|
||||
$url = sprintf(httpbin('/status/%d'), $code);
|
||||
$options = array(
|
||||
'follow_redirects' => false,
|
||||
'transport' => $transport,
|
||||
);
|
||||
|
||||
if (!$success) {
|
||||
if ($code >= 400) {
|
||||
$this->setExpectedException('Requests_Exception_HTTP_' . $code, $code);
|
||||
if ($code >= 400 || $code === 304 || $code === 305 || $code === 306) {
|
||||
$this->setExpectedException('Requests_Exception_HTTP_' . $code, '', $code);
|
||||
}
|
||||
}
|
||||
$request = Requests::get($url, array(), $this->getOptions($options));
|
||||
$request = Requests::get($url, array(), $options);
|
||||
$request->throw_for_status(true);
|
||||
}
|
||||
|
||||
public function testStatusCodeUnknown(){
|
||||
$request = Requests::get('http://httpbin.org/status/599', array(), $this->getOptions());
|
||||
$transport = new MockTransport();
|
||||
$transport->code = 599;
|
||||
|
||||
$options = array(
|
||||
'transport' => $transport,
|
||||
);
|
||||
|
||||
$request = Requests::get(httpbin('/status/599'), array(), $options);
|
||||
$this->assertEquals(599, $request->status_code);
|
||||
$this->assertEquals(false, $request->success);
|
||||
}
|
||||
|
|
@ -374,12 +441,19 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
* @expectedException Requests_Exception_HTTP_Unknown
|
||||
*/
|
||||
public function testStatusCodeThrowUnknown(){
|
||||
$request = Requests::get('http://httpbin.org/status/599', array(), $this->getOptions());
|
||||
$transport = new MockTransport();
|
||||
$transport->code = 599;
|
||||
|
||||
$options = array(
|
||||
'transport' => $transport,
|
||||
);
|
||||
|
||||
$request = Requests::get(httpbin('/status/599'), array(), $options);
|
||||
$request->throw_for_status(true);
|
||||
}
|
||||
|
||||
public function testGzipped() {
|
||||
$request = Requests::get('http://httpbin.org/gzip', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/gzip'), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body);
|
||||
|
|
@ -390,13 +464,13 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions($options));
|
||||
$request = Requests::get(httpbin('/get'), array(), $this->getOptions($options));
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
$this->assertEmpty($request->body);
|
||||
|
||||
$contents = file_get_contents($options['filename']);
|
||||
$result = json_decode($contents, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
|
||||
unlink($options['filename']);
|
||||
|
|
@ -406,7 +480,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'blocking' => false
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions($options));
|
||||
$request = Requests::get(httpbin('/get'), array(), $this->getOptions($options));
|
||||
$empty = new Requests_Response();
|
||||
$this->assertEquals($empty, $request);
|
||||
}
|
||||
|
|
@ -424,11 +498,12 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
return;
|
||||
}
|
||||
|
||||
$request = Requests::get('https://httpbin.org/get', array(), $this->getOptions());
|
||||
$request = Requests::get(httpbin('/get', true), array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
// Disable, since httpbin always returns http
|
||||
// $this->assertEquals(httpbin('/get', true), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
|
|
@ -459,10 +534,6 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
/**
|
||||
* Test that SSL fails with a bad certificate
|
||||
*
|
||||
* This is defined as invalid by
|
||||
* https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
|
||||
* and is used in testing in PhantomJS. That said, expect this to break.
|
||||
*
|
||||
* @expectedException Requests_Exception
|
||||
*/
|
||||
public function testBadDomain() {
|
||||
|
|
@ -471,15 +542,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
return;
|
||||
}
|
||||
|
||||
$request = Requests::get('https://tv.eurosport.com/', array(), $this->getOptions());
|
||||
$request = Requests::head('https://wrong.host.badssl.com/', array(), $this->getOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the transport supports Server Name Indication with HTTPS
|
||||
*
|
||||
* sni.velox.ch is used for SNI testing, and the common name is set to
|
||||
* `*.sni.velox.ch` as such. Without alternate name support, this will fail
|
||||
* as `sni.velox.ch` is only in the alternate name
|
||||
* badssl.com is used for SSL testing, and the common name is set to
|
||||
* `*.badssl.com` as such. Without alternate name support, this will fail
|
||||
* as `badssl.com` is only in the alternate name
|
||||
*/
|
||||
public function testAlternateNameSupport() {
|
||||
if ($this->skip_https) {
|
||||
|
|
@ -487,16 +558,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
return;
|
||||
}
|
||||
|
||||
$request = Requests::get('https://sni.velox.ch/', array(), $this->getOptions());
|
||||
$request = Requests::head('https://badssl.com/', array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the transport supports Server Name Indication with HTTPS
|
||||
*
|
||||
* sni.velox.ch is used for SNI testing, and the common name is set to
|
||||
* `*.sni.velox.ch` as such. Without SNI support, this will fail. Also tests
|
||||
* our wildcard support.
|
||||
* feelingrestful.com (owned by hmn.md and used with permission) points to
|
||||
* CloudFlare, and will fail if SNI isn't sent.
|
||||
*/
|
||||
public function testSNISupport() {
|
||||
if ($this->skip_https) {
|
||||
|
|
@ -504,7 +574,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
return;
|
||||
}
|
||||
|
||||
$request = Requests::get('https://abc.sni.velox.ch/', array(), $this->getOptions());
|
||||
$request = Requests::head('https://feelingrestful.com/', array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
}
|
||||
|
||||
|
|
@ -515,17 +585,17 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$options = array(
|
||||
'timeout' => 1,
|
||||
);
|
||||
$request = Requests::get('http://httpbin.org/delay/10', array(), $this->getOptions($options));
|
||||
$request = Requests::get(httpbin('/delay/10'), array(), $this->getOptions($options));
|
||||
var_dump($request);
|
||||
}
|
||||
|
||||
public function testMultiple() {
|
||||
$requests = array(
|
||||
'test1' => array(
|
||||
'url' => 'http://httpbin.org/get'
|
||||
'url' => httpbin('/get')
|
||||
),
|
||||
'test2' => array(
|
||||
'url' => 'http://httpbin.org/get'
|
||||
'url' => httpbin('/get')
|
||||
),
|
||||
);
|
||||
$responses = Requests::request_multiple($requests, $this->getOptions());
|
||||
|
|
@ -536,7 +606,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals(200, $responses['test1']->status_code);
|
||||
|
||||
$result = json_decode($responses['test1']->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
|
||||
// test2
|
||||
|
|
@ -545,17 +615,17 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals(200, $responses['test2']->status_code);
|
||||
|
||||
$result = json_decode($responses['test2']->body, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
}
|
||||
|
||||
public function testMultipleWithDifferingMethods() {
|
||||
$requests = array(
|
||||
'get' => array(
|
||||
'url' => 'http://httpbin.org/get',
|
||||
'url' => httpbin('/get'),
|
||||
),
|
||||
'post' => array(
|
||||
'url' => 'http://httpbin.org/post',
|
||||
'url' => httpbin('/post'),
|
||||
'type' => Requests::POST,
|
||||
'data' => 'test',
|
||||
),
|
||||
|
|
@ -577,10 +647,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
public function testMultipleWithFailure() {
|
||||
$requests = array(
|
||||
'success' => array(
|
||||
'url' => 'http://httpbin.org/get',
|
||||
'url' => httpbin('/get'),
|
||||
),
|
||||
'timeout' => array(
|
||||
'url' => 'http://httpbin.org/delay/10',
|
||||
'url' => httpbin('/delay/10'),
|
||||
'options' => array(
|
||||
'timeout' => 1,
|
||||
),
|
||||
|
|
@ -594,10 +664,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
public function testMultipleUsingCallback() {
|
||||
$requests = array(
|
||||
'get' => array(
|
||||
'url' => 'http://httpbin.org/get',
|
||||
'url' => httpbin('/get'),
|
||||
),
|
||||
'post' => array(
|
||||
'url' => 'http://httpbin.org/post',
|
||||
'url' => httpbin('/post'),
|
||||
'type' => Requests::POST,
|
||||
'data' => 'test',
|
||||
),
|
||||
|
|
@ -615,10 +685,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
public function testMultipleUsingCallbackAndFailure() {
|
||||
$requests = array(
|
||||
'success' => array(
|
||||
'url' => 'http://httpbin.org/get',
|
||||
'url' => httpbin('/get'),
|
||||
),
|
||||
'timeout' => array(
|
||||
'url' => 'http://httpbin.org/delay/10',
|
||||
'url' => httpbin('/delay/10'),
|
||||
'options' => array(
|
||||
'timeout' => 1,
|
||||
),
|
||||
|
|
@ -641,13 +711,13 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
public function testMultipleToFile() {
|
||||
$requests = array(
|
||||
'get' => array(
|
||||
'url' => 'http://httpbin.org/get',
|
||||
'url' => httpbin('/get'),
|
||||
'options' => array(
|
||||
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
|
||||
),
|
||||
),
|
||||
'post' => array(
|
||||
'url' => 'http://httpbin.org/post',
|
||||
'url' => httpbin('/post'),
|
||||
'type' => Requests::POST,
|
||||
'data' => 'test',
|
||||
'options' => array(
|
||||
|
|
@ -660,24 +730,97 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
|
|||
// GET request
|
||||
$contents = file_get_contents($requests['get']['options']['filename']);
|
||||
$result = json_decode($contents, true);
|
||||
$this->assertEquals('http://httpbin.org/get', $result['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result['url']);
|
||||
$this->assertEmpty($result['args']);
|
||||
unlink($requests['get']['options']['filename']);
|
||||
|
||||
// POST request
|
||||
$contents = file_get_contents($requests['post']['options']['filename']);
|
||||
$result = json_decode($contents, true);
|
||||
$this->assertEquals('http://httpbin.org/post', $result['url']);
|
||||
$this->assertEquals(httpbin('/post'), $result['url']);
|
||||
$this->assertEquals('test', $result['data']);
|
||||
unlink($requests['post']['options']['filename']);
|
||||
}
|
||||
|
||||
public function testHostHeader() {
|
||||
$request = Requests::get('http://portquiz.positon.org:8080/', array(), $this->getOptions());
|
||||
$responseDoc = new DOMDocument;
|
||||
$responseDoc->loadHTML($request->body);
|
||||
$portXpath = new DOMXPath($responseDoc);
|
||||
$portXpathMatches = $portXpath->query('//p/b');
|
||||
$this->assertEquals(8080, $portXpathMatches->item(0)->nodeValue);
|
||||
public function testAlternatePort() {
|
||||
$request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions());
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
$num = preg_match('#You have reached this page on port <b>(\d+)</b>#i', $request->body, $matches);
|
||||
$this->assertEquals(1, $num, 'Response should contain the port number');
|
||||
$this->assertEquals(8080, $matches[1]);
|
||||
}
|
||||
|
||||
public function testProgressCallback() {
|
||||
$mock = $this->getMockBuilder('stdClass')->setMethods(array('progress'))->getMock();
|
||||
$mock->expects($this->atLeastOnce())->method('progress');
|
||||
$hooks = new Requests_Hooks();
|
||||
$hooks->register('request.progress', array($mock, 'progress'));
|
||||
$options = array(
|
||||
'hooks' => $hooks,
|
||||
);
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
}
|
||||
|
||||
public function testAfterRequestCallback() {
|
||||
$mock = $this->getMockBuilder('stdClass')
|
||||
->setMethods(array('after_request'))
|
||||
->getMock();
|
||||
|
||||
$mock->expects($this->atLeastOnce())
|
||||
->method('after_request')
|
||||
->with(
|
||||
$this->isType('string'),
|
||||
$this->logicalAnd($this->isType('array'), $this->logicalNot($this->isEmpty()))
|
||||
);
|
||||
$hooks = new Requests_Hooks();
|
||||
$hooks->register('curl.after_request', array($mock, 'after_request'));
|
||||
$hooks->register('fsockopen.after_request', array($mock, 'after_request'));
|
||||
$options = array(
|
||||
'hooks' => $hooks,
|
||||
);
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$response = Requests::get(httpbin('/get'), array(), $options);
|
||||
}
|
||||
|
||||
public function testReusableTransport() {
|
||||
$options = $this->getOptions(array('transport' => new $this->transport()));
|
||||
|
||||
$request1 = Requests::get(httpbin('/get'), array(), $options);
|
||||
$request2 = Requests::get(httpbin('/get'), array(), $options);
|
||||
|
||||
$this->assertEquals(200, $request1->status_code);
|
||||
$this->assertEquals(200, $request2->status_code);
|
||||
|
||||
$result1 = json_decode($request1->body, true);
|
||||
$result2 = json_decode($request2->body, true);
|
||||
|
||||
$this->assertEquals(httpbin('/get'), $result1['url']);
|
||||
$this->assertEquals(httpbin('/get'), $result2['url']);
|
||||
|
||||
$this->assertEmpty($result1['args']);
|
||||
$this->assertEmpty($result2['args']);
|
||||
}
|
||||
|
||||
public function testQueryDataFormat() {
|
||||
$data = array('test' => 'true', 'test2' => 'test');
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions(array('data_format' => 'query')));
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals(httpbin('/post').'?test=true&test2=test', $result['url']);
|
||||
$this->assertEquals('', $result['data']);
|
||||
}
|
||||
|
||||
public function testBodyDataFormat() {
|
||||
$data = array('test' => 'true', 'test2' => 'test');
|
||||
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions(array('data_format' => 'body')));
|
||||
$this->assertEquals(200, $request->status_code);
|
||||
|
||||
$result = json_decode($request->body, true);
|
||||
$this->assertEquals(httpbin('/post'), $result['url']);
|
||||
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
vendor/rmccue/requests/tests/Transport/cURL.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/Transport/cURL.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/Transport/fsockopen.php
vendored
Executable file → Normal file
0
vendor/rmccue/requests/tests/Transport/fsockopen.php
vendored
Executable file → Normal file
33
vendor/rmccue/requests/tests/bootstrap.php
vendored
Executable file → Normal file
33
vendor/rmccue/requests/tests/bootstrap.php
vendored
Executable file → Normal file
|
|
@ -1,5 +1,26 @@
|
|||
<?php
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
function define_from_env($name, $default = false) {
|
||||
$env = getenv($name);
|
||||
if ($env) {
|
||||
define($name, $env);
|
||||
}
|
||||
else {
|
||||
define($name, $default);
|
||||
}
|
||||
}
|
||||
|
||||
define_from_env('REQUESTS_TEST_HOST', 'requests-php-tests.herokuapp.com');
|
||||
define_from_env('REQUESTS_TEST_HOST_HTTP', REQUESTS_TEST_HOST);
|
||||
define_from_env('REQUESTS_TEST_HOST_HTTPS', REQUESTS_TEST_HOST);
|
||||
|
||||
define_from_env('REQUESTS_HTTP_PROXY');
|
||||
define_from_env('REQUESTS_HTTP_PROXY_AUTH');
|
||||
define_from_env('REQUESTS_HTTP_PROXY_AUTH_USER');
|
||||
define_from_env('REQUESTS_HTTP_PROXY_AUTH_PASS');
|
||||
|
||||
include(dirname(dirname(__FILE__)) . '/library/Requests.php');
|
||||
Requests::register_autoloader();
|
||||
|
||||
|
|
@ -17,6 +38,11 @@ function autoload_tests($class) {
|
|||
|
||||
spl_autoload_register('autoload_tests');
|
||||
|
||||
function httpbin($suffix = '', $ssl = false) {
|
||||
$host = $ssl ? 'https://' . REQUESTS_TEST_HOST_HTTPS : 'http://' . REQUESTS_TEST_HOST_HTTP;
|
||||
return rtrim( $host, '/' ) . '/' . ltrim( $suffix, '/' );
|
||||
}
|
||||
|
||||
class MockTransport implements Requests_Transport {
|
||||
public $code = 200;
|
||||
public $chunked = false;
|
||||
|
|
@ -59,16 +85,21 @@ class MockTransport implements Requests_Transport {
|
|||
415 => '415 Unsupported Media Type',
|
||||
416 => '416 Requested Range Not Satisfiable',
|
||||
417 => '417 Expectation Failed',
|
||||
418 => '418 I\'m a teapot',
|
||||
428 => '428 Precondition Required',
|
||||
429 => '429 Too Many Requests',
|
||||
431 => '431 Request Header Fields Too Large',
|
||||
500 => '500 Internal Server Error',
|
||||
501 => '501 Not Implemented',
|
||||
502 => '502 Bad Gateway',
|
||||
503 => '503 Service Unavailable',
|
||||
504 => '504 Gateway Timeout',
|
||||
505 => '505 HTTP Version Not Supported',
|
||||
511 => '511 Network Authentication Required',
|
||||
);
|
||||
|
||||
public function request($url, $headers = array(), $data = array(), $options = array()) {
|
||||
$status = self::$messages[$this->code];
|
||||
$status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown';
|
||||
$response = "HTTP/1.0 $status\r\n";
|
||||
$response .= "Content-Type: text/plain\r\n";
|
||||
if ($this->chunked) {
|
||||
|
|
|
|||
4
vendor/rmccue/requests/tests/phpunit.xml.dist
vendored
Executable file → Normal file
4
vendor/rmccue/requests/tests/phpunit.xml.dist
vendored
Executable file → Normal file
|
|
@ -7,6 +7,9 @@
|
|||
<testsuite name="Transports">
|
||||
<directory suffix=".php">Transport</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Proxies">
|
||||
<directory suffix=".php">Proxy</directory>
|
||||
</testsuite>
|
||||
<testsuite name="General">
|
||||
<file>ChunkedEncoding.php</file>
|
||||
<file>Cookies.php</file>
|
||||
|
|
@ -14,6 +17,7 @@
|
|||
<file>IRI.php</file>
|
||||
<file>Requests.php</file>
|
||||
<file>Response/Headers.php</file>
|
||||
<file>Session.php</file>
|
||||
<file>SSL.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
|
|
|||
5
vendor/rmccue/requests/tests/utils/proxy/proxy.py
vendored
Executable file
5
vendor/rmccue/requests/tests/utils/proxy/proxy.py
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
def request(context, flow):
|
||||
flow.request.headers["x-requests-proxy"] = "http"
|
||||
|
||||
def response(context, flow):
|
||||
flow.response.headers[b"x-requests-proxied"] = "http"
|
||||
11
vendor/rmccue/requests/tests/utils/proxy/start.sh
vendored
Executable file
11
vendor/rmccue/requests/tests/utils/proxy/start.sh
vendored
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
PROXYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PORT=${PORT:-9000}
|
||||
|
||||
PROXYBIN=${PROXYBIN:-"$(which mitmdump)"}
|
||||
ARGS="-s '$PROXYDIR/proxy.py' -p $PORT"
|
||||
if [[ ! -z "$AUTH" ]]; then
|
||||
ARGS="$ARGS --singleuser=$AUTH"
|
||||
fi
|
||||
PIDFILE="$PROXYDIR/proxy.pid"
|
||||
|
||||
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS
|
||||
5
vendor/rmccue/requests/tests/utils/proxy/stop.sh
vendored
Executable file
5
vendor/rmccue/requests/tests/utils/proxy/stop.sh
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
PROXYDIR="$PWD/$(dirname $0)"
|
||||
|
||||
PIDFILE="$PROXYDIR/proxy.pid"
|
||||
|
||||
start-stop-daemon --stop --pidfile $PIDFILE --make-pidfile && rm $PROXYDIR/proxy.pid
|
||||
Loading…
Add table
Add a link
Reference in a new issue