Skip to content

Commit

Permalink
[PR #6451/a60e8a58 backport][3.9] Regression test for handling unsupp…
Browse files Browse the repository at this point in the history
…orted Upgrade requests (issue #6446) (#6455)

Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Co-authored-by: Peter Würtz <pwuertz@gmail.com>
  • Loading branch information
3 people authored Dec 23, 2021
1 parent 63ac2a0 commit 488f314
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

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


async def test_simple_server(aiohttp_raw_server, aiohttp_client) -> None:
Expand All @@ -18,6 +18,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, aiohttp_client):
exc = RuntimeError("custom runtime error")

Expand Down

0 comments on commit 488f314

Please sign in to comment.