mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 10:03:27 +01:00
Merge branch 'master' into add_invalid_argument_exception
This commit is contained in:
commit
49a74936c4
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM composer:latest as setup
|
||||
|
||||
RUN mkdir /guzzle
|
||||
|
||||
WORKDIR /guzzle
|
||||
|
||||
RUN set -xe \
|
||||
&& composer init --name=guzzlehttp/test --description="Simple project for testing Guzzle scripts" --author="Márk Sági-Kazár <mark.sagikazar@gmail.com>" --no-interaction \
|
||||
&& composer require guzzlehttp/guzzle
|
||||
|
||||
|
||||
FROM php:7.2
|
||||
|
||||
RUN mkdir /guzzle
|
||||
|
||||
WORKDIR /guzzle
|
||||
|
||||
COPY --from=setup /guzzle /guzzle
|
@ -184,10 +184,10 @@ requests.
|
||||
'webp' => $client->getAsync('/image/webp')
|
||||
];
|
||||
|
||||
// Wait on all of the requests to complete. Throws a ConnectException
|
||||
// Wait on all of the requests to complete. Throws a ConnectException
|
||||
// if any of the requests fail
|
||||
$results = Promise\unwrap($promises);
|
||||
|
||||
|
||||
// Wait for the requests to complete, even if some of them fail
|
||||
$results = Promise\settle($promises)->wait();
|
||||
|
||||
@ -229,7 +229,7 @@ amount of requests you wish to send.
|
||||
|
||||
// Force the pool of requests to complete.
|
||||
$promise->wait();
|
||||
|
||||
|
||||
Or using a closure that will return a promise once the pool calls the closure.
|
||||
|
||||
.. code-block:: php
|
||||
@ -246,7 +246,7 @@ Or using a closure that will return a promise once the pool calls the closure.
|
||||
};
|
||||
|
||||
$pool = new Pool($client, $requests(100));
|
||||
|
||||
|
||||
|
||||
Using Responses
|
||||
===============
|
||||
@ -447,6 +447,43 @@ to use a shared cookie jar for all requests.
|
||||
$client = new \GuzzleHttp\Client(['cookies' => true]);
|
||||
$r = $client->request('GET', 'http://httpbin.org/cookies');
|
||||
|
||||
Different implementations exist for the ``GuzzleHttp\Cookie\CookieJarInterface``
|
||||
:
|
||||
|
||||
- The ``GuzzleHttp\Cookie\CookieJar`` class stores cookies as an array.
|
||||
- The ``GuzzleHttp\Cookie\FileCookieJar`` class persists non-session cookies
|
||||
using a JSON formatted file.
|
||||
- The ``GuzzleHttp\Cookie\SessionCookieJar`` class persists cookies in the
|
||||
client session.
|
||||
|
||||
You can manually set cookies into a cookie jar with the named constructor
|
||||
``fromArray(array $cookies, $domain)``.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$jar = \GuzzleHttp\Cookie\CookieJar::fromArray(
|
||||
[
|
||||
'some_cookie' => 'foo',
|
||||
'other_cookie' => 'barbaz1234'
|
||||
],
|
||||
'example.org'
|
||||
);
|
||||
|
||||
You can get a cookie by its name with the ``getCookieByName($name)`` method
|
||||
which returns a ``GuzzleHttp\Cookie\SetCookie`` instance.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$cookie = $jar->getCookieByName('some_cookie');
|
||||
|
||||
$cookie->getValue(); // 'foo'
|
||||
$cookie->getDomain(); // 'example.org'
|
||||
$cookie->getExpires(); // expiration date as a Unix timestamp
|
||||
|
||||
The cookies can be also fetched into an array thanks to the `toArray()` method.
|
||||
The ``GuzzleHttp\Cookie\CookieJarInterface`` interface extends
|
||||
``Traversable`` so it can be iterated in a foreach loop.
|
||||
|
||||
|
||||
Redirects
|
||||
=========
|
||||
@ -499,7 +536,7 @@ on each other.
|
||||
│ └── ClientException
|
||||
├── ConnectionException
|
||||
└── TooManyRedirectsException
|
||||
|
||||
|
||||
Guzzle throws exceptions for errors that occur during a transfer.
|
||||
|
||||
- In the event of a networking error (connection timeout, DNS errors, etc.),
|
||||
@ -568,7 +605,7 @@ behavior of the library.
|
||||
the timeout.
|
||||
``HTTP_PROXY``
|
||||
Defines the proxy to use when sending requests using the "http" protocol.
|
||||
|
||||
|
||||
Note: because the HTTP_PROXY variable may contain arbitrary user input on some (CGI) environments, the variable is only used on the CLI SAPI. See https://httpoxy.org for more information.
|
||||
``HTTPS_PROXY``
|
||||
Defines the proxy to use when sending requests using the "https" protocol.
|
||||
|
@ -34,7 +34,7 @@ a response or exception by shifting return values off of a queue.
|
||||
$mock = new MockHandler([
|
||||
new Response(200, ['X-Foo' => 'Bar']),
|
||||
new Response(202, ['Content-Length' => 0]),
|
||||
new RequestException("Error Communicating with Server", new Request('GET', 'test'))
|
||||
new RequestException('Error Communicating with Server', new Request('GET', 'test'))
|
||||
]);
|
||||
|
||||
$handlerStack = HandlerStack::create($mock);
|
||||
|
@ -120,7 +120,7 @@ class CookieJar implements CookieJarInterface
|
||||
} elseif (!$path) {
|
||||
$this->cookies = array_filter(
|
||||
$this->cookies,
|
||||
function (SetCookie $cookie) use ($path, $domain) {
|
||||
function (SetCookie $cookie) use ($domain) {
|
||||
return !$cookie->matchesDomain($domain);
|
||||
}
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ class StreamHandler
|
||||
// Append a content-length header if body size is zero to match
|
||||
// cURL's behavior.
|
||||
if (0 === $request->getBody()->getSize()) {
|
||||
$request = $request->withHeader('Content-Length', 0);
|
||||
$request = $request->withHeader('Content-Length', '0');
|
||||
}
|
||||
|
||||
return $this->createResponse(
|
||||
|
@ -206,7 +206,7 @@ class HandlerStack
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
private function findByName($name)
|
||||
@ -223,10 +223,10 @@ class HandlerStack
|
||||
/**
|
||||
* Splices a function into the middleware list at a specific position.
|
||||
*
|
||||
* @param $findName
|
||||
* @param $withName
|
||||
* @param string $findName
|
||||
* @param string $withName
|
||||
* @param callable $middleware
|
||||
* @param $before
|
||||
* @param bool $before
|
||||
*/
|
||||
private function splice($findName, $withName, callable $middleware, $before)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ final class Middleware
|
||||
return $handler($request, $options);
|
||||
}
|
||||
return $handler($request, $options)->then(
|
||||
function (ResponseInterface $response) use ($request, $handler) {
|
||||
function (ResponseInterface $response) use ($request) {
|
||||
$code = $response->getStatusCode();
|
||||
if ($code < 400) {
|
||||
return $response;
|
||||
|
@ -19,6 +19,9 @@ class RetryMiddleware
|
||||
/** @var callable */
|
||||
private $decider;
|
||||
|
||||
/** @var callable */
|
||||
private $delay;
|
||||
|
||||
/**
|
||||
* @param callable $decider Function that accepts the number of retries,
|
||||
* a request, [response], and [exception] and
|
||||
@ -42,7 +45,7 @@ class RetryMiddleware
|
||||
/**
|
||||
* Default exponential backoff delay function.
|
||||
*
|
||||
* @param $retries
|
||||
* @param int $retries
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@ class FileCookieJarTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testPersistsToFileFileParameters
|
||||
* @dataProvider providerPersistsToFileFileParameters
|
||||
*/
|
||||
public function testPersistsToFile($testSaveSessionCookie = false)
|
||||
{
|
||||
@ -78,7 +78,7 @@ class FileCookieJarTest extends TestCase
|
||||
unlink($this->file);
|
||||
}
|
||||
|
||||
public function testPersistsToFileFileParameters()
|
||||
public function providerPersistsToFileFileParameters()
|
||||
{
|
||||
return array(
|
||||
array(false),
|
||||
|
@ -38,7 +38,7 @@ class SessionCookieJarTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider testPersistsToSessionParameters
|
||||
* @dataProvider providerPersistsToSessionParameters
|
||||
*/
|
||||
public function testPersistsToSession($testSaveSessionCookie = false)
|
||||
{
|
||||
@ -82,7 +82,7 @@ class SessionCookieJarTest extends TestCase
|
||||
unset($_SESSION[$this->sessionVar]);
|
||||
}
|
||||
|
||||
public function testPersistsToSessionParameters()
|
||||
public function providerPersistsToSessionParameters()
|
||||
{
|
||||
return array(
|
||||
array(false),
|
||||
|
@ -37,8 +37,8 @@ class CurlHandlerTest extends TestCase
|
||||
Server::enqueue([$response, $response]);
|
||||
$a = new CurlHandler();
|
||||
$request = new Request('GET', Server::$url);
|
||||
$a($request, []);
|
||||
$a($request, []);
|
||||
$this->assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
|
||||
$this->assertInstanceOf('GuzzleHttp\Promise\FulfilledPromise', $a($request, []));
|
||||
}
|
||||
|
||||
public function testDoesSleep()
|
||||
|
@ -46,6 +46,10 @@ class CurlMultiHandlerTest extends TestCase
|
||||
$response->cancel();
|
||||
$responses[] = $response;
|
||||
}
|
||||
|
||||
foreach($responses as $r) {
|
||||
$this->assertEquals('rejected', $response->getState());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCannotCancelFinished()
|
||||
@ -56,6 +60,7 @@ class CurlMultiHandlerTest extends TestCase
|
||||
$response = $a(new Request('GET', Server::$url), []);
|
||||
$response->wait();
|
||||
$response->cancel();
|
||||
$this->assertEquals('fulfilled', $response->getState());
|
||||
}
|
||||
|
||||
public function testDelaysConcurrently()
|
||||
|
@ -307,7 +307,8 @@ class StreamHandlerTest extends TestCase
|
||||
|
||||
public function testVerifyCanBeDisabled()
|
||||
{
|
||||
$this->getSendResult(['verify' => false]);
|
||||
$handler = $this->getSendResult(['verify' => false]);
|
||||
$this->assertInstanceOf('GuzzleHttp\Psr7\Response', $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,6 +338,8 @@ class StreamHandlerTest extends TestCase
|
||||
$opts = stream_context_get_options($res->getBody()->detach());
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
$this->assertEquals($path, $opts['ssl']['cafile']);
|
||||
} else {
|
||||
$this->assertArrayNotHasKey('cafile', $opts['ssl']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,9 @@ class HandlerStackTest extends TestCase
|
||||
$this->assertTrue($h->hasHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testCanSetDifferentHandlerAfterConstruction()
|
||||
{
|
||||
$f = function () {};
|
||||
|
@ -34,6 +34,9 @@ class PoolTest extends TestCase
|
||||
$p->promise()->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testSendsAndRealizesFuture()
|
||||
{
|
||||
$c = $this->getClient();
|
||||
@ -41,6 +44,9 @@ class PoolTest extends TestCase
|
||||
$p->promise()->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doesNotPerformAssertions
|
||||
*/
|
||||
public function testExecutesPendingWhenWaiting()
|
||||
{
|
||||
$r1 = new Promise(function () use (&$r1) { $r1->resolve(new Response()); });
|
||||
|
Loading…
x
Reference in New Issue
Block a user