Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: guzzle/psr7
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.2.1
Choose a base ref
...
head repository: guzzle/psr7
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.2.2
Choose a head ref
  • 6 commits
  • 9 files changed
  • 4 contributors

Commits on Mar 24, 2022

  1. Add version guidance to readme (#496)

    * Add version guidance to readme
    
    * Update README.md
    
    * Update README.md
    sagikazarmark authored Mar 24, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    Byron Sebastian Thiel
    Copy the full SHA
    5c69324 View commit details

Commits on Apr 28, 2022

  1. Copy the full SHA
    58a607d View commit details

Commits on May 2, 2022

  1. Copy the full SHA
    81bf80e View commit details
  2. Copy the full SHA
    f8ae7cb View commit details

Commits on Jun 8, 2022

  1. Throw an exception when multipart options is misformatted (#511)

    I spend a lot of time searching for an error that was only a misformatted data in the multipart request option, and the server just die without give any information about of error. I think that an exception would be useful for other people that is as absent-minded as me.
    AlexanderZon authored Jun 8, 2022
    Copy the full SHA
    10c4dd3 View commit details
  2. Copy the full SHA
    a119247 View commit details
Showing with 72 additions and 11 deletions.
  1. +8 −0 CHANGELOG.md
  2. +6 −0 README.md
  3. +1 −4 composer.json
  4. +3 −0 src/Message.php
  5. +3 −5 src/MessageTrait.php
  6. +3 −0 src/MultipartStream.php
  7. +6 −1 src/Stream.php
  8. +15 −0 tests/MessageTest.php
  9. +27 −1 tests/StreamTest.php
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 2.2.2 - 2022-06-08

### Fixed

- Fix `Message::parseRequestUri()` for numeric headers
- Re-wrap exceptions thrown in `fread` into runtime exceptions
- Throw an exception when multipart options is misformatted

## 2.2.1 - 2022-03-20

### Fixed
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -807,6 +807,12 @@ Whether two URIs can be considered equivalent. Both URIs are normalized automati
This of course assumes they will be resolved against the same base URI. If this is not the case, determination of
equivalence or difference of relative references does not mean anything.

## Version Guidance

| Version | Status | PHP Version |
|---------|----------------|------------------|
| 1.x | Security fixes | >= 5.4, < 8.2 |
| 2.x | Latest | ^7.2.5 \|\| ^8.0 |

## Security

5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -87,9 +87,6 @@
"bamarni/composer-bin-plugin": true
},
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
"sort-packages": true
}
}
3 changes: 3 additions & 0 deletions src/Message.php
Original file line number Diff line number Diff line change
@@ -175,6 +175,9 @@ public static function parseMessage(string $message): array
public static function parseRequestUri(string $path, array $headers): string
{
$hostKey = array_filter(array_keys($headers), function ($k) {
// Numeric array keys are converted to int by PHP.
$k = (string) $k;

return strtolower($k) === 'host';
});

8 changes: 3 additions & 5 deletions src/MessageTrait.php
Original file line number Diff line number Diff line change
@@ -145,11 +145,9 @@ private function setHeaders(array $headers): void
{
$this->headerNames = $this->headers = [];
foreach ($headers as $header => $value) {
if (is_int($header)) {
// Numeric array keys are converted to int by PHP but having a header name '123' is not forbidden by the spec
// and also allowed in withHeader(). So we need to cast it to string again for the following assertion to pass.
$header = (string) $header;
}
// Numeric array keys are converted to int by PHP.
$header = (string) $header;

$this->assertHeader($header);
$value = $this->normalizeHeaderValue($value);
$normalized = strtolower($header);
3 changes: 3 additions & 0 deletions src/MultipartStream.php
Original file line number Diff line number Diff line change
@@ -68,6 +68,9 @@ protected function createStream(array $elements = []): StreamInterface
$stream = new AppendStream();

foreach ($elements as $element) {
if (!is_array($element)) {
throw new \UnexpectedValueException("An array is expected");
}
$this->addElement($stream, $element);
}

7 changes: 6 additions & 1 deletion src/Stream.php
Original file line number Diff line number Diff line change
@@ -229,7 +229,12 @@ public function read($length): string
return '';
}

$string = fread($this->stream, $length);
try {
$string = fread($this->stream, $length);
} catch (\Exception $e) {
throw new \RuntimeException('Unable to read from stream', 0, $e);
}

if (false === $string) {
throw new \RuntimeException('Unable to read from stream');
}
15 changes: 15 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
@@ -126,6 +126,21 @@ public function testParsesRequestMessagesWithCustomMethod(): void
self::assertSame('GET_DATA', $request->getMethod());
}

public function testParsesRequestMessagesWithNumericHeader(): void
{
$req = "GET /abc HTTP/1.0\r\nHost: foo.com\r\nFoo: Bar\r\nBaz: Bam\r\nBaz: Qux\r\n123: 456\r\n\r\nTest";
$request = Psr7\Message::parseRequest($req);
self::assertSame('GET', $request->getMethod());
self::assertSame('/abc', $request->getRequestTarget());
self::assertSame('1.0', $request->getProtocolVersion());
self::assertSame('foo.com', $request->getHeaderLine('Host'));
self::assertSame('Bar', $request->getHeaderLine('Foo'));
self::assertSame('Bam, Qux', $request->getHeaderLine('Baz'));
self::assertSame('456', $request->getHeaderLine('123'));
self::assertSame('Test', (string)$request->getBody());
self::assertSame('http://foo.com/abc', (string)$request->getUri());
}

public function testParsesRequestMessagesWithFoldedHeadersOnHttp10(): void
{
$req = "PUT / HTTP/1.0\r\nFoo: Bar\r\n Bam\r\n\r\n";
28 changes: 27 additions & 1 deletion tests/StreamTest.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@

namespace GuzzleHttp\Tests\Psr7;

use GuzzleHttp\Psr7\FnStream;
use GuzzleHttp\Psr7\Stream;
use GuzzleHttp\Psr7\StreamWrapper;
use PHPUnit\Framework\TestCase;

/**
@@ -255,7 +257,7 @@ public function testStreamReadingWithNegativeLength(): void
$stream->close();
}

public function testStreamReadingFreadError(): void
public function testStreamReadingFreadFalse(): void
{
self::$isFReadError = true;
$r = fopen('php://temp', 'r');
@@ -275,6 +277,30 @@ public function testStreamReadingFreadError(): void
$stream->close();
}

public function testStreamReadingFreadException(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to read from stream');

$r = StreamWrapper::getResource(new FnStream([
'read' => function ($len): string {
throw new \ErrorException('Some error');
},
'isReadable' => function (): bool {
return true;
},
'isWritable' => function (): bool {
return false;
},
'eof' => function (): bool {
return false;
}
]));

$stream = new Stream($r);
$stream->read(1);
}

/**
* @requires extension zlib
*