Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 3014f9c

Browse files
committed
Dump copilot requests, too if CODEGATE_DUMP_DIR is set
I fount dumping requests and replies invaluable with debugging. But we never enabled dumping the requests with copilot. Let's do it now!
1 parent f6113de commit 3014f9c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/codegate/providers/copilot/provider.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
TEMPDIR = tempfile.TemporaryDirectory(prefix="codegate-", dir=basedir, delete=False)
4040

4141

42-
def _dump_data(suffix, func):
42+
def _dump_data(suffix, func, trigger: bytes | None = None):
4343
if os.getenv("CODEGATE_DUMP_DIR"):
4444
buf = bytearray(b"")
4545

@@ -48,7 +48,7 @@ def inner(self, data: bytes):
4848
func(self, data)
4949
buf.extend(data)
5050

51-
if data == b"0\r\n\r\n":
51+
if not trigger or data == trigger:
5252
ts = datetime.datetime.now()
5353
fname = os.path.join(TEMPDIR.name, ts.strftime(f"{suffix}-%Y%m%dT%H%M%S%f.txt"))
5454
with open(fname, mode="wb") as fd:
@@ -58,14 +58,11 @@ def inner(self, data: bytes):
5858
return inner
5959
return func
6060

61-
6261
def _dump_request(func):
6362
return _dump_data("request", func)
6463

65-
6664
def _dump_response(func):
67-
return _dump_data("response", func)
68-
65+
return _dump_data("response", func, b"0\r\n\r\n")
6966

7067
# Constants
7168
MAX_BUFFER_SIZE = 10 * 1024 * 1024 # 10MB
@@ -336,7 +333,12 @@ def _check_buffer_size(self, new_data: bytes) -> bool:
336333
"""Check if adding new data would exceed buffer size limit"""
337334
return len(self.buffer) + len(new_data) <= MAX_BUFFER_SIZE
338335

336+
@_dump_request
337+
def _dump_create_http_request(self, data: bytes) -> bytes:
338+
return data
339+
339340
async def _forward_data_through_pipeline(self, data: bytes) -> Union[HttpRequest, HttpResponse]:
341+
self._dump_create_http_request(data)
340342
http_request = http_request_from_bytes(data)
341343
if not http_request:
342344
# we couldn't parse this into an HTTP request, so we just pass through

0 commit comments

Comments
 (0)