From 91784cf3cd5fb5509c10dcd1f3e8c363e4597519 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 16 Feb 2024 00:21:54 +0100 Subject: [PATCH] Separate unidirectional and bidirectional handlers --- src/Driver/Http3Driver.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Driver/Http3Driver.php b/src/Driver/Http3Driver.php index a9923d2f..68605366 100644 --- a/src/Driver/Http3Driver.php +++ b/src/Driver/Http3Driver.php @@ -61,7 +61,9 @@ class Http3Driver extends ConnectionHttpDriver /** @var DeferredFuture> */ private DeferredFuture $parsedSettings; /** @var array */ - private array $streamHandlers = []; + private array $bidirectionalStreamHandlers = []; + /** @var array */ + private array $unidirectionalStreamHandlers = []; /** * @param positive-int $headerSizeLimit @@ -97,9 +99,15 @@ public function addSetting(Http3Settings|int $setting, int $value): void } /** @param \Closure(string $buf, QuicSocket $stream): void $handler */ - public function addStreamHandler(int $type, \Closure $handler): void + public function addUnidirectionalStreamHandler(int $type, \Closure $handler): void + { + $this->bidirectionalStreamHandlers[$type] = $handler; + } + + /** @param \Closure(string $buf, QuicSocket $stream): void $handler */ + public function addBidirectionalStreamHandler(int $type, \Closure $handler): void { - $this->streamHandlers[$type] = $handler; + $this->unidirectionalStreamHandlers[$type] = $handler; } /** @@ -586,9 +594,10 @@ function (int $bodySize) use (&$bodySizeLimit, &$dataSuspension) { break; default: - if (isset($this->streamHandlers[$type])) { - [, $buf, $stream] = $frame; - $this->streamHandlers[$type]($buf, $stream); + [, $buf, $stream] = $frame; + $handlers = ($stream->getId() & 0x2) ? $this->unidirectionalStreamHandlers : $this->bidirectionalStreamHandlers; + if (isset($handlers[$type])) { + $handlers[$type]($buf, $stream); break; } $parser->abort(new Http3ConnectionException("An unexpected stream or frame was received", Http3Error::H3_FRAME_UNEXPECTED));