diff --git a/docker/api/exec_api.py b/docker/api/exec_api.py index f0e4afa6..ad2cd331 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 3007799c..6ba2a3dd 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)