From be5588d5d80958778166e3cb321c875f260b0a17 Mon Sep 17 00:00:00 2001 From: Paul Jongsma Date: Thu, 10 Nov 2016 12:53:00 +0100 Subject: [PATCH] Add the client address to the request header --- sanic/server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sanic/server.py b/sanic/server.py index 70dca448..729e1044 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -114,6 +114,11 @@ class HttpProtocol(asyncio.Protocol): self.headers.append((name.decode(), value.decode('utf-8'))) def on_headers_complete(self): + + ra = self.transport.get_extra_info('peername') + if ra: + self.headers.append(('Remote-Addr','%s:%s' % ra)) + self.request = Request( url_bytes=self.url, headers=dict(self.headers),