Skip to content

Commit

Permalink
Add HttpDriverMergedFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Feb 18, 2024
1 parent 279eb2b commit f9fb034
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/Driver/HttpDriverMergedFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Amp\Http\Server\Driver;

use Amp\Http\Server\ErrorHandler;
use Amp\Http\Server\RequestHandler;

class HttpDriverMergedFactory implements HttpDriverFactory
{
private int $index = 0;

/**
* @param list<HttpDriverMiddleware> $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();
}
}
4 changes: 3 additions & 1 deletion src/Driver/Internal/Http3/Http3Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit f9fb034

Please sign in to comment.