-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Websocket\Server; | ||
|
||
use Amp\Http; | ||
use Amp\Http\Server\Request; | ||
use Amp\Http\Server\Response; | ||
use Amp\Websocket\Compression\Rfc7692CompressionFactory; | ||
use Amp\Websocket\Compression\WebsocketCompressionContext; | ||
|
||
final class Rfc7692CompressionNegotiator implements WebsocketCompressionNegotiator | ||
{ | ||
private readonly Rfc7692CompressionFactory $compressionContextFactory; | ||
|
||
public function __construct() | ||
{ | ||
$this->compressionContextFactory = new Rfc7692CompressionFactory(); | ||
} | ||
|
||
public function negotiateCompression(Request $request, Response $response): ?WebsocketCompressionContext | ||
{ | ||
$extensions = Http\splitHeader($request, 'sec-websocket-extensions') ?? []; | ||
foreach ($extensions as $extension) { | ||
if ($compressionContext = $this->compressionContextFactory->fromClientHeader($extension, $headerLine)) { | ||
/** @psalm-suppress PossiblyNullArgument */ | ||
$response->setHeader('sec-websocket-extensions', $headerLine); | ||
|
||
return $compressionContext; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Websocket\Server; | ||
|
||
use Amp\Http\Server\Request; | ||
use Amp\Http\Server\Response; | ||
use Amp\Websocket\Compression\WebsocketCompressionContext; | ||
|
||
interface WebsocketCompressionNegotiator | ||
{ | ||
/** | ||
* Examine the given {@see Request} and {@see Response} returned from a {@see WebsocketAcceptor} to determine | ||
* if compression should be enabled for the client. If so, return an instance of {@see WebsocketCompressionContext} | ||
* and modify the {@see Response} object accordingly. | ||
*/ | ||
public function negotiateCompression(Request $request, Response $response): ?WebsocketCompressionContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters