forked from beluga-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerAttachWebsocket.php
More file actions
39 lines (33 loc) · 1.18 KB
/
ContainerAttachWebsocket.php
File metadata and controls
39 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Docker\Endpoint;
use Docker\API\Endpoint\ContainerAttachWebsocket as BaseEndpoint;
use Docker\Stream\AttachWebsocketStream;
use Docker\Stream\DockerRawStream;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Serializer\SerializerInterface;
class ContainerAttachWebsocket extends BaseEndpoint
{
public function getExtraHeaders(): array
{
return array_merge(
parent::getExtraHeaders(),
[
'Host' => 'localhost',
'Origin' => 'php://docker-php',
'Upgrade' => 'websocket',
'Connection' => 'Upgrade',
'Sec-WebSocket-Version' => '13',
'Sec-WebSocket-Key' => base64_encode(uniqid()),
]
);
}
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string
$contentType = null)
{
if (200 === $response->getStatusCode() && DockerRawStream::HEADER === $contentType) {
return new AttachWebsocketStream($response->getBody());
}
return parent::transformResponseBody($response, $serializer, $contentType);
}
}