39
39
TEMPDIR = tempfile .TemporaryDirectory (prefix = "codegate-" , dir = basedir , delete = False )
40
40
41
41
42
- def _dump_data (suffix , func ):
42
+ def _dump_data (suffix , func , trigger : bytes | None = None ):
43
43
if os .getenv ("CODEGATE_DUMP_DIR" ):
44
44
buf = bytearray (b"" )
45
45
@@ -48,7 +48,7 @@ def inner(self, data: bytes):
48
48
func (self , data )
49
49
buf .extend (data )
50
50
51
- if data == b"0 \r \n \r \n " :
51
+ if not trigger or data == trigger :
52
52
ts = datetime .datetime .now ()
53
53
fname = os .path .join (TEMPDIR .name , ts .strftime (f"{ suffix } -%Y%m%dT%H%M%S%f.txt" ))
54
54
with open (fname , mode = "wb" ) as fd :
@@ -64,7 +64,7 @@ def _dump_request(func):
64
64
65
65
66
66
def _dump_response (func ):
67
- return _dump_data ("response" , func )
67
+ return _dump_data ("response" , func , b"0 \r \n \r \n " )
68
68
69
69
70
70
# Constants
@@ -336,7 +336,12 @@ def _check_buffer_size(self, new_data: bytes) -> bool:
336
336
"""Check if adding new data would exceed buffer size limit"""
337
337
return len (self .buffer ) + len (new_data ) <= MAX_BUFFER_SIZE
338
338
339
+ @_dump_request
340
+ def _dump_create_http_request (self , data : bytes ) -> bytes :
341
+ return data
342
+
339
343
async def _forward_data_through_pipeline (self , data : bytes ) -> Union [HttpRequest , HttpResponse ]:
344
+ self ._dump_create_http_request (data )
340
345
http_request = http_request_from_bytes (data )
341
346
if not http_request :
342
347
# we couldn't parse this into an HTTP request, so we just pass through
0 commit comments