diff --git a/src/Client.php b/src/Client.php index 4d87863..d448358 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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; @@ -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 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( @@ -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. *