Merge pull request #37 from techdavid/better-headers

Improve handling of HTTP headers
This commit is contained in:
Alex Yatskov 2017-08-20 15:23:01 -07:00 committed by GitHub
commit d06b231b51

View File

@ -202,16 +202,23 @@ class AjaxServer:
self.resetHeaders()
def addHeader(self, name, value):
self.headers.append([name, value])
def setHeader(self, name, value):
self.extraHeaders[name] = value
def resetHeaders(self):
self.headers = [
['HTTP/1.1 200 OK', None],
['Content-Type', 'text/json'],
['Content-Length', '']
['Content-Type', 'text/json']
]
self.extraHeaders = {}
def getHeaders(self):
headers = self.headers[:]
for name in self.extraHeaders:
headers.append([name, self.extraHeaders[name]])
return headers
def advance(self):
@ -257,8 +264,8 @@ class AjaxServer:
resp = bytes()
headers = self.headers
headers[2][1] = str(len(body))
self.setHeader('Content-Length', str(len(body)))
headers = self.getHeaders()
for key, value in headers:
if value is None: