33import aiohttp
44import json
55
6- import mitmproxy
76from mitmproxy import ctx , flowfilter
87from mitmproxy .http import Response
98from controller import MITM_DOMAIN_NAME
@@ -99,7 +98,7 @@ async def response(self, flow):
9998 }
10099 await self .send_callback (flow , self .config ["callback_response_url" ], callback_body )
101100
102- async def send_callback (self , flow : mitmproxy . http . HTTPFlow , url : str , body : dict ):
101+ async def send_callback (self , flow , url : str , body : dict ):
103102 try :
104103 # use asyncio so we don't block other unrelated requests from being processed
105104 async with aiohttp .request (
@@ -123,17 +122,12 @@ async def send_callback(self, flow: mitmproxy.http.HTTPFlow, url: str, body: dic
123122 respond_status_code = test_response_body .get ("respond_status_code" , body .get ("response_code" ))
124123 respond_body = test_response_body .get ("respond_body" , body .get ("response_body" ))
125124 print (f'{ datetime .now ().strftime ("%H:%M:%S.%f" )} callback for { flow .request .url } returning custom response: HTTP { respond_status_code } { json .dumps (respond_body )} ' )
126-
127125 flow .response = Response .make (
128126 respond_status_code , json .dumps (respond_body ),
129127 headers = {
130128 "MITM-Proxy" : "yes" , # so we don't reprocess this
131129 "Content-Type" : "application/json" ,
132-
133- # Copy the CORS headers from the original response
134- ** {k : v for k , v in flow .response .headers .items () if k .startswith ("Access-Control" )}
135- },
136- )
130+ })
137131 except Exception as error :
138132 print (f"ERR: callback for { flow .request .url } returned { error } " )
139133 print (f"ERR: callback, provided request body was { body } " )
0 commit comments