-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
DO NOT MERGE: debug test_unsupported_upgrade #7960
Changes from 8 commits
a431dff
22b56c2
591f398
d2f177f
86b0eae
45497d2
4601f43
d897aa2
5c6b4da
1673a5f
310b342
0ded1a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,9 @@ def feed_data( | |
data_len = len(data) | ||
start_pos = 0 | ||
loop = self.loop | ||
import pprint | ||
|
||
pprint.pprint(["feed_data", data]) | ||
|
||
while start_pos < data_len: | ||
# read HTTP message (request/response line + headers), \r\n\r\n | ||
|
@@ -347,17 +350,26 @@ def get_content_length() -> Optional[int]: | |
if SEC_WEBSOCKET_KEY1 in msg.headers: | ||
raise InvalidHeader(SEC_WEBSOCKET_KEY1) | ||
|
||
self._upgraded = msg.upgrade | ||
|
||
method = getattr(msg, "method", self.method) | ||
# code is only present on responses | ||
code = getattr(msg, "code", 0) | ||
|
||
import pprint | ||
|
||
pprint.pprint(["upgraded", msg.upgrade, msg]) | ||
# If response is not 101 than we didn't upgrade | ||
# if its 0 its not a response | ||
self._upgraded = msg.upgrade and code in (0, 101) | ||
|
||
assert self.protocol is not None | ||
# calculate payload | ||
empty_body = status_code_must_be_empty_body(code) or bool( | ||
method and method_must_be_empty_body(method) | ||
) | ||
import pprint | ||
|
||
pprint.pprint(["empty_body", empty_body, code, msg.upgrade]) | ||
# self._upgraded=False | ||
if not empty_body and ( | ||
(length is not None and length > 0) | ||
or msg.chunked | ||
|
@@ -514,6 +526,9 @@ def parse_headers( | |
close_conn = False | ||
# https://www.rfc-editor.org/rfc/rfc9110.html#name-101-switching-protocols | ||
elif v == "upgrade" and headers.get(hdrs.UPGRADE): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the source of the problem for #6446? Just because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you think you can provide a fix, that'd be great. I believe there is already an xfail test from that issue, so as long as you can get that test passing.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One problem at a time for this newbie... Brotli first 😉 |
||
import pprint | ||
|
||
pprint.pprint(["upgrade", headers.get(hdrs.UPGRADE)]) | ||
upgrade = True | ||
|
||
# encoding | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# type: ignore | ||
import asyncio | ||
import sys | ||
from contextlib import suppress | ||
from typing import Any | ||
from unittest import mock | ||
|
@@ -8,6 +9,11 @@ | |
|
||
from aiohttp import client, helpers, web | ||
|
||
if sys.version_info >= (3, 11): | ||
import asyncio as async_timeout | ||
else: | ||
import async_timeout | ||
|
||
|
||
async def test_simple_server(aiohttp_raw_server: Any, aiohttp_client: Any) -> None: | ||
async def handler(request): | ||
|
@@ -31,13 +37,29 @@ | |
# don't fail if a client probes for an unsupported protocol upgrade | ||
# https://github.com/aio-libs/aiohttp/issues/6446#issuecomment-999032039 | ||
async def handler(request: web.Request): | ||
return web.Response(body=await request.read()) | ||
try: | ||
import pprint | ||
|
||
pprint.pprint(["handler called"]) | ||
async with async_timeout.timeout(10): | ||
result = await request.read() | ||
pprint.pprint(["handler read", result]) | ||
return web.Response(body=result) | ||
except Exception as e: | ||
import pprint | ||
|
||
pprint.pprint(["handler except", e]) | ||
raise | ||
|
||
upgrade_headers = {"Connection": "Upgrade", "Upgrade": "unsupported_proto"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what is parsing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assume that would be handled in the parsers (i.e. llhttp or http_parser.py, depending on whether extensions are enabled). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay. My point is, especially it it happens externally, the test should know and account for the behavior. I would hope, no matter which parser is used, that "unsupported_proto" would simply be thrown away and equivalent to "". Then the test should also test a valid, but unsupported, token. |
||
server = await aiohttp_raw_server(handler) | ||
cli = await aiohttp_client(server) | ||
cli: client.ClientSession = await aiohttp_client(server) | ||
test_data = b"Test" | ||
resp = await cli.post("/path/to", data=test_data, headers=upgrade_headers) | ||
async with async_timeout.timeout(10): | ||
resp = await cli.post("/path/to", data=test_data, headers=upgrade_headers) | ||
import pprint | ||
|
||
pprint.pprint(resp.headers) | ||
assert resp.status == 200 | ||
data = await resp.read() | ||
assert data == test_data | ||
|
Check notice
Code scanning / CodeQL
Except block handles 'BaseException' Note