Skip to content

Commit

Permalink
Await the read and close the connection at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
kgaughan committed Oct 21, 2024
1 parent 1c176d2 commit 1968c56
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/uwhoisd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

async def start_service(iface: str, port: int, whois):
async def handle_request(reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
query = reader.read_until(b"\r\n")
query = await reader.readuntil(b"\r\n")
cleaned = query.decode().strip().lower()
if not utils.is_well_formed_fqdn(cleaned):
result = f"; Bad query: '{cleaned}'\r\n"
else:
result = await whois(cleaned)
writer.write(result.encode())
await writer.drain()
writer.close()

svr = await asyncio.start_server(handle_request, host=iface, port=port)
async with svr:
Expand Down

0 comments on commit 1968c56

Please sign in to comment.