From f9fb0346fd90511333de1749832fe8abd078522b Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 18 Feb 2024 19:46:24 +0100 Subject: [PATCH] Add HttpDriverMergedFactory --- src/Driver/HttpDriverMergedFactory.php | 34 +++++++++++++++++++++++ src/Driver/Internal/Http3/Http3Parser.php | 4 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Driver/HttpDriverMergedFactory.php diff --git a/src/Driver/HttpDriverMergedFactory.php b/src/Driver/HttpDriverMergedFactory.php new file mode 100644 index 00000000..ef166af3 --- /dev/null +++ b/src/Driver/HttpDriverMergedFactory.php @@ -0,0 +1,34 @@ + $middlewares + */ + public function __construct(private array $middlewares, private HttpDriverFactory $factory) + { + } + + public function createHttpDriver(RequestHandler $requestHandler, ErrorHandler $errorHandler, Client $client): HttpDriver + { + if ($this->index >= \count($this->middlewares)) { + return $this->factory->createHttpDriver($requestHandler, $errorHandler, $client); + } + + $factory = clone $this; + ++$factory->index; + return $this->middlewares[$this->index]->createHttpDriver($factory, $requestHandler, $errorHandler, $client); + } + + public function getApplicationLayerProtocols(): array + { + return $this->factory->getApplicationLayerProtocols(); + } +} diff --git a/src/Driver/Internal/Http3/Http3Parser.php b/src/Driver/Internal/Http3/Http3Parser.php index ad0f1702..797cf206 100644 --- a/src/Driver/Internal/Http3/Http3Parser.php +++ b/src/Driver/Internal/Http3/Http3Parser.php @@ -315,12 +315,14 @@ public function process(): ConcurrentIterator $type = self::decodeVarintFromStream($stream, $buf, $off); if ($stream->isWritable()) { - // client-initiated bidirectional stream + // bidirectional stream if ($type > 0x0d /* bigger than any default frame */ && $type % 0x1f !== 0x2 /* and not a padding frame */) { // Unknown frame type. Users may handle it (e.g. WebTransport). $this->queue->push([$type, \substr($buf, $off), $stream]); return; } + + // Note: the parser will also allow for Messages to be sent on new streams. MUST fail connections which do push HEADERS. $off = 0; $messageGenerator = $this->readHttpMessage($stream, $buf, $off); if (!$messageGenerator->valid()) {