Bug 1628627 - [mozproxy] Mitmproxy is ignoring 301 requests r=perftest-reviewers,tarek,AlexandruIonescu
authorFlorin Strugariu <fstrugariu@mozilla.com>
Thu, 30 Apr 2020 07:39:32 +0000
changeset 526882 04bda73f9d19eceafc070b63e9fd4b23985d9665
parent 526881 741768b1c721686a957bd6e032a7e9ac9556a728
child 526883 ad9958d7404c6da8f7f2bb1fa60a6f5947577eb9
push id37365
push userapavel@mozilla.com
push dateThu, 30 Apr 2020 15:50:41 +0000
treeherdermozilla-central@d34716786f5b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersperftest-reviewers, tarek, AlexandruIonescu
bugs1628627
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1628627 - [mozproxy] Mitmproxy is ignoring 301 requests r=perftest-reviewers,tarek,AlexandruIonescu Differential Revision: https://phabricator.services.mozilla.com/D72338
testing/mozbase/mozproxy/mozproxy/backends/mitm/scripts/alternate-server-replay.py
--- a/testing/mozbase/mozproxy/mozproxy/backends/mitm/scripts/alternate-server-replay.py
+++ b/testing/mozbase/mozproxy/mozproxy/backends/mitm/scripts/alternate-server-replay.py
@@ -4,16 +4,17 @@
 # Altered features:
 # * returns 404 rather than dropping the whole HTTP/2 connection on the floor
 # * remove the replay packages that don't have any content in their response package
 from __future__ import absolute_import, print_function
 
 import os
 import json
 import hashlib
+import traceback
 import urllib
 from collections import defaultdict
 import time
 import signal
 
 import typing
 from urllib import parse
 
@@ -22,16 +23,20 @@ from mitmproxy import exceptions
 from mitmproxy import io
 
 # PATCHING AREA  - ALLOWS HTTP/2 WITH NO CERT SNIFFING
 from mitmproxy.proxy.protocol import tls
 from mitmproxy.proxy.protocol.http2 import Http2Layer, SafeH2Connection
 
 _PROTO = {}
 
+NO_CONTENT_STATUS_CODES = [100, 101,
+                           204,
+                           301, 302, 303, 304, 307, 308]
+
 
 @property
 def _alpn(self):
     proto = _PROTO.get(self.server_sni)
     if proto is None:
         return self.server_conn.get_alpn_proto_negotiated()
     if proto.startswith("HTTP/2"):
         return b"h2"
@@ -118,26 +123,26 @@ class AlternateServerPlayback:
                 # Mitmproxy can't replay WebSocket packages.
                 ctx.log.info(
                     "Recorded response is a WebSocketFlow. Removing from recording list as"
                     "  WebSockets are disabled"
                 )
             elif i.response:
                 # check if recorded request has a response associated
                 if self.mitm_version == "5.0.1":
-                    if i.response.content:
+                    if (i.response.content or
+                            i.response.status_code in NO_CONTENT_STATUS_CODES):
                         # Mitmproxy 5.0.1 Cannot assemble flow with missing content
 
                         l = self.flowmap.setdefault(self._hash(i), [])
                         l.append(i)
                     else:
-                        ctx.log.info(
-                             "Recorded response %s has no content. Removing from recording list"
-                             % i.request.url
-                        )
+                        ctx.log.info("Recorded request %s  with response status code %s has "
+                                     "no response content. Removing from recording list"
+                                     % (i.request.url, i.response.status_code))
                 if self.mitm_version in ("4.0.2", "4.0.4"):
                     # see: https://github.com/mitmproxy/mitmproxy/issues/3856
                     l = self.flowmap.setdefault(self._hash(i), [])
                     l.append(i)
             else:
                 ctx.log.info(
                     "Recorded request %s has no response. Removing from recording list"
                     % i.request.url
@@ -161,19 +166,19 @@ class AlternateServerPlayback:
                     with open(proto) as f:
                         recording_info = json.loads(f.read())
                     ctx.log.info(
                         "Replaying file {} recorded on {}".format(
                             os.path.basename(path), recording_info["recording_date"]
                         )
                     )
                     _PROTO.update(recording_info["http_protocol"])
-        except Exception as e:
-            ctx.log.error("Could not load recording file! Stopping playback process!")
-            ctx.log.info(e)
+        except Exception:
+            ctx.log.error("Could not load recording file! Stopping playback process! ")
+            ctx.log.info(traceback.print_exc())
             ctx.master.shutdown()
 
     def _hash(self, flow):
         """
             Calculates a loose hash of the flow request.
         """
         r = flow.request