generated from matrix-org/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add statuscode; listen for config updates
- Loading branch information
Showing
4 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from add_header import AddHeader | ||
from status_code import StatusCode | ||
|
||
|
||
addons = [AddHeader()] | ||
addons = [StatusCode()] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from mitmproxy import ctx | ||
from mitmproxy.http import Response | ||
|
||
class StatusCode: | ||
def __init__(self): | ||
self.return_status_code = 0 # disabled | ||
|
||
def load(self, loader): | ||
loader.add_option( | ||
name="statuscode", | ||
typespec=int, | ||
default=0, | ||
help="Change the response status code", | ||
) | ||
|
||
def configure(self, updates): | ||
if "statuscode" not in updates: | ||
self.return_status_code = 0 | ||
return | ||
if ctx.options.statuscode is None or ctx.options.statuscode == 0: | ||
self.return_status_code = 0 | ||
return | ||
self.return_status_code = ctx.options.statuscode | ||
logging.info(f"statuscode will return HTTP {self.return_status_code}") | ||
|
||
def response(self, flow): | ||
if self.return_status_code == 0: | ||
return | ||
flow.response = Response.make(self.return_status_code) |