Skip to content

Commit

Permalink
Introduce separate push event for pushed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Aug 30, 2023
1 parent bf5fa72 commit ac99861
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ static function () {
);

events()->requestStart($request);
events()->push($request);
events()->requestHeaderStart($request, $stream->stream);
events()->requestHeaderEnd($request, $stream->stream);
events()->requestBodyStart($request, $stream->stream);
Expand Down
5 changes: 5 additions & 0 deletions src/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function networkInterceptorEnd(Request $request, NetworkInterceptor $inte
*/
public function connectionAcquired(Request $request, Connection $connection): void;

/**
* Called after the server initiated a push.
*/
public function push(Request $request): void;

/**
* Called before the request headers are sent.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/EventListener/LogHttpArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,9 @@ public function networkInterceptorEnd(Request $request, NetworkInterceptor $inte
{
// nothing to do
}

public function push(Request $request): void
{
// nothing to do
}
}
14 changes: 13 additions & 1 deletion src/Internal/EventInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ public function connectionAcquired(Request $request, Connection $connection): vo
$this->invoke($request, fn (EventListener $eventListener) => $eventListener->connectionAcquired($request, $connection));
}

public function push(Request $request): void
{
$previousPhase = self::getPhase($request);
if ($previousPhase !== Phase::Blocked) {
throw new \Error('Invalid request phase transition from ' . $previousPhase->name . ' to Push');
}

$this->requestPhase[$request] = Phase::Push;

$this->invoke($request, fn (EventListener $eventListener) => $eventListener->push($request));
}

public function requestHeaderStart(Request $request, Stream $stream): void
{
$previousPhase = self::getPhase($request);
if ($previousPhase !== Phase::Connected && $previousPhase !== Phase::Blocked) {
if ($previousPhase !== Phase::Connected && $previousPhase !== Phase::Push) {
throw new \Error('Invalid request phase transition from ' . $previousPhase->name . ' to RequestHeaders');
}

Expand Down
1 change: 1 addition & 0 deletions src/Internal/Phase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum Phase
case Unprocessed;
case Blocked;
case Connected;
case Push;
case RequestHeaders;
case RequestBody;
case ServerProcessing;
Expand Down

0 comments on commit ac99861

Please sign in to comment.