aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addons/disable_h2c_upgrade.py
diff options
context:
space:
mode:
Diffstat (limited to 'mitmproxy/addons/disable_h2c_upgrade.py')
-rw-r--r--mitmproxy/addons/disable_h2c_upgrade.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mitmproxy/addons/disable_h2c_upgrade.py b/mitmproxy/addons/disable_h2c_upgrade.py
new file mode 100644
index 00000000..f4a36d5f
--- /dev/null
+++ b/mitmproxy/addons/disable_h2c_upgrade.py
@@ -0,0 +1,21 @@
+class DisableH2CleartextUpgrade:
+
+ """
+ We currently only support HTTP/2 over a TLS connection. Some clients try
+ to upgrade a connection from HTTP/1.1 to h2c, so we need to remove those
+ headers to avoid protocol errors if one endpoints suddenly starts sending
+ HTTP/2 frames.
+ """
+
+ def process_flow(self, f):
+ if f.request.headers.get('upgrade', '') == 'h2c':
+ del f.request.headers['upgrade']
+ if 'connection' in f.request.headers:
+ del f.request.headers['connection']
+ if 'http2-settings' in f.request.headers:
+ del f.request.headers['http2-settings']
+
+ # Handlers
+
+ def request(self, f):
+ self.process_flow(f)