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

fix: do not try to send buffer data if it is empty #393

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/codegate/providers/copilot/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def _request_to_target(self, headers: list[str], body: bytes):
logger.debug("=" * 40)

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

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

if self.target_transport:
body_start = self.buffer.index(b"\r\n\r\n") + 4
body = self.buffer[body_start:]
await self._request_to_target(new_headers, body)
if self.buffer:
body_start = self.buffer.index(b"\r\n\r\n") + 4
body = self.buffer[body_start:]
await self._request_to_target(new_headers, body)
else:
# just skip it
logger.info("No buffer content arrived, skipping")
else:
logger.error("Target transport not available")
self.send_error_response(502, b"Failed to establish target connection")
Expand Down
Loading