summaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorStephen Moore <stephen@delfick.com>2015-09-20 15:48:07 +1000
committerJoffrey F <joffrey@docker.com>2015-10-14 17:29:31 -0700
commit7f3692ceeda92ca3690394822cbd3c99378c0d7e (patch)
tree14cab5bb453d57b901ed0d1dbaa8d8d4f5cdb4ed /docker
parentb1f25317deae569d332cf5faaccda8710932e6ef (diff)
downloaddocker-py-7f3692ceeda92ca3690394822cbd3c99378c0d7e.tar.gz
Fix attach method over SSL connections
Signed-off-by: Stephen Moore <stephen@delfick.com>
Diffstat (limited to 'docker')
-rw-r--r--docker/client.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/docker/client.py b/docker/client.py
index d219472..d339f3b 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -188,6 +188,8 @@ class Client(
self._raise_for_status(response)
if six.PY3:
sock = response.raw._fp.fp.raw
+ if self.base_url.startswith("https://"):
+ sock = sock._sock
else:
sock = response.raw._fp.fp._sock
try:
@@ -244,10 +246,7 @@ class Client(
# Disable timeout on the underlying socket to prevent
# Read timed out(s) for long running processes
socket = self._get_raw_response_socket(response)
- if six.PY3:
- socket._sock.settimeout(None)
- else:
- socket.settimeout(None)
+ self._disable_socket_timeout(socket)
while True:
header = response.raw.read(constants.STREAM_HEADER_SIZE_BYTES)
@@ -276,6 +275,19 @@ class Client(
for out in response.iter_content(chunk_size=1, decode_unicode=True):
yield out
+ def _disable_socket_timeout(self, socket):
+ """ Depending on the combination of python version and whether we're
+ connecting over http or https, we might need to access _sock, which
+ may or may not exist; or we may need to just settimeout on socket
+ itself, which also may or may not have settimeout on it.
+
+ To avoid missing the correct one, we try both.
+ """
+ if hasattr(socket, "settimeout"):
+ socket.settimeout(None)
+ if hasattr(socket, "_sock") and hasattr(socket._sock, "settimeout"):
+ socket._sock.settimeout(None)
+
def _get_result(self, container, stream, res):
cont = self.inspect_container(container)
return self._get_result_tty(stream, res, cont['Config']['Tty'])