Skip to content

Commit

Permalink
Separate unidirectional and bidirectional handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Feb 15, 2024
1 parent c23e971 commit 91784cf
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Driver/Http3Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class Http3Driver extends ConnectionHttpDriver
/** @var DeferredFuture<array<int, int>> */
private DeferredFuture $parsedSettings;
/** @var array<int, \Closure(string $buf, QuicSocket $stream): void> */
private array $streamHandlers = [];
private array $bidirectionalStreamHandlers = [];
/** @var array<int, \Closure(string $buf, QuicSocket $stream): void> */
private array $unidirectionalStreamHandlers = [];

/**
* @param positive-int $headerSizeLimit
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 91784cf

Please sign in to comment.