Merge pull request #37 from techdavid/better-headers
Improve handling of HTTP headers
This commit is contained in:
commit
d06b231b51
@ -202,16 +202,23 @@ class AjaxServer:
|
|||||||
self.resetHeaders()
|
self.resetHeaders()
|
||||||
|
|
||||||
|
|
||||||
def addHeader(self, name, value):
|
def setHeader(self, name, value):
|
||||||
self.headers.append([name, value])
|
self.extraHeaders[name] = value
|
||||||
|
|
||||||
|
|
||||||
def resetHeaders(self):
|
def resetHeaders(self):
|
||||||
self.headers = [
|
self.headers = [
|
||||||
['HTTP/1.1 200 OK', None],
|
['HTTP/1.1 200 OK', None],
|
||||||
['Content-Type', 'text/json'],
|
['Content-Type', 'text/json']
|
||||||
['Content-Length', '']
|
|
||||||
]
|
]
|
||||||
|
self.extraHeaders = {}
|
||||||
|
|
||||||
|
|
||||||
|
def getHeaders(self):
|
||||||
|
headers = self.headers[:]
|
||||||
|
for name in self.extraHeaders:
|
||||||
|
headers.append([name, self.extraHeaders[name]])
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
def advance(self):
|
def advance(self):
|
||||||
@ -256,9 +263,9 @@ class AjaxServer:
|
|||||||
body = json.dumps(None);
|
body = json.dumps(None);
|
||||||
|
|
||||||
resp = bytes()
|
resp = bytes()
|
||||||
|
|
||||||
headers = self.headers
|
self.setHeader('Content-Length', str(len(body)))
|
||||||
headers[2][1] = str(len(body))
|
headers = self.getHeaders()
|
||||||
|
|
||||||
for key, value in headers:
|
for key, value in headers:
|
||||||
if value is None:
|
if value is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user