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

Commit 9fdf848

Browse files
authored
Merge pull request #393 from stacklok/issue-373
fix: do not try to send buffer data if it is empty
2 parents 079518d + c7885bd commit 9fdf848

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/codegate/providers/copilot/provider.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def _request_to_target(self, headers: list[str], body: bytes):
180180
logger.debug("=" * 40)
181181

182182
for i in range(0, len(body), CHUNK_SIZE):
183-
chunk = body[i : i + CHUNK_SIZE]
183+
chunk = body[i: i + CHUNK_SIZE]
184184
self.target_transport.write(chunk)
185185

186186
def connection_made(self, transport: asyncio.Transport) -> None:
@@ -343,9 +343,13 @@ async def handle_http_request(self) -> None:
343343
new_headers.append(f"Host: {self.target_host}")
344344

345345
if self.target_transport:
346-
body_start = self.buffer.index(b"\r\n\r\n") + 4
347-
body = self.buffer[body_start:]
348-
await self._request_to_target(new_headers, body)
346+
if self.buffer:
347+
body_start = self.buffer.index(b"\r\n\r\n") + 4
348+
body = self.buffer[body_start:]
349+
await self._request_to_target(new_headers, body)
350+
else:
351+
# just skip it
352+
logger.info("No buffer content arrived, skipping")
349353
else:
350354
logger.error("Target transport not available")
351355
self.send_error_response(502, b"Failed to establish target connection")

0 commit comments

Comments
 (0)