Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php:
- 8.4
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"php": ">=5.3.0",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"fig/http-message-util": "^1.1",
"psr/http-message": "^1.0",
"psr/http-message": "^2.0 || ^1.0",
"react/event-loop": "^1.2",
"react/promise": "^3.2 || ^2.3 || ^1.2.1",
"react/socket": "^1.16",
"react/stream": "^1.4"
},
"require-dev": {
"clue/http-proxy-react": "^1.8",
"clue/http-proxy-react": "^1.10",
"clue/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"phpunit/phpunit": "^9.6 || ^8.5 || ^5.7 || ^4.8.36",
"react/async": "^4.2 || ^3 || ^2",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.11"
Expand Down
7 changes: 7 additions & 0 deletions src/Io/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] Abstract HTTP message base class (PSR-7)
*
Expand Down Expand Up @@ -170,3 +172,8 @@ public function withBody(StreamInterface $body)
return $message;
}
}
} else {
abstract class AbstractMessage extends V2\AbstractMessage
{
}
}
7 changes: 7 additions & 0 deletions src/Io/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use React\Http\Message\Uri;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] Abstract HTTP request base class (PSR-7)
*
Expand Down Expand Up @@ -154,3 +156,8 @@ public function withUri(UriInterface $uri, $preserveHost = false)
return $request;
}
}
} else {
abstract class AbstractRequest extends V2\AbstractRequest
{
}
}
7 changes: 7 additions & 0 deletions src/Io/BufferedBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Psr\Http\Message\StreamInterface;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] PSR-7 message body implementation using an in-memory buffer
*
Expand Down Expand Up @@ -177,3 +179,8 @@ public function getMetadata($key = null)
return $key === null ? array() : null;
}
}
} else {
class BufferedBody extends V2\BufferedBody
{
}
}
7 changes: 7 additions & 0 deletions src/Io/EmptyBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Evenement\EventEmitter;
use Psr\Http\Message\StreamInterface;
use React\Stream\ReadableStreamInterface;
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] Bridge between an empty StreamInterface from PSR-7 and ReadableStreamInterface from ReactPHP
*
Expand Down Expand Up @@ -140,3 +142,8 @@ public function getMetadata($key = null)
return ($key === null) ? array() : null;
}
}
} else {
class EmptyBodyStream extends V2\EmptyBodyStream
{
}
}
7 changes: 7 additions & 0 deletions src/Io/HttpBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Evenement\EventEmitter;
use Psr\Http\Message\StreamInterface;
use React\Stream\ReadableStreamInterface;
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] Bridge between StreamInterface from PSR-7 and ReadableStreamInterface from ReactPHP
*
Expand Down Expand Up @@ -180,3 +182,8 @@ public function handleEnd()
}
}
}
} else {
class HttpBodyStream extends V2\HttpBodyStream
{
}
}
7 changes: 7 additions & 0 deletions src/Io/ReadableBodyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Evenement\EventEmitter;
use Psr\Http\Message\StreamInterface;
use React\Stream\ReadableStreamInterface;
use React\Stream\Util;
use React\Stream\WritableStreamInterface;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* @internal
*/
Expand Down Expand Up @@ -151,3 +153,8 @@ public function handleEnd()
$this->close();
}
}
} else {
class ReadableBodyStream extends V2\ReadableBodyStream
{
}
}
9 changes: 8 additions & 1 deletion src/Io/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace React\Http\Io;

use Composer\InstalledVersions;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use InvalidArgumentException;
use RuntimeException;

if (version_compare(InstalledVersions::getVersion('psr/http-message'), '2.0.0', '<')) {
/**
* [Internal] Implementation of the PSR-7 `UploadedFileInterface`
*
Expand All @@ -18,7 +20,7 @@
* @see UploadedFileInterface
* @internal
*/
final class UploadedFile implements UploadedFileInterface
class UploadedFile implements UploadedFileInterface
{
/**
* @var StreamInterface
Expand Down Expand Up @@ -128,3 +130,8 @@ public function getClientMediaType()
return $this->mediaType;
}
}
} else {
final class UploadedFile extends V2\UploadedFile
{
}
}
172 changes: 172 additions & 0 deletions src/Io/V2/AbstractMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace React\Http\Io\V2;

use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

/**
* [Internal] Abstract HTTP message base class (PSR-7)
*
* @internal
* @see MessageInterface
*/
abstract class AbstractMessage implements MessageInterface
{
/**
* [Internal] Regex used to match all request header fields into an array, thanks to @kelunik for checking the HTTP specs and coming up with this regex
*
* @internal
* @var string
*/
const REGEX_HEADERS = '/^([^()<>@,;:\\\"\/\[\]?={}\x00-\x20\x7F]++):[\x20\x09]*+((?:[\x20\x09]*+[\x21-\x7E\x80-\xFF]++)*+)[\x20\x09]*+[\r]?+\n/m';

/** @var array<string,string[]> */
private $headers = array();

/** @var array<string,string> */
private $headerNamesLowerCase = array();

/** @var string */
private $protocolVersion;

/** @var StreamInterface */
private $body;

/**
* @param string $protocolVersion
* @param array<string,string|string[]> $headers
* @param StreamInterface $body
*/
protected function __construct($protocolVersion, array $headers, StreamInterface $body)
{
foreach ($headers as $name => $value) {
if ($value !== array()) {
if (\is_array($value)) {
foreach ($value as &$one) {
$one = (string) $one;
}
} else {
$value = array((string) $value);
}

$lower = \strtolower($name);
if (isset($this->headerNamesLowerCase[$lower])) {
$value = \array_merge($this->headers[$this->headerNamesLowerCase[$lower]], $value);
unset($this->headers[$this->headerNamesLowerCase[$lower]]);
}

$this->headers[$name] = $value;
$this->headerNamesLowerCase[$lower] = $name;
}
}

$this->protocolVersion = (string) $protocolVersion;
$this->body = $body;
}

public function getProtocolVersion(): string
{
return $this->protocolVersion;
}

public function withProtocolVersion(string $version): MessageInterface
{
if ((string) $version === $this->protocolVersion) {
return $this;
}

$message = clone $this;
$message->protocolVersion = (string) $version;

return $message;
}

public function getHeaders(): array
{
return $this->headers;
}

public function hasHeader(string $name): bool
{
return isset($this->headerNamesLowerCase[\strtolower($name)]);
}

public function getHeader(string $name): array
{
$lower = \strtolower($name);
return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : array();
}

public function getHeaderLine(string $name): string
{
return \implode(', ', $this->getHeader($name));
}

public function withHeader(string $name, $value): MessageInterface
{
if ($value === array()) {
return $this->withoutHeader($name);
} elseif (\is_array($value)) {
foreach ($value as &$one) {
$one = (string) $one;
}
} else {
$value = array((string) $value);
}

$lower = \strtolower($name);
if (isset($this->headerNamesLowerCase[$lower]) && $this->headerNamesLowerCase[$lower] === (string) $name && $this->headers[$this->headerNamesLowerCase[$lower]] === $value) {
return $this;
}

$message = clone $this;
if (isset($message->headerNamesLowerCase[$lower])) {
unset($message->headers[$message->headerNamesLowerCase[$lower]]);
}

$message->headers[$name] = $value;
$message->headerNamesLowerCase[$lower] = $name;

return $message;
}

public function withAddedHeader(string $name, $value): MessageInterface
{
if ($value === array()) {
return $this;
}

return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value)));
}

public function withoutHeader(string $name): MessageInterface
{
$lower = \strtolower($name);
if (!isset($this->headerNamesLowerCase[$lower])) {
return $this;
}

$message = clone $this;
unset($message->headers[$message->headerNamesLowerCase[$lower]], $message->headerNamesLowerCase[$lower]);

return $message;
}

public function getBody(): StreamInterface
{
return $this->body;
}

public function withBody(StreamInterface $body): MessageInterface
{
if ($body === $this->body) {
return $this;
}

$message = clone $this;
$message->body = $body;

return $message;
}
}
Loading
Loading