-
Notifications
You must be signed in to change notification settings - Fork 6
/
request.py
83 lines (69 loc) · 2.44 KB
/
request.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
## @package PyHoot.request
# Request object to handle HTTP requests
## @file request.py Implementation of @ref PyHoot.request
import base
class Request(base.Base):
""" Request that will be build over time, contain the method, uri and headers
Arguements:
self._method, the method of the request (in the current
version only GET is supported)
self._uri, the uri of the requested file
self._headers, a dictionary that contain the name of the
header as key and the header itself as value
self.sent_status, a boolean who say if we already sent
status or not
"""
def __init__(self, method=None, uri=None):
""" Request that will be build over time, contain the method, uri
and headers
Arguments:
method, the method of the request (in the current
version only GET)
uri, the uri of the requested file
"""
super(Request, self).__init__()
self._method = method
self._uri = uri
self._headers = {}
## Have we sent the status already?
self.sent_status = False
## Have we recived everything?
self.full_request = False
@property
def method(self):
""" Return self._method"""
return self._method
@method.setter
def method(self, method):
""" Set self._method
Arguments:
method, the new method
"""
self._method = method
@property
def uri(self):
"""Return self._uri"""
return self._uri
@uri.setter
def uri(self, uri):
""" Set self.uri
Arguments:
uri, the new uri
"""
self._uri = uri
def add_header(self, header, content):
""" Add header
Arguemnts:
header, the name of the header
content, the content of the header
"""
self._headers[header] = content
def get_all_header(self):
""" Return self._headers"""
return self._headers
def remove_header(self, header):
""" Remove a header by its name
Arguemtns:
header, the name of the header
"""
self._headers.pop(header)