From b397637bb979566183116b2663ec2c1ef02246a9 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Thu, 18 Jul 2019 19:57:17 -0700 Subject: [PATCH] bugfix: fix incompatible api between multidict and websockets, and bump up websockets version to match uvicorn --- sanic/compat.py | 7 +++++++ sanic/server.py | 4 ++-- setup.py | 2 +- tox.ini | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 sanic/compat.py diff --git a/sanic/compat.py b/sanic/compat.py new file mode 100644 index 00000000..30aec0a7 --- /dev/null +++ b/sanic/compat.py @@ -0,0 +1,7 @@ +from multidict import CIMultiDict + + +class Header(CIMultiDict): + + def get_all(self, key): + return self.getall(key, []) diff --git a/sanic/server.py b/sanic/server.py index 5057f0b5..e1d7a3d2 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -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, diff --git a/setup.py b/setup.py index 751f1549..a574ca3e 100644 --- a/setup.py +++ b/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", ] diff --git a/tox.ini b/tox.ini index 3ff30ef8..ab8a099e 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = gunicorn pytest-benchmark uvicorn - websockets>=6.0,<7.0 + websockets>=7.0,<8.0 commands = pytest {posargs:tests --cov sanic} - coverage combine --append