Merge pull request #1053 from danpalmer/master
Fix ip and socket data format on V6
This commit is contained in:
commit
2585900692
|
@ -20,7 +20,7 @@ def test_index_put_not_allowed():
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
```
|
```
|
||||||
|
|
||||||
Internally, each time you call one of the `test_client` methods, the Sanic app is run at `127.0.01:42101` and
|
Internally, each time you call one of the `test_client` methods, the Sanic app is run at `127.0.0.1:42101` and
|
||||||
your test request is executed against your application, using `aiohttp`.
|
your test request is executed against your application, using `aiohttp`.
|
||||||
|
|
||||||
The `test_client` methods accept the following arguments and keyword arguments:
|
The `test_client` methods accept the following arguments and keyword arguments:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
from cgi import parse_header
|
from cgi import parse_header
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
@ -185,9 +186,18 @@ class Request(dict):
|
||||||
return self._socket
|
return self._socket
|
||||||
|
|
||||||
def _get_address(self):
|
def _get_address(self):
|
||||||
|
sock = self.transport.get_extra_info('socket')
|
||||||
|
|
||||||
|
if sock.family == socket.AF_INET:
|
||||||
self._socket = (self.transport.get_extra_info('peername') or
|
self._socket = (self.transport.get_extra_info('peername') or
|
||||||
(None, None))
|
(None, None))
|
||||||
self._ip, self._port = self._socket
|
self._ip, self._port = self._socket
|
||||||
|
elif sock.family == socket.AF_INET6:
|
||||||
|
self._socket = (self.transport.get_extra_info('peername') or
|
||||||
|
(None, None, None, None))
|
||||||
|
self._ip, self._port, *_ = self._socket
|
||||||
|
else:
|
||||||
|
self._ip, self._port = (None, None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def remote_addr(self):
|
def remote_addr(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user