Merge pull request #1635 from huge-success/upgrade-websockets
Upgrade websockets, resolve incompatible issue between multidict and websockets
This commit is contained in:
commit
3f9c94ba4a
|
@ -5,8 +5,7 @@ from inspect import isawaitable
|
|||
from typing import Any, Awaitable, Callable, MutableMapping, Union
|
||||
from urllib.parse import quote
|
||||
|
||||
from multidict import CIMultiDict
|
||||
|
||||
from sanic.compat import Header
|
||||
from sanic.exceptions import InvalidUsage, ServerError
|
||||
from sanic.log import logger
|
||||
from sanic.request import Request
|
||||
|
@ -186,7 +185,7 @@ class ASGIApp:
|
|||
instance.transport.add_task = sanic_app.loop.create_task
|
||||
instance.transport.loop = sanic_app.loop
|
||||
|
||||
headers = CIMultiDict(
|
||||
headers = Header(
|
||||
[
|
||||
(key.decode("latin-1"), value.decode("latin-1"))
|
||||
for key, value in scope.get("headers", [])
|
||||
|
|
6
sanic/compat.py
Normal file
6
sanic/compat.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from multidict import CIMultiDict
|
||||
|
||||
|
||||
class Header(CIMultiDict):
|
||||
def get_all(self, key):
|
||||
return self.getall(key, default=[])
|
|
@ -4,8 +4,8 @@ from os import path
|
|||
from urllib.parse import quote_plus
|
||||
|
||||
from aiofiles import open as open_async
|
||||
from multidict import CIMultiDict
|
||||
|
||||
from sanic.compat import Header
|
||||
from sanic.cookies import CookieJar
|
||||
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.streaming_fn = streaming_fn
|
||||
self.status = status
|
||||
self.headers = CIMultiDict(headers or {})
|
||||
self.headers = Header(headers or {})
|
||||
self.chunked = chunked
|
||||
self._cookies = None
|
||||
|
||||
|
@ -164,7 +164,7 @@ class HTTPResponse(BaseHTTPResponse):
|
|||
self.body = body_bytes
|
||||
|
||||
self.status = status
|
||||
self.headers = CIMultiDict(headers or {})
|
||||
self.headers = Header(headers or {})
|
||||
self._cookies = None
|
||||
|
||||
def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None):
|
||||
|
|
|
@ -12,8 +12,8 @@ from time import time
|
|||
|
||||
from httptools import HttpRequestParser
|
||||
from httptools.parser.errors import HttpParserError
|
||||
from multidict import CIMultiDict
|
||||
|
||||
from sanic.compat import Header
|
||||
from sanic.exceptions import (
|
||||
HeaderExpectationFailed,
|
||||
InvalidUsage,
|
||||
|
@ -304,7 +304,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
def on_headers_complete(self):
|
||||
self.request = self.request_class(
|
||||
url_bytes=self.url,
|
||||
headers=CIMultiDict(self.headers),
|
||||
headers=Header(self.headers),
|
||||
version=self.parser.get_http_version(),
|
||||
method=self.parser.get_method().decode(),
|
||||
transport=self.transport,
|
||||
|
|
2
setup.py
2
setup.py
|
@ -80,7 +80,7 @@ requirements = [
|
|||
uvloop,
|
||||
ujson,
|
||||
"aiofiles>=0.3.0",
|
||||
"websockets>=6.0,<7.0",
|
||||
"websockets>=7.0,<8.0",
|
||||
"multidict>=4.0,<5.0",
|
||||
"requests-async==0.5.0",
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user