Change parsing cookies mechanism. (like Django instade of http.cookies.SimpleCookie)
This commit is contained in:
parent
9bdf7a9980
commit
ba1dbacd35
|
@ -1,8 +1,9 @@
|
||||||
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 import cookies
|
||||||
from httptools import parse_url
|
from httptools import parse_url
|
||||||
from urllib.parse import parse_qs, urlunparse
|
from urllib.parse import parse_qs, urlunparse
|
||||||
|
|
||||||
|
@ -157,13 +158,17 @@ class Request(dict):
|
||||||
def cookies(self):
|
def cookies(self):
|
||||||
if self._cookies is None:
|
if self._cookies is None:
|
||||||
cookie = self.headers.get('Cookie')
|
cookie = self.headers.get('Cookie')
|
||||||
if cookie is not None:
|
|
||||||
cookies = SimpleCookie()
|
|
||||||
cookies.load(cookie)
|
|
||||||
self._cookies = {name: cookie.value
|
|
||||||
for name, cookie in cookies.items()}
|
|
||||||
else:
|
|
||||||
self._cookies = {}
|
self._cookies = {}
|
||||||
|
if cookie is not None:
|
||||||
|
for chunk in cookie.split(';'):
|
||||||
|
if '=' in chunk:
|
||||||
|
key, val = chunk.split('=', 1)
|
||||||
|
else:
|
||||||
|
key, val = '', chunk
|
||||||
|
key, val = key.strip(), val.strip()
|
||||||
|
if key or val:
|
||||||
|
self._cookies[key] = cookies._unquote(val)
|
||||||
|
|
||||||
return self._cookies
|
return self._cookies
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -181,13 +186,22 @@ class Request(dict):
|
||||||
@property
|
@property
|
||||||
def socket(self):
|
def socket(self):
|
||||||
if not hasattr(self, '_socket'):
|
if not hasattr(self, '_socket'):
|
||||||
self._get_socket()
|
self._get_address()
|
||||||
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