diff options
author | Cédric Krier <cedk@users.noreply.github.com> | 2019-02-19 16:18:50 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-02-19 16:18:50 (GMT) |
commit | beda52ed36e701e45f22903fc4d3bec0d085b25b (patch) | |
tree | e96db330072912b7dce724ffdc547291bae4758a /Lib/xmlrpc | |
parent | 513e9b4425d09cb0b4889495f9b93dda341b8dd0 (diff) | |
download | cpython-beda52ed36e701e45f22903fc4d3bec0d085b25b.zip cpython-beda52ed36e701e45f22903fc4d3bec0d085b25b.tar.gz cpython-beda52ed36e701e45f22903fc4d3bec0d085b25b.tar.bz2 |
bpo-35153: Add headers parameter to xmlrpc.client.ServerProxy (GH-10308)
Allow to add HTTP headers to XML-RPC requests sent to the server.
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r-- | Lib/xmlrpc/client.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index ddab76f..a0e923a 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1131,10 +1131,12 @@ class Transport: # that they can decode such a request encode_threshold = None #None = don't encode - def __init__(self, use_datetime=False, use_builtin_types=False): + def __init__(self, use_datetime=False, use_builtin_types=False, + *, headers=()): self._use_datetime = use_datetime self._use_builtin_types = use_builtin_types self._connection = (None, None) + self._headers = list(headers) self._extra_headers = [] ## @@ -1265,7 +1267,7 @@ class Transport: def send_request(self, host, handler, request_body, debug): connection = self.make_connection(host) - headers = self._extra_headers[:] + headers = self._headers + self._extra_headers if debug: connection.set_debuglevel(1) if self.accept_gzip_encoding and gzip: @@ -1347,9 +1349,11 @@ class Transport: class SafeTransport(Transport): """Handles an HTTPS transaction to an XML-RPC server.""" - def __init__(self, use_datetime=False, use_builtin_types=False, *, - context=None): - super().__init__(use_datetime=use_datetime, use_builtin_types=use_builtin_types) + def __init__(self, use_datetime=False, use_builtin_types=False, + *, headers=(), context=None): + super().__init__(use_datetime=use_datetime, + use_builtin_types=use_builtin_types, + headers=headers) self.context = context # FIXME: mostly untested @@ -1409,7 +1413,7 @@ class ServerProxy: def __init__(self, uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False, use_builtin_types=False, - *, context=None): + *, headers=(), context=None): # establish a "logical" server connection # get the url @@ -1429,6 +1433,7 @@ class ServerProxy: extra_kwargs = {} transport = handler(use_datetime=use_datetime, use_builtin_types=use_builtin_types, + headers=headers, **extra_kwargs) self.__transport = transport |