Skip to content

Commit

Permalink
CaseInsensitiveDict for request and response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanjaneyuluIdavalapati committed Jul 3, 2018
1 parent 04810cf commit 8e802d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions kwikapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import concurrent.futures

from deeputil import Dummy, AttrDict, generate_random_string
from requests.structures import CaseInsensitiveDict

from .protocols import PROTOCOLS, DEFAULT_PROTOCOL
from .apidoc import ApiDoc
Expand Down Expand Up @@ -126,7 +127,8 @@ class MockRequest(BaseRequest):

def __init__(self, **kwargs):
super().__init__()
self._request = dict(method='GET', body='', headers={})
self._request = dict(method='GET', body='',
headers=CaseInsensitiveDict())
self._request.update(kwargs)
self.response = MockResponse()

Expand All @@ -149,7 +151,7 @@ def headers(self):
class MockResponse(BaseResponse):
def __init__(self):
super().__init__()
self.headers = {}
self.headers = CaseInsensitiveDict()
self.raw_response = None

def write(self, data, protocol, stream=False):
Expand Down
5 changes: 3 additions & 2 deletions kwikapi/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import socket
from urllib.parse import urljoin, urlparse, urlencode
import urllib.request
from requests.structures import CaseInsensitiveDict

from deeputil import Dummy, ExpiringCache

Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(self, url, version=None, protocol=DEFAULT_PROTOCOL,
self._request = request
self._timeout = timeout
self._dnscache = dnscache
self._headers = headers
self._headers = CaseInsensitiveDict(headers) if headers is not None else None
self._log = log

if not self._dnscache:
Expand All @@ -74,7 +75,7 @@ def _copy(self, **kwargs):
return Client(**_kwargs)

def _prepare_request(self, post_body, get_params=None):
headers = (self._headers or {}).copy()
headers = (self._headers or CaseInsensitiveDict()).copy()

if self._request:
for hk, hv in self._request.headers.items():
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
],
extras_require={
'django': ['kwikapi-django==0.2.2'],
'tornado': ['kwikapi-tornado==0.2.5'],
'all': ['kwikapi-django==0.2.2', 'kwikapi-tornado==0.2.5']
'tornado': ['kwikapi-tornado==0.2.6'],
'all': ['kwikapi-django==0.2.2', 'kwikapi-tornado==0.2.6']
},
classifiers=[
'Environment :: Web Environment',
Expand Down

0 comments on commit 8e802d7

Please sign in to comment.