-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.py
35 lines (28 loc) · 1 KB
/
response.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
import StringIO
class response:
httpVersion = "HTTP/1.1"
responseMessage = {
200: 'OK',
404: 'Not Found',
405: 'Method Not Allowed',
500: 'Internal Server Error',
}
def __init__(self):
self.response = StringIO.StringIO()
self.headers = {}
def setResponseLine(self, code):
self.code = code;
def setHeader(self, name, value):
self.headers[name] = value
def setContent(self, content):
self.content = content
def toString(self):
self.response.write("%s %s %s\r\n" % (self.httpVersion, self.code, self.responseMessage[self.code]))
self.keys = self.headers.keys()
for self.key in self.keys:
self.response.write("%s: %s\r\n" % (self.key, self.headers[self.key]))
self.response.write("\r\n")
self.response.write(self.content)
returnVal = self.response.getvalue()
self.response.close()
return returnVal