bugfix: replace CIMultiDict with compat.Header in all places

This commit is contained in:
Yun Xu 2019-07-18 20:11:25 -07:00
parent b397637bb9
commit 5dafa9a170
3 changed files with 7 additions and 9 deletions

View File

@ -5,8 +5,7 @@ from inspect import isawaitable
from typing import Any, Awaitable, Callable, MutableMapping, Union from typing import Any, Awaitable, Callable, MutableMapping, Union
from urllib.parse import quote from urllib.parse import quote
from multidict import CIMultiDict from sanic.compat import Header
from sanic.exceptions import InvalidUsage, ServerError from sanic.exceptions import InvalidUsage, ServerError
from sanic.log import logger from sanic.log import logger
from sanic.request import Request from sanic.request import Request
@ -186,7 +185,7 @@ class ASGIApp:
instance.transport.add_task = sanic_app.loop.create_task instance.transport.add_task = sanic_app.loop.create_task
instance.transport.loop = sanic_app.loop instance.transport.loop = sanic_app.loop
headers = CIMultiDict( headers = Header(
[ [
(key.decode("latin-1"), value.decode("latin-1")) (key.decode("latin-1"), value.decode("latin-1"))
for key, value in scope.get("headers", []) for key, value in scope.get("headers", [])

View File

@ -2,6 +2,5 @@ from multidict import CIMultiDict
class Header(CIMultiDict): class Header(CIMultiDict):
def get_all(self, key):
def get_all(self, key): return self.getall(key, default=[])
return self.getall(key, [])

View File

@ -4,8 +4,8 @@ from os import path
from urllib.parse import quote_plus from urllib.parse import quote_plus
from aiofiles import open as open_async from aiofiles import open as open_async
from multidict import CIMultiDict
from sanic.compat import Header
from sanic.cookies import CookieJar from sanic.cookies import CookieJar
from sanic.helpers import STATUS_CODES, has_message_body, remove_entity_headers from sanic.helpers import STATUS_CODES, has_message_body, remove_entity_headers
@ -74,7 +74,7 @@ class StreamingHTTPResponse(BaseHTTPResponse):
self.content_type = content_type self.content_type = content_type
self.streaming_fn = streaming_fn self.streaming_fn = streaming_fn
self.status = status self.status = status
self.headers = CIMultiDict(headers or {}) self.headers = Header(headers or {})
self.chunked = chunked self.chunked = chunked
self._cookies = None self._cookies = None
@ -164,7 +164,7 @@ class HTTPResponse(BaseHTTPResponse):
self.body = body_bytes self.body = body_bytes
self.status = status self.status = status
self.headers = CIMultiDict(headers or {}) self.headers = Header(headers or {})
self._cookies = None self._cookies = None
def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None): def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None):