(self, flow: http.HTTPFlow, hdrs: Headers)
| 92 | self.run(flow, flow.response.headers) |
| 93 | |
| 94 | def run(self, flow: http.HTTPFlow, hdrs: Headers) -> None: |
| 95 | matches = [] |
| 96 | |
| 97 | # first check all the filters against the original, unmodified flow |
| 98 | for spec in self.replacements: |
| 99 | matches.append(spec.matches(flow)) |
| 100 | |
| 101 | # unset all specified headers |
| 102 | for i, spec in enumerate(self.replacements): |
| 103 | if matches[i]: |
| 104 | hdrs.pop(spec.subject, None) |
| 105 | |
| 106 | # set all specified headers if the replacement string is not empty |
| 107 | |
| 108 | for i, spec in enumerate(self.replacements): |
| 109 | if matches[i]: |
| 110 | try: |
| 111 | replacement = spec.read_replacement() |
| 112 | except OSError as e: |
| 113 | logging.warning(f"Could not read replacement file: {e}") |
| 114 | continue |
| 115 | else: |
| 116 | if replacement: |
| 117 | hdrs.add(spec.subject, replacement) |
no test coverage detected