Skip to content

Commit b072a32

Browse files
Update thimble.py with remote_addr - closes issue #16
1 parent d9bfd27 commit b072a32

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

thimble.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,20 @@ async def on_connect(self, reader, writer):
392392
Returns:
393393
nothing
394394
"""
395-
client_ip = writer.get_extra_info('peername')[0]
395+
remote_addr = writer.get_extra_info('peername')[0]
396396
if self.debug:
397-
print(f'Connection from client: {client_ip}')
397+
print(f'Connection from client: {remote_addr}')
398398

399399
try:
400400
req_buffer = await reader.read(self.req_buffer_size)
401401
req = await Thimble.parse_http_request(req_buffer)
402-
if self.debug:
403-
print(f'Request: {req}')
404402
except Exception as ex:
405403
await self.send_error(400, writer)
406404
print(f'Unable to parse request: {ex}')
407405
else:
406+
req['remote_addr'] = remote_addr
407+
if self.debug:
408+
print(f'Request: {req}')
408409
route_value = self.resolve_route(req['method'] + req['path'])
409410
if isinstance(route_value, tuple): # a function and URL wildcard value were returned
410411
await self.send_function_results(route_value[0], req, route_value[1], writer)
@@ -422,7 +423,7 @@ async def on_connect(self, reader, writer):
422423
reader.close()
423424
await reader.wait_closed()
424425
if self.debug:
425-
print(f'Connection closed for {client_ip}')
426+
print(f'Connection closed for {remote_addr}')
426427

427428
def run(self, host='0.0.0.0', port=80, loop=None, debug=False):
428429
"""

0 commit comments

Comments
 (0)