diff options
author | Chandler Abraham <cabraham@twitter.com> | 2015-04-09 19:35:40 -0700 |
---|---|---|
committer | Chandler Abraham <cabraham@twitter.com> | 2015-04-10 18:37:41 -0700 |
commit | e41e5cbfdd7b778e6f68e86658e95f9e413133cb (patch) | |
tree | d12b4e3c2e834f2d5efd0ec9c85dee159f508123 /netlib/http.py | |
parent | e58f76aec1db9cc784a3b73c3050d010bb084968 (diff) | |
download | mitmproxy-e41e5cbfdd7b778e6f68e86658e95f9e413133cb.tar.gz mitmproxy-e41e5cbfdd7b778e6f68e86658e95f9e413133cb.tar.bz2 mitmproxy-e41e5cbfdd7b778e6f68e86658e95f9e413133cb.zip |
netlib websockets
Diffstat (limited to 'netlib/http.py')
-rw-r--r-- | netlib/http.py | 14 |
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): """ |