Skip to content

Commit 123c6d6

Browse files
committed
Update aiohttp async driver. Use native public aiohttp API
1 parent 04e7c4d commit 123c6d6

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/engineio/async_drivers/aiohttp.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import sys
3-
from urllib.parse import urlsplit
43

54
from aiohttp.web import Response, WebSocketResponse
65

@@ -22,31 +21,27 @@ def translate_request(request):
2221
"""This function takes the arguments passed to the request handler and
2322
uses them to generate a WSGI compatible environ dictionary.
2423
"""
25-
message = request._message
26-
payload = request._payload
27-
28-
uri_parts = urlsplit(message.path)
2924
environ = {
30-
'wsgi.input': payload,
25+
'wsgi.input': request.content,
3126
'wsgi.errors': sys.stderr,
3227
'wsgi.version': (1, 0),
3328
'wsgi.async': True,
3429
'wsgi.multithread': False,
3530
'wsgi.multiprocess': False,
3631
'wsgi.run_once': False,
3732
'SERVER_SOFTWARE': 'aiohttp',
38-
'REQUEST_METHOD': message.method,
39-
'QUERY_STRING': uri_parts.query or '',
40-
'RAW_URI': message.path,
41-
'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version,
33+
'REQUEST_METHOD': request.method,
34+
'QUERY_STRING': request.query_string or '',
35+
'RAW_URI': request.path_qs,
36+
'SERVER_PROTOCOL': 'HTTP/%s.%s' % request.version,
4237
'REMOTE_ADDR': '127.0.0.1',
4338
'REMOTE_PORT': '0',
4439
'SERVER_NAME': 'aiohttp',
4540
'SERVER_PORT': '0',
4641
'aiohttp.request': request
4742
}
4843

49-
for hdr_name, hdr_value in message.headers.items():
44+
for hdr_name, hdr_value in request.headers.items():
5045
hdr_name = hdr_name.upper()
5146
if hdr_name == 'CONTENT-TYPE':
5247
environ['CONTENT_TYPE'] = hdr_value
@@ -63,9 +58,7 @@ def translate_request(request):
6358

6459
environ['wsgi.url_scheme'] = environ.get('HTTP_X_FORWARDED_PROTO', 'http')
6560

66-
path_info = uri_parts.path
67-
68-
environ['PATH_INFO'] = path_info
61+
environ['PATH_INFO'] = request.path
6962
environ['SCRIPT_NAME'] = ''
7063

7164
return environ

0 commit comments

Comments
 (0)