Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Support for TCP Hijack in execStartStream #63

Open
wants to merge 7 commits into
base: 1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Clue\React\Docker\Io\StreamingParser;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
use React\Socket\ConnectionInterface;
use React\Stream\ReadableStreamInterface;
use Rize\UriTemplate;

Expand Down Expand Up @@ -1294,14 +1295,19 @@ public function execStartDetached($exec, $tty = false)
*
* @param string $exec exec ID
* @param boolean $tty tty mode
* @param boolean $hijack hijack tcp connection
* @param string $stderrEvent custom event to emit for STDERR data (otherwise emits as "data")
* @return ReadableStreamInterface stream of exec data
* @return ReadableStreamInterface|PromiseInterface<ConnectionInterface> Readable stream of exec data or Hijacked Connection in TTY mode
* @link https://docs.docker.com/engine/api/v1.40/#operation/ExecStart
* @see self::execStart()
* @see self::execStartDetached()
*/
public function execStartStream($exec, $tty = false, $stderrEvent = null)
public function execStartStream($exec, $tty = false, $stderrEvent = null, $hijack = false)
{
if ($hijack) {
return $this->execStartStreamUpgrade($exec, $stderrEvent);
}

$stream = $this->streamingParser->parsePlainStream(
$this->browser->withOptions(array('streaming' => true))->post(
$this->uri->expand(
Expand All @@ -1327,6 +1333,26 @@ public function execStartStream($exec, $tty = false, $stderrEvent = null)
return $stream;
}

protected function execStartStreamUpgrade($exec, $tty = false)
{
return $this->browser->withOptions(array('streaming' => true, 'upgrade' => true))->post(
$this->uri->expand(
'/exec/{exec}/start',
array(
'exec' => $exec
)
),
array(
'Content-Type' => 'application/json',
'Connection' => 'Upgrade',
'Upgrade' => 'tcp',
),
$this->json(array(
'Tty' => !!$tty
))
);
}

/**
* Resizes the tty session used by the exec command id.
*
Expand Down