Skip to content

Commit

Permalink
Merge 4a96331 into cf5b383
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic182 committed Dec 11, 2020
2 parents cf5b383 + 4a96331 commit 9d9dad4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions aiosonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class HttpHeaders(CaseInsensitiveDict):
@staticmethod
def _clear_line(line: bytes):
"""Clear readed line."""
return line.rstrip().split(b': ', 1)
return line.rstrip().decode().split(': ', 1)


#: Headers
Expand Down Expand Up @@ -163,13 +163,13 @@ async def _set_response_headers(self, iterator):
self._set_header(*header_tuple)

# set cookies in response
if header_tuple[0].lower() == b'set-cookie':
if header_tuple[0].lower() == 'set-cookie':
self._update_cookies(header_tuple)

def _update_cookies(self, header_tuple):
"""Update jar of cookies."""
self.cookies = self.cookies or cookies.SimpleCookie()
self.cookies.load(header_tuple[1].decode())
self.cookies.load(header_tuple[1])

def _set_connection(self, connection: Connection):
"""Set header to response."""
Expand All @@ -182,9 +182,9 @@ def status_code(self) -> int:

def _set_body(self, data):
"""Set body."""
if self.compressed == b'gzip':
if self.compressed == 'gzip':
self.body += gzip_decompress(data)
elif self.compressed == b'deflate':
elif self.compressed == 'deflate':
self.body += zlib_decompress(data)
else:
self.body += data
Expand Down Expand Up @@ -442,10 +442,10 @@ async def _do_request(urlparsed: ParseResult,

await response._set_response_headers(_parse_headers_iterator(connection))

size = response.headers.get(b'content-length')
chunked = response.headers.get(b'transfer-encoding', '') == b'chunked'
keepalive = b'close' not in response.headers.get(b'connection', b'')
response.compressed = response.headers.get(b'content-encoding', '')
size = response.headers.get('content-length')
chunked = response.headers.get('transfer-encoding', '') == 'chunked'
keepalive = 'close' not in response.headers.get('connection', '')
response.compressed = response.headers.get('content-encoding', '')

if size:
response._set_body(await connection.reader.readexactly(int(size)))
Expand Down Expand Up @@ -703,7 +703,7 @@ async def request(self,

max_redirects = 30
# if class or request method has false, it will be false
verify_ssl = verify and self.verify_ssl
verify_ssl = verify and self.verify_ssl
while True:
headers_data = partial(_get_header_data,
url=urlparsed,
Expand Down Expand Up @@ -733,7 +733,7 @@ async def request(self,
urlparsed.hostname, headers)

parsed_full_url = _get_url_parsed(
response.headers[b'location'].decode())
response.headers['location'])

# if full url, will have scheme
if parsed_full_url.scheme:
Expand All @@ -742,7 +742,7 @@ async def request(self,
urlparsed = _get_url_parsed(
url.replace(
urlparsed.path,
response.headers[b'location'].decode()))
response.headers['location']))
else:
return response
except ConnectTimeout:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def test_headers_retrival():

def test_headers_retrival_common():
"""Test reading header with more than one ":" char ocurrence."""
res = [b'Authorization', b'Bearer foobar']
sample_header = b': '.join(res) + b'\r\n'
res = ['Authorization', 'Bearer foobar']
sample_header = b': '.join([item.encode() for item in res]) + b'\r\n'
assert HttpHeaders._clear_line(sample_header) == res

0 comments on commit 9d9dad4

Please sign in to comment.