This commit is contained in:
manzerbredes 2016-03-28 12:17:43 +02:00
commit 53f65de9d4
88 changed files with 3596 additions and 694 deletions

View file

@ -93,7 +93,7 @@ class Client implements ClientInterface
$options = $this->prepareDefaults($options);
return $this->transfer(
$request->withUri($this->buildUri($request->getUri(), $options)),
$request->withUri($this->buildUri($request->getUri(), $options), $request->hasHeader('Host')),
$options
);
}
@ -173,7 +173,7 @@ class Client implements ClientInterface
$cleanedNoProxy = str_replace(' ', '', $noProxy);
$defaults['proxy']['no'] = explode(',', $cleanedNoProxy);
}
$this->config = $config + $defaults;
if (!empty($config['cookies']) && $config['cookies'] === true) {
@ -291,7 +291,7 @@ class Client implements ClientInterface
. 'x-www-form-urlencoded requests, and the multipart '
. 'option to send multipart/form-data requests.');
}
$options['body'] = http_build_query($options['form_params'], null, '&');
$options['body'] = http_build_query($options['form_params'], '', '&');
unset($options['form_params']);
$options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded';
}
@ -357,7 +357,8 @@ class Client implements ClientInterface
}
if (isset($options['json'])) {
$modify['body'] = Psr7\stream_for(json_encode($options['json']));
$jsonStr = \GuzzleHttp\json_encode($options['json']);
$modify['body'] = Psr7\stream_for($jsonStr);
$options['_conditional']['Content-Type'] = 'application/json';
unset($options['json']);
}

View file

@ -12,7 +12,7 @@ use Psr\Http\Message\UriInterface;
*/
interface ClientInterface
{
const VERSION = '6.1.1';
const VERSION = '6.2.0';
/**
* Send an HTTP request.
@ -44,14 +44,14 @@ interface ClientInterface
* relative path to append to the base path of the client. The URL can
* contain the query string as well.
*
* @param string $method HTTP method
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
* @param string $method HTTP method.
* @param string|UriInterface|null $uri URI object or string (default null).
* @param array $options Request options to apply.
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function request($method, $uri, array $options = []);
public function request($method, $uri = null, array $options = []);
/**
* Create and send an asynchronous HTTP request.

View file

@ -5,7 +5,7 @@ use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Cookie jar that stores cookies an an array
* Cookie jar that stores cookies as an array
*/
class CookieJar implements CookieJarInterface
{
@ -58,22 +58,10 @@ class CookieJar implements CookieJarInterface
}
/**
* Quote the cookie value if it is not already quoted and it contains
* problematic characters.
*
* @param string $value Value that may or may not need to be quoted
*
* @return string
* @deprecated
*/
public static function getCookieValue($value)
{
if (substr($value, 0, 1) !== '"' &&
substr($value, -1, 1) !== '"' &&
strpbrk($value, ';,=')
) {
$value = '"' . $value . '"';
}
return $value;
}
@ -248,7 +236,7 @@ class CookieJar implements CookieJarInterface
(!$cookie->getSecure() || $scheme == 'https')
) {
$values[] = $cookie->getName() . '='
. self::getCookieValue($cookie->getValue());
. $cookie->getValue();
}
}

View file

@ -11,7 +11,7 @@ class FileCookieJar extends CookieJar
/** @var bool Control whether to persist session cookies or not. */
private $storeSessionCookies;
/**
* Create a new FileCookieJar object
*
@ -55,7 +55,8 @@ class FileCookieJar extends CookieJar
}
}
if (false === file_put_contents($filename, json_encode($json))) {
$jsonStr = \GuzzleHttp\json_encode($json);
if (false === file_put_contents($filename, $jsonStr)) {
throw new \RuntimeException("Unable to save file {$filename}");
}
}
@ -73,9 +74,11 @@ class FileCookieJar extends CookieJar
$json = file_get_contents($filename);
if (false === $json) {
throw new \RuntimeException("Unable to load file {$filename}");
} elseif ($json === '') {
return;
}
$data = json_decode($json, true);
$data = \GuzzleHttp\json_decode($json, true);
if (is_array($data)) {
foreach (json_decode($json, true) as $cookie) {
$this->setCookie(new SetCookie($cookie));

View file

@ -265,6 +265,9 @@ class CurlFactory implements CurlFactoryInterface
$this->removeHeader('Content-Length', $conf);
}
$body = $request->getBody();
if ($body->isSeekable()) {
$body->rewind();
}
$conf[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
return $body->read($length);
};

View file

@ -192,6 +192,6 @@ class CurlMultiHandler
}
}
return max(0, $currentTime - $nextTime);
return max(0, $nextTime - $currentTime) * 1000000;
}
}

View file

@ -56,8 +56,13 @@ final class EasyHandle
if (!empty($this->options['decode_content'])
&& isset($normalizedKeys['content-encoding'])
) {
$headers['x-encoded-content-encoding']
= $headers[$normalizedKeys['content-encoding']];
unset($headers[$normalizedKeys['content-encoding']]);
if (isset($normalizedKeys['content-length'])) {
$headers['x-encoded-content-length']
= $headers[$normalizedKeys['content-length']];
$bodyLength = (int) $this->sink->getSize();
if ($bodyLength) {
$headers[$normalizedKeys['content-length']] = $bodyLength;

View file

@ -74,7 +74,7 @@ class MockHandler implements \Countable
$response = array_shift($this->queue);
if (is_callable($response)) {
$response = $response($request, $options);
$response = call_user_func($response, $request, $options);
}
$response = $response instanceof \Exception

View file

@ -138,7 +138,7 @@ class StreamHandler
: fopen('php://temp', 'r+');
return is_string($sink)
? new Psr7\Stream(Psr7\try_fopen($sink, 'r+'))
? new Psr7\LazyOpenStream($sink, 'w+')
: Psr7\stream_for($sink);
}
@ -153,10 +153,15 @@ class StreamHandler
$stream = new Psr7\InflateStream(
Psr7\stream_for($stream)
);
$headers['x-encoded-content-encoding']
= $headers[$normalizedKeys['content-encoding']];
// Remove content-encoding header
unset($headers[$normalizedKeys['content-encoding']]);
// Fix content-length header
if (isset($normalizedKeys['content-length'])) {
$headers['x-encoded-content-length']
= $headers[$normalizedKeys['content-length']];
$length = (int) $stream->getSize();
if ($length == 0) {
unset($headers[$normalizedKeys['content-length']]);

View file

@ -75,9 +75,14 @@ final class Middleware
* @param array $container Container to hold the history (by reference).
*
* @return callable Returns a function that accepts the next handler.
* @throws \InvalidArgumentException if container is not an array or ArrayAccess.
*/
public static function history(array &$container)
public static function history(&$container)
{
if (!is_array($container) && !$container instanceof \ArrayAccess) {
throw new \InvalidArgumentException('history container must be an array or object implementing ArrayAccess');
}
return function (callable $handler) use (&$container) {
return function ($request, array $options) use ($handler, &$container) {
return $handler($request, $options)->then(

View file

@ -282,3 +282,49 @@ function is_host_in_noproxy($host, array $noProxyArray)
return false;
}
/**
* Wrapper for json_decode that throws when an error occurs.
*
* @param string $json JSON data to parse
* @param bool $assoc When true, returned objects will be converted
* into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options.
*
* @return mixed
* @throws \InvalidArgumentException if the JSON cannot be decoded.
* @link http://www.php.net/manual/en/function.json-decode.php
*/
function json_decode($json, $assoc = false, $depth = 512, $options = 0)
{
$data = \json_decode($json, $assoc, $depth, $options);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(
'json_decode error: ' . json_last_error_msg());
}
return $data;
}
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param string $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*
* @return string
* @throws \InvalidArgumentException if the JSON cannot be encoded.
* @link http://www.php.net/manual/en/function.json-encode.php
*/
function json_encode($value, $options = 0, $depth = 512)
{
$json = \json_encode($value, $options, $depth);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(
'json_encode error: ' . json_last_error_msg());
}
return $json;
}