Allow case-insensitive HTTP Upgrade header (#2097)

* Allow case-insensitive HTTP Upgrade header

* Allow case-insensitive Upgrade header when checking the scheme

* Fix reference to headers

* Add None check

* Simplify HTTP Upgrade checks

* Fix newlines at end of file

* Run make pretty
This commit is contained in:
ENT8R 2021-04-05 13:15:45 +02:00 committed by GitHub
parent 93a0246c03
commit eba7821a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -218,7 +218,9 @@ class Http:
raise InvalidUsage("Bad Request")
headers_instance = Header(headers)
self.upgrade_websocket = headers_instance.get("upgrade") == "websocket"
self.upgrade_websocket = (
headers_instance.get("upgrade", "").lower() == "websocket"
)
# Prepare a Request object
request = self.protocol.request_class(

View File

@ -581,7 +581,7 @@ class Request:
if (
self.app.websocket_enabled
and self.headers.get("upgrade") == "websocket"
and self.headers.get("upgrade", "").lower() == "websocket"
):
scheme = "ws"
else: