summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2016-07-08 12:12:23 +0200
committerDavid Gageot <david@gageot.net>2016-07-08 17:25:46 +0200
commit2ed97bb044e9854171c6261621d90323a659f59d (patch)
treeaeb495974e0e5558bbcd275957cd0fca7a0924a5
parent29faf56ed359e42380596aac56fc6fb53c5347b9 (diff)
downloaddocker-py-2ed97bb044e9854171c6261621d90323a659f59d.tar.gz
Add hijack hints for non-detached exec api calls
Signed-off-by: David Gageot <david@gageot.net>
-rw-r--r--docker/api/exec_api.py10
-rw-r--r--tests/unit/exec_test.py32
2 files changed, 39 insertions, 3 deletions
diff --git a/docker/api/exec_api.py b/docker/api/exec_api.py
index f0e4afa..ad2cd33 100644
--- a/docker/api/exec_api.py
+++ b/docker/api/exec_api.py
@@ -66,8 +66,16 @@ class ExecApiMixin(object):
'Detach': detach
}
+ headers = {} if detach else {
+ 'Connection': 'Upgrade',
+ 'Upgrade': 'tcp'
+ }
+
res = self._post_json(
- self._url('/exec/{0}/start', exec_id), data=data, stream=stream
+ self._url('/exec/{0}/start', exec_id),
+ headers=headers,
+ data=data,
+ stream=stream
)
if socket:
diff --git a/tests/unit/exec_test.py b/tests/unit/exec_test.py
index 3007799..6ba2a3d 100644
--- a/tests/unit/exec_test.py
+++ b/tests/unit/exec_test.py
@@ -51,8 +51,36 @@ class ExecTest(DockerClientTest):
}
)
- self.assertEqual(args[1]['headers'],
- {'Content-Type': 'application/json'})
+ self.assertEqual(
+ args[1]['headers'], {
+ 'Content-Type': 'application/json',
+ 'Connection': 'Upgrade',
+ 'Upgrade': 'tcp'
+ }
+ )
+
+ def test_exec_start_detached(self):
+ self.client.exec_start(fake_api.FAKE_EXEC_ID, detach=True)
+
+ args = fake_request.call_args
+ self.assertEqual(
+ args[0][1], url_prefix + 'exec/{0}/start'.format(
+ fake_api.FAKE_EXEC_ID
+ )
+ )
+
+ self.assertEqual(
+ json.loads(args[1]['data']), {
+ 'Tty': False,
+ 'Detach': True
+ }
+ )
+
+ self.assertEqual(
+ args[1]['headers'], {
+ 'Content-Type': 'application/json'
+ }
+ )
def test_exec_inspect(self):
self.client.exec_inspect(fake_api.FAKE_EXEC_ID)