diff --git a/tests/test_api_client/test_rest_response.py b/tests/test_api_client/test_rest_response.py new file mode 100644 index 00000000..4dcacc2b --- /dev/null +++ b/tests/test_api_client/test_rest_response.py @@ -0,0 +1,23 @@ +from xero_python.rest import RESTResponse + + +class DummyResponse: + def __init__(self): + self.status = 200 + self.reason = "OK" + self.data = b"{}" + self.headers = { + "Content-Disposition": "attachment; filename=test.json", + "X-Trace-Id": "abc123", + } + + +def test_rest_response_reads_headers_without_deprecated_urllib3_helpers(): + response = RESTResponse(DummyResponse()) + + assert response.getheaders() == { + "Content-Disposition": "attachment; filename=test.json", + "X-Trace-Id": "abc123", + } + assert response.getheader("Content-Disposition") == "attachment; filename=test.json" + assert response.getheader("Missing", "fallback") == "fallback" diff --git a/xero_python/rest.py b/xero_python/rest.py index db0e84a6..7598deb0 100644 --- a/xero_python/rest.py +++ b/xero_python/rest.py @@ -45,11 +45,11 @@ def text(self): def getheaders(self): """Returns a dictionary of the response headers.""" - return self.urllib3_response.getheaders() + return dict(self.urllib3_response.headers.items()) def getheader(self, name, default=None): """Returns a given response header.""" - return self.urllib3_response.getheader(name, default) + return self.urllib3_response.headers.get(name, default) class RESTClientObject(object):