-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.py
More file actions
43 lines (34 loc) · 1.1 KB
/
request.py
File metadata and controls
43 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Request:
def __init__(self, raw_data):
self.data = raw_data.decode('utf-8').split('\r\n')
def __get_request_value(self, key: str) -> str:
key = key.lower()
for item in self.data[: -1]:
splitted = item.split(':')
if splitted[0].lower() == key:
return splitted[1].strip()
return ''
@property
def method(self) -> str:
return str(self.data[0]).split(' ')[0]
@property
def http_version(self) -> str:
return str(self.data[0]).split(' ')[2]
@property
def url(self) -> str:
return str(self.data[0]).split(' ')[1]
@property
def user_agent(self) -> str:
return self.__get_request_value('User-Agent')
@property
def accept(self) -> str:
return self.__get_request_value('Accept')
@property
def content_type(self) -> str:
return self.__get_request_value('Content-Type')
@property
def content_length(self) -> int:
return self.__get_request_value('Content-Length')
@property
def payload(self):
return str(self.data[-1])