Skip to content

Commit 5e2bf6f

Browse files
committed
raise on misdirected websocket handshake
responding "HTTP/1.1 101 Switching Protocols" to a HEAD request is unlikely intended.
1 parent 7b1e50b commit 5e2bf6f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

aiohttp/web_ws.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .log import ws_logger
3737
from .streams import EofStream
3838
from .typedefs import JSONDecoder, JSONEncoder
39-
from .web_exceptions import HTTPBadRequest, HTTPException
39+
from .web_exceptions import HTTPBadRequest, HTTPException, HTTPMethodNotAllowed
4040
from .web_request import BaseRequest
4141
from .web_response import StreamResponse
4242

@@ -226,6 +226,9 @@ def _handshake(
226226
self, request: BaseRequest
227227
) -> Tuple["CIMultiDict[str]", Optional[str], int, bool]:
228228
headers = request.headers
229+
if request.method != hdrs.METH_GET:
230+
raise HTTPMethodNotAllowed(request.method, {hdrs.METH_GET})
231+
229232
if "websocket" != headers.get(hdrs.UPGRADE, "").lower().strip():
230233
raise HTTPBadRequest(
231234
text=(

0 commit comments

Comments
 (0)