Commit b315b3b8 authored by webchick's avatar webchick

Issue #2546272 by hussainweb, jhedstrom, dawehner: Update guzzlehttp/psr7 to...

Issue #2546272 by hussainweb, jhedstrom, dawehner: Update guzzlehttp/psr7 to 1.2.0 and guzzlehttp/promises to 1.0.2
parent 8aee36fd
......@@ -850,16 +850,16 @@
},
{
"name": "guzzlehttp/promises",
"version": "1.0.1",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7"
"reference": "97fe7210def29451ec74923b27e552238defd75a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
"reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
"url": "https://api.github.com/repos/guzzle/promises/zipball/97fe7210def29451ec74923b27e552238defd75a",
"reference": "97fe7210def29451ec74923b27e552238defd75a",
"shasum": ""
},
"require": {
......@@ -879,7 +879,7 @@
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions.php"
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
......@@ -897,20 +897,20 @@
"keywords": [
"promise"
],
"time": "2015-06-24 16:16:25"
"time": "2015-08-15 19:37:21"
},
{
"name": "guzzlehttp/psr7",
"version": "1.1.0",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd"
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/af0e1758de355eb113917ad79c3c0e3604bce4bd",
"reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"shasum": ""
},
"require": {
......@@ -934,7 +934,7 @@
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions.php"
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
......@@ -955,7 +955,7 @@
"stream",
"uri"
],
"time": "2015-06-24 19:55:15"
"time": "2015-08-15 19:32:36"
},
{
"name": "masterminds/html5",
......
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
......@@ -6,8 +6,8 @@
$baseDir = dirname($vendorDir);
return array(
$vendorDir . '/guzzlehttp/psr7/src/functions.php',
$vendorDir . '/guzzlehttp/promises/src/functions.php',
$vendorDir . '/guzzlehttp/promises/src/functions_include.php',
$vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
$vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
$baseDir . '/lib/Drupal.php',
);
......@@ -2110,119 +2110,6 @@
"psr-7"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/af0e1758de355eb113917ad79c3c0e3604bce4bd",
"reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2015-06-24 19:55:15",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
]
},
{
"name": "guzzlehttp/promises",
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
"reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2015-06-24 16:16:25",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
]
},
{
"name": "guzzlehttp/guzzle",
"version": "dev-master",
......@@ -3477,5 +3364,118 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com"
},
{
"name": "guzzlehttp/promises",
"version": "1.0.2",
"version_normalized": "1.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "97fe7210def29451ec74923b27e552238defd75a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/97fe7210def29451ec74923b27e552238defd75a",
"reference": "97fe7210def29451ec74923b27e552238defd75a",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2015-08-15 19:37:21",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.0",
"version_normalized": "1.2.0.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2015-08-15 19:32:36",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
]
}
]
phpunit.xml
composer.phar
composer.lock
composer-test.lock
vendor/
build/artifacts/
artifacts/
docs/_build
docs/*.pyc
.idea
.DS_STORE
# CHANGELOG
## 1.0.2 - 2015-05-15
* Conditionally require functions.php.
## 1.0.1 - 2015-06-24
* Updating EachPromise to call next on the underlying promise iterator as late
......
......@@ -21,7 +21,7 @@
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": ["src/functions.php"]
"files": ["src/functions_include.php"]
},
"extra": {
"branch-alias": {
......
<?php
namespace GuzzleHttp\Promise;
// Don't redefine the functions if included multiple times.
if (function_exists('GuzzleHttp\Promise\promise_for')) {
return;
}
/**
* Get the global task queue used for promise resolution.
*
......
<?php
// Don't redefine the functions if included multiple times.
if (!function_exists('GuzzleHttp\Promise\promise_for')) {
require __DIR__ . '/functions.php';
}
phpunit.xml
composer.phar
composer.lock
composer-test.lock
vendor/
build/artifacts/
artifacts/
docs/_build
docs/*.pyc
.idea
.DS_STORE
# CHANGELOG
## 1.2.0 - 2015-08-15
* Body as `"0"` is now properly added to a response.
* Now allowing forward seeking in CachingStream.
* Now properly parsing HTTP requests that contain proxy targets in
`parse_request`.
* functions.php is now conditionally required.
* user-info is no longer dropped when resolving URIs.
## 1.1.0 - 2015-06-24
* URIs can now be relative.
......
......@@ -25,7 +25,7 @@
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": ["src/functions.php"]
"files": ["src/functions_include.php"]
},
"extra": {
"branch-alias": {
......
......@@ -41,30 +41,33 @@ public function rewind()
$this->seek(0);
}
/**
* {@inheritdoc}
* @throws \RuntimeException When seeking with SEEK_END or when seeking
* past the total size of the buffer stream
*/
public function seek($offset, $whence = SEEK_SET)
{
if ($whence == SEEK_SET) {
$byte = $offset;
} elseif ($whence == SEEK_CUR) {
$byte = $offset + $this->tell();
} elseif ($whence == SEEK_END) {
$size = $this->remoteStream->getSize();
if ($size === null) {
$size = $this->cacheEntireStream();
}
// Because 0 is the first byte, we seek to size - 1.
$byte = $size - 1 - $offset;
} else {
throw new \RuntimeException('CachingStream::seek() supports SEEK_SET and SEEK_CUR');
throw new \InvalidArgumentException('Invalid whence');
}
// You cannot skip ahead past where you've read from the remote stream
if ($byte > $this->stream->getSize()) {
throw new \RuntimeException(
sprintf('Cannot seek to byte %d when the buffered stream only'
. ' contains %d bytes', $byte, $this->stream->getSize())
);
}
$diff = $byte - $this->stream->getSize();
$this->stream->seek($byte);
if ($diff > 0) {
// If the seek byte is greater the number of read bytes, then read
// the difference of bytes to cache the bytes and inherently seek.
$this->read($diff);
} else {
// We can just do a normal seek since we've already seen this byte.
$this->stream->seek($byte);
}
}
public function read($length)
......@@ -122,4 +125,12 @@ public function close()
{
$this->remoteStream->close() && $this->stream->close();
}
private function cacheEntireStream()
{
$target = new FnStream(['write' => 'strlen']);
copy_to_stream($this, $target);
return $this->tell();
}
}
......@@ -93,7 +93,7 @@ public function __construct(
) {
$this->statusCode = (int) $status;
if ($body) {
if ($body !== null) {
$this->stream = stream_for($body);
}
......
......@@ -123,44 +123,33 @@ public static function resolve(UriInterface $base, $rel)
return $base;
}
if ($rel instanceof UriInterface) {
$relParts = [
'scheme' => $rel->getScheme(),
'host' => $rel->getHost(),
'port' => $rel->getPort(),
'path' => $rel->getPath(),
'query' => $rel->getQuery(),
'fragment' => $rel->getFragment()
];
} else {
$relParts = parse_url($rel) + [
'scheme' => '',
'host' => '',
'port' => '',
'path' => '',
'query' => '',
'fragment' => ''
];
if (!($rel instanceof UriInterface)) {
$rel = new self($rel);
}
if (!empty($relParts['scheme']) && !empty($relParts['host'])) {
return $rel instanceof UriInterface
? $rel
: self::fromParts($relParts);
// Return the relative uri as-is if it has a scheme.
if ($rel->getScheme()) {
return $rel->withPath(static::removeDotSegments($rel->getPath()));
}
$relParts = [
'scheme' => $rel->getScheme(),
'authority' => $rel->getAuthority(),
'path' => $rel->getPath(),
'query' => $rel->getQuery(),
'fragment' => $rel->getFragment()
];
$parts = [
'scheme' => $base->getScheme(),
'host' => $base->getHost(),
'port' => $base->getPort(),
'path' => $base->getPath(),
'query' => $base->getQuery(),
'fragment' => $base->getFragment()
'scheme' => $base->getScheme(),
'authority' => $base->getAuthority(),
'path' => $base->getPath(),
'query' => $base->getQuery(),
'fragment' => $base->getFragment()
];
if (!empty($relParts['host'])) {
$parts['host'] = $relParts['host'];
$parts['port'] = $relParts['port'];
if (!empty($relParts['authority'])) {
$parts['authority'] = $relParts['authority'];
$parts['path'] = self::removeDotSegments($relParts['path']);
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
......@@ -170,7 +159,7 @@ public static function resolve(UriInterface $base, $rel)
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
} else {
if (!empty($parts['host']) && empty($parts['path'])) {
if (!empty($parts['authority']) && empty($parts['path'])) {
$mergedPath = '/';
} else {
$mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
......@@ -185,7 +174,13 @@ public static function resolve(UriInterface $base, $rel)
$parts['fragment'] = $relParts['fragment'];
}
return static::fromParts($parts);
return new self(static::createUriString(
$parts['scheme'],
$parts['authority'],
$parts['path'],
$parts['query'],
$parts['fragment']
));
}
/**
......
......@@ -440,19 +440,22 @@ function readline(StreamInterface $stream, $maxLength = null)
function parse_request($message)
{
$data = _parse_message($message);
if (!preg_match('/^[a-zA-Z]+\s+\/.*/', $data['start-line'])) {
$matches = [];
if (!preg_match('/^[a-zA-Z]+\s+([a-zA-Z]+:\/\/|\/).*/', $data['start-line'], $matches)) {
throw new \InvalidArgumentException('Invalid request string');
}
$parts = explode(' ', $data['start-line'], 3);
$version = isset($parts[2]) ? explode('/', $parts[2])[1] : '1.1';
return new Request(
$request = new Request(
$parts[0],
_parse_request_uri($parts[1], $data['headers']),
$matches[1] === '/' ? _parse_request_uri($parts[1], $data['headers']) : $parts[1],
$data['headers'],
$data['body'],
$version
);
return $matches[1] === '/' ? $request : $request->withRequestTarget($parts[1]);
}
/**
......
<?php
// Don't redefine the functions if included multiple times.
if (!function_exists('GuzzleHttp\Psr7\str')) {
require __DIR__ . '/functions.php';
}
......@@ -32,22 +32,43 @@ public function testUsesRemoteSizeIfPossible()
$this->assertEquals(4, $caching->getSize());
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Cannot seek to byte 10
*/
public function testCannotSeekPastWhatHasBeenRead()
public function testReadsUntilCachedToByte()
{
$this->body->seek(10);
$this->body->seek(5);
$this->assertEquals('n', $this->body->read(1));
$this->body->seek(0);
$this->assertEquals('t', $this->body->read(1));
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage CachingStream::seek() supports SEEK_SET and SEEK_CUR
*/
public function testCannotUseSeekEnd()
public function testCanSeekNearEndWithSeekEnd()
{
$baseStream = Psr7\stream_for(implode('', range('a', 'z')));
$cached = new CachingStream($baseStream);
$cached->seek(1, SEEK_END);
$this->assertEquals(24, $baseStream->tell());
$this->assertEquals('y', $cached->read(1));
$this->assertEquals(26, $cached->getSize());
}
public function testCanSeekToEndWithSeekEnd()
{
$this->body->seek(2, SEEK_END);
$baseStream = Psr7\stream_for(implode('', range('a', 'z')));
$cached = new CachingStream($baseStream);
$cached->seek(0, SEEK_END);
$this->assertEquals(25, $baseStream->tell());
$this->assertEquals('z', $cached->read(1));
$this->assertEquals(26, $cached->getSize());
}
public function testCanUseSeekEndWithUnknownSize()
{
$baseStream = Psr7\stream_for('testing');
$decorated = Psr7\FnStream::decorate($baseStream, [
'getSize' => function () { return null; }
]);
$cached = new CachingStream($decorated);
$cached->seek(1, SEEK_END);
$this->assertEquals('ng', $cached->read(2));
}
public function testRewindUsesSeek()
......@@ -134,4 +155,12 @@ public function testClosesBothStreams()
$d->close();
$this->assertFalse(is_resource($s));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testEnsuresValidWhence()
{
$this->body->seek(10, -123456);
}
}
......@@ -270,6 +270,18 @@ public function testParsesRequestMessagesWithUriWhenHostIsNotFirst()
$this->assertEquals('http://foo.com/', (string) $request->getUri());
}
public function testParsesRequestMessagesWithFullUri()
{
$req = "GET https://www.google.com:443/search?q=foobar HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
$request = Psr7\parse_request($req);
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals('https://www.google.com:443/search?q=foobar', $request->getRequestTarget());
$this->assertEquals('1.1', $request->getProtocolVersion());
$this->assertEquals('www.google.com', $request->getHeaderLine('Host'));
$this->assertEquals('', (string) $request->getBody());
$this->assertEquals('https://www.google.com/search?q=foobar', (string) $request->getUri());
}
/**
* @expectedException \InvalidArgumentException
*/
......