Skip to content

Commit

Permalink
Make modifications to response_class as small as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed May 3, 2023
1 parent 698d544 commit df8a492
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions plugins/module_utils/_api/transport/unixconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import socket

from ansible.module_utils.six import PY2
from ansible.module_utils.six.moves import http_client as httplib

from .basehttpadapter import BaseHTTPAdapter
from .. import constants
Expand All @@ -24,17 +23,6 @@
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer


class UnixHTTPResponse(httplib.HTTPResponse, object):
def __init__(self, sock, *args, **kwargs):
disable_buffering = kwargs.pop('disable_buffering', False)
if PY2:
# FIXME: We may need to disable buffering on Py3 as well,
# but there's no clear way to do it at the moment. See:
# https://github.com/docker/docker-py/issues/1799
kwargs['buffering'] = not disable_buffering
super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)


class UnixHTTPConnection(urllib3_connection.HTTPConnection, object):

def __init__(self, base_url, unix_socket, timeout=60):
Expand All @@ -58,10 +46,13 @@ def putheader(self, header, *values):
self.disable_buffering = True

def response_class(self, sock, *args, **kwargs):
if self.disable_buffering:
kwargs['disable_buffering'] = True
if PY2:
# FIXME: We may need to disable buffering on Py3 as well,
# but there's no clear way to do it at the moment. See:
# https://github.com/docker/docker-py/issues/1799
kwargs['buffering'] = not self.disable_buffering

return UnixHTTPResponse(sock, *args, **kwargs)
return super(UnixHTTPConnection, self).response_class(sock, *args, **kwargs)


class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
Expand Down

0 comments on commit df8a492

Please sign in to comment.