aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http.py')
-rw-r--r--netlib/http.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/netlib/http.py b/netlib/http.py
index 26438863..2c72621d 100644
--- a/netlib/http.py
+++ b/netlib/http.py
@@ -29,6 +29,20 @@ def _is_valid_host(host):
return None
return True
+def is_successful_upgrade(request, response):
+ """
+ determines if a client and server successfully agreed to an HTTP protocol upgrade
+
+ https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
+ """
+ http_switching_protocols_code = 101
+
+ if request and response:
+ responseUpgrade = request.headers.get("Upgrade")
+ requestUpgrade = response.headers.get("Upgrade")
+ if response.code == http_switching_protocols_code and responseUpgrade == requestUpgrade:
+ return requestUpgrade[0] if len(requestUpgrade) > 0 else None
+ return None
def parse_url(url):
"""