Skip to content

Commit a031791

Browse files
authored
Dump copilot requests, too if CODEGATE_DUMP_DIR is set (#1196)
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 072ab9f commit a031791

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/codegate/providers/copilot/provider.py

+8-3
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:
@@ -64,7 +64,7 @@ def _dump_request(func):
6464

6565

6666
def _dump_response(func):
67-
return _dump_data("response", func)
67+
return _dump_data("response", func, b"0\r\n\r\n")
6868

6969

7070
# Constants
@@ -336,7 +336,12 @@ def _check_buffer_size(self, new_data: bytes) -> bool:
336336
"""Check if adding new data would exceed buffer size limit"""
337337
return len(self.buffer) + len(new_data) <= MAX_BUFFER_SIZE
338338

339+
@_dump_request
340+
def _dump_create_http_request(self, data: bytes) -> bytes:
341+
return data
342+
339343
async def _forward_data_through_pipeline(self, data: bytes) -> Union[HttpRequest, HttpResponse]:
344+
self._dump_create_http_request(data)
340345
http_request = http_request_from_bytes(data)
341346
if not http_request:
342347
# we couldn't parse this into an HTTP request, so we just pass through

0 commit comments

Comments
 (0)