From be5588d5d80958778166e3cb321c875f260b0a17 Mon Sep 17 00:00:00 2001 From: Paul Jongsma Date: Thu, 10 Nov 2016 12:53:00 +0100 Subject: [PATCH 1/4] 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), From b92e46df4018aa9288e1918eca2f65e2820b61c7 Mon Sep 17 00:00:00 2001 From: Paul Jongsma Date: Thu, 10 Nov 2016 13:06:27 +0100 Subject: [PATCH 2/4] fix whitespace --- sanic/server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 729e1044..ec4e5780 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -114,11 +114,10 @@ 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), From 8ebc92c236652f357394e618640505a11ba49283 Mon Sep 17 00:00:00 2001 From: Paul Jongsma Date: Thu, 10 Nov 2016 13:09:37 +0100 Subject: [PATCH 3/4] pass flake8 tests --- sanic/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/server.py b/sanic/server.py index ec4e5780..e802b5df 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -116,7 +116,7 @@ class HttpProtocol(asyncio.Protocol): def on_headers_complete(self): ra = self.transport.get_extra_info('peername') if ra: - self.headers.append(('Remote-Addr','%s:%s' % ra)) + self.headers.append(('Remote-Addr', '%s:%s' % ra)) self.request = Request( url_bytes=self.url, From 28ce2447ef9c4bd75ad6e21bc9f3a660714a3b02 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Thu, 10 Nov 2016 15:28:16 -0600 Subject: [PATCH 4/4] Update variable name Give `ra` a more explicit name --- sanic/server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index e802b5df..0fd85440 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -114,9 +114,9 @@ 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)) + remote_addr = self.transport.get_extra_info('peername') + if remote_addr: + self.headers.append(('Remote-Addr', '%s:%s' % remote_addr)) self.request = Request( url_bytes=self.url,