diff --git a/ldclient/impl/datasource/feature_requester.py b/ldclient/impl/datasource/feature_requester.py index dbb4f16c..98d07bb8 100644 --- a/ldclient/impl/datasource/feature_requester.py +++ b/ldclient/impl/datasource/feature_requester.py @@ -42,7 +42,7 @@ def get_all_data(self): from_cache = True else: data = json.loads(r.data.decode('UTF-8')) - etag = r.getheader('ETag') + etag = r.headers.get('ETag') from_cache = False if etag is not None: self._cache[uri] = CacheEntry(data=data, etag=etag) diff --git a/ldclient/impl/events/event_processor.py b/ldclient/impl/events/event_processor.py index bf246153..b246bcd6 100644 --- a/ldclient/impl/events/event_processor.py +++ b/ldclient/impl/events/event_processor.py @@ -373,7 +373,7 @@ def _trigger_flush(self): pass def _handle_response(self, r): - server_date_str = r.getheader('Date') + server_date_str = r.headers.get('Date') if server_date_str is not None: server_date = parsedate(server_date_str) if server_date is not None: diff --git a/testing/stub_util.py b/testing/stub_util.py index 834f0e71..8bddcdad 100644 --- a/testing/stub_util.py +++ b/testing/stub_util.py @@ -72,17 +72,28 @@ def get_all_data(self): raise self.exception return self.all_data + +class _MockHTTPHeaderDict(dict): + def __init__(self, d): + super().__init__({k.lower(): v for k, v in d.items()}) + + def get(self, key, default=None): + return super().get(key.lower(), default) + + class MockResponse: def __init__(self, status, headers): self._status = status - self._headers = headers + self._headers = _MockHTTPHeaderDict(headers) @property def status(self): return self._status - def getheader(self, name): - return self._headers.get(name.lower()) + @property + def headers(self): + return self._headers + class MockHttp: def __init__(self):