Skip to content

Commit

Permalink
Regression test for handling unsupported Upgrade requests (issue #6446)…
Browse files Browse the repository at this point in the history
… (#6451)

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
(cherry picked from commit a60e8a5)
  • Loading branch information
pwuertz authored and webknjaz committed Dec 23, 2021
1 parent eda8114 commit 70f45e9
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 @@ -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

0 comments on commit 70f45e9

Please sign in to comment.