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

[PR #6451/a60e8a58 forwardport][3.9] Regression test for handling unsupported Upgrade requests (issue #6446) #6456

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tests/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from aiohttp import client, web
from aiohttp import client, helpers, web


async def test_simple_server(aiohttp_raw_server: Any, aiohttp_client: Any) -> None:
Expand All @@ -20,6 +20,28 @@ async def handler(request):
assert txt == "/path/to"


@pytest.mark.xfail(
not helpers.NO_EXTENSIONS,
raises=client.ServerDisconnectedError,
reason="The behavior of C-extensions differs from pure-Python: "
"https://github.com/aio-libs/aiohttp/issues/6446",
)
async def test_unsupported_upgrade(aiohttp_raw_server, aiohttp_client) -> None:
# 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())

upgrade_headers = {"Connection": "Upgrade", "Upgrade": "unsupported_proto"}
server = await aiohttp_raw_server(handler)
cli = await aiohttp_client(server)
test_data = b"Test"
resp = await cli.post("/path/to", data=test_data, headers=upgrade_headers)
assert resp.status == 200
data = await resp.read()
assert data == test_data


async def test_raw_server_not_http_exception(
aiohttp_raw_server: Any, aiohttp_client: Any, loop: Any
) -> None:
Expand Down