Skip to content

Commit

Permalink
add statuscode; listen for config updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 30, 2023
1 parent 955b514 commit a9a6b13
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func RunNewDeployment(t *testing.T, shouldTCPDump bool) *SlidingSyncDeployment {
Env: map[string]string{},
Cmd: []string{
"mitmdump", "--mode", "reverse:http://hs1:8008@3000", "--mode", "reverse:http://hs2:8008@3001", "-s", "/addons/__init__.py",
//"--set", "statuscode=400",
},
// WaitingFor: wait.ForLog("listening"),
Networks: []string{networkName},
Expand Down
4 changes: 2 additions & 2 deletions tests/addons/__init__.py
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()]
9 changes: 0 additions & 9 deletions tests/addons/add_header.py

This file was deleted.

31 changes: 31 additions & 0 deletions tests/addons/status_code.py
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)

0 comments on commit a9a6b13

Please sign in to comment.