Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial proof-of-concept for uvicorn compatibility #2035

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
web_urldispatcher, web_ws)
from .abc import AbstractMatchInfo, AbstractRouter
from .frozenlist import FrozenList
from .http import HttpVersion # noqa
from .helpers import TimeService
from .http import HttpVersion, RawRequestMessage # noqa
from .log import access_logger, web_logger
from .signals import FuncSignal, PostSignal, PreSignal, Signal
from .web_exceptions import * # noqa
Expand Down Expand Up @@ -313,9 +314,32 @@ def _handle(self, request):
for app in match_info.apps])
return resp

def __call__(self):
"""gunicorn compatibility"""
return self
async def __call__(self, message, channels):
"""uvicorn compatibility"""
aio_message = RawRequestMessage(
method=message['method'],
path=message['path'],
version=message['http_version'],
headers=dict(message['headers']),
raw_headers=dict(message['headers']),
should_close=False,
compression=False,
upgrade=False,
chunked=False,
url=URL(message['path'])
)
protocol = channels['reply']._protocol
protocol._time_service = TimeService(self._loop)
request = self._make_request(aio_message, None, protocol, None, None)
response = await self._handle(request)
await channels['reply'].send({
'status': response.status,
'headers': [
(key.encode(), value.encode())
for key, value in response.headers.items()
],
'content': response.body
})

def __repr__(self):
return "<Application 0x{:x}>".format(id(self))
Expand Down