Merge pull request #36 from techdavid/header-functions

Allow other add-ons to add headers
This commit is contained in:
Alex Yatskov 2017-08-20 09:03:17 -07:00 committed by GitHub
commit a68d7d6130

View File

@ -199,6 +199,19 @@ class AjaxServer:
self.handler = handler self.handler = handler
self.clients = [] self.clients = []
self.sock = None self.sock = None
self.resetHeaders()
def addHeader(self, name, value):
self.headers.append([name, value])
def resetHeaders(self):
self.headers = [
['HTTP/1.1 200 OK', None],
['Content-Type', 'text/json'],
['Content-Length', '']
]
def advance(self): def advance(self):
@ -243,11 +256,9 @@ class AjaxServer:
body = json.dumps(None); body = json.dumps(None);
resp = bytes() resp = bytes()
headers = [
['HTTP/1.1 200 OK', None], headers = self.headers
['Content-Type', 'text/json'], headers[2][1] = str(len(body))
['Content-Length', str(len(body))]
]
for key, value in headers: for key, value in headers:
if value is None: if value is None: