From 517601b38ceebffb91fbaec45b104e4c615d26e5 Mon Sep 17 00:00:00 2001 From: bosunski Date: Sun, 26 Jul 2020 12:24:16 +0100 Subject: [PATCH 1/7] Begin execStreamHijak --- composer.json | 13 +++++++++++-- src/Client.php | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9a0abe3..91d413f 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "php": ">=5.3", - "clue/buzz-react": "^2.0", + "react/http": "dev-master", "clue/json-stream": "^0.1", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "react/promise": "^2.0 || ^1.1", @@ -32,5 +32,14 @@ "clue/caret-notation": "^0.2", "clue/tar-react": "^0.2", "phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35" - } + }, + "repositories": [ + { + "type": "vcs", + "url": "/Users/mac/Projects/oss/http", + "options": { + "symlink": true + } + } + ] } diff --git a/src/Client.php b/src/Client.php index 4d87863..957f3e9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,7 +2,7 @@ namespace Clue\React\Docker; -use Clue\React\Buzz\Browser; +use React\Http\Browser; use Clue\React\Docker\Io\ResponseParser; use Clue\React\Docker\Io\StreamingParser; use React\EventLoop\LoopInterface; From 4bb963628eca1601d86e99c08e87743adcff7f00 Mon Sep 17 00:00:00 2001 From: bosunski Date: Sun, 26 Jul 2020 12:28:29 +0100 Subject: [PATCH 2/7] Begin execStreamHijak --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91d413f..76663ce 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,8 @@ "keywords": ["Docker", "container", "ReactPHP", "async"], "homepage": "https://github.com/clue/reactphp-docker", "license": "MIT", + "minimum-stability": "dev", + "prefer-stable": true, "authors": [ { "name": "Christian Lück", @@ -18,7 +20,7 @@ }, "require": { "php": ">=5.3", - "react/http": "dev-master", + "react/http": "dev-writable", "clue/json-stream": "^0.1", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "react/promise": "^2.0 || ^1.1", From 0f1cf2021940620eab3bc35cde161a592b1c06db Mon Sep 17 00:00:00 2001 From: bosunski Date: Mon, 27 Jul 2020 20:24:20 +0100 Subject: [PATCH 3/7] Add option for Hijack in execStartStream --- src/Client.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 957f3e9..6c272ad 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, $hijack = false, $stderrEvent = null) { + if ($hijack) { + return $this->execStartStreamUpgrade($exec, $stderrEvent); + } + $stream = $this->streamingParser->parsePlainStream( $this->browser->withOptions(array('streaming' => true))->post( $this->uri->expand( @@ -1327,6 +1333,27 @@ public function execStartStream($exec, $tty = false, $stderrEvent = null) return $stream; } + protected function execStartStreamUpgrade($exec, $stderrEvent = null) + { + return $this->browser->withOptions(array('streaming' => true, 'hijack' => true))->requestUpgrade( + "POST", + $this->uri->expand( + '/exec/{exec}/start', + array( + 'exec' => $exec + ) + ), + array( + 'Content-Type' => 'application/json', + 'Connection' => 'Upgrade', + 'Upgrade' => 'tcp', + ), + $this->json(array( + 'Tty' => true + )) + ); + } + /** * Resizes the tty session used by the exec command id. * From 318df7c6938498cda460be94af9e176727094e0a Mon Sep 17 00:00:00 2001 From: bosunski Date: Mon, 27 Jul 2020 20:26:59 +0100 Subject: [PATCH 4/7] Reverted composer.json --- composer.json | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 76663ce..9a0abe3 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,6 @@ "keywords": ["Docker", "container", "ReactPHP", "async"], "homepage": "https://github.com/clue/reactphp-docker", "license": "MIT", - "minimum-stability": "dev", - "prefer-stable": true, "authors": [ { "name": "Christian Lück", @@ -20,7 +18,7 @@ }, "require": { "php": ">=5.3", - "react/http": "dev-writable", + "clue/buzz-react": "^2.0", "clue/json-stream": "^0.1", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "react/promise": "^2.0 || ^1.1", @@ -34,14 +32,5 @@ "clue/caret-notation": "^0.2", "clue/tar-react": "^0.2", "phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35" - }, - "repositories": [ - { - "type": "vcs", - "url": "/Users/mac/Projects/oss/http", - "options": { - "symlink": true - } - } - ] + } } From 091f172c4ba009ca1bd08713c0b44b95957ddd58 Mon Sep 17 00:00:00 2001 From: bosunski Date: Mon, 27 Jul 2020 20:31:31 +0100 Subject: [PATCH 5/7] Reverted Namespace --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 6c272ad..f838e94 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,7 +2,7 @@ namespace Clue\React\Docker; -use React\Http\Browser; +use Clue\React\Buzz\Browser; use Clue\React\Docker\Io\ResponseParser; use Clue\React\Docker\Io\StreamingParser; use React\EventLoop\LoopInterface; From c635fbbccc3be7b5cf594713f5a3dde276f347c7 Mon Sep 17 00:00:00 2001 From: bosunski Date: Mon, 27 Jul 2020 20:49:29 +0100 Subject: [PATCH 6/7] replaced requestUpgrade with post() --- src/Client.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index f838e94..ee421e4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1333,10 +1333,9 @@ public function execStartStream($exec, $tty = false, $hijack = false, $stderrEve return $stream; } - protected function execStartStreamUpgrade($exec, $stderrEvent = null) + protected function execStartStreamUpgrade($exec, $tty = false) { - return $this->browser->withOptions(array('streaming' => true, 'hijack' => true))->requestUpgrade( - "POST", + return $this->browser->withOptions(array('streaming' => true, 'upgrade' => true))->post( $this->uri->expand( '/exec/{exec}/start', array( @@ -1349,7 +1348,7 @@ protected function execStartStreamUpgrade($exec, $stderrEvent = null) 'Upgrade' => 'tcp', ), $this->json(array( - 'Tty' => true + 'Tty' => !!$tty )) ); } From e94bbd9bfcce2fd69063256f3eaccc335a9b32ba Mon Sep 17 00:00:00 2001 From: bosunski Date: Mon, 27 Jul 2020 21:57:45 +0100 Subject: [PATCH 7/7] Changed paramter order --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index ee421e4..d448358 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1302,7 +1302,7 @@ public function execStartDetached($exec, $tty = false) * @see self::execStart() * @see self::execStartDetached() */ - public function execStartStream($exec, $tty = false, $hijack = false, $stderrEvent = null) + public function execStartStream($exec, $tty = false, $stderrEvent = null, $hijack = false) { if ($hijack) { return $this->execStartStreamUpgrade($exec, $stderrEvent);