Improve handling of HTTP headers
This commit is contained in:
parent
a68d7d6130
commit
8179643067
@ -202,16 +202,22 @@ class AjaxServer:
|
|||||||
self.resetHeaders()
|
self.resetHeaders()
|
||||||
|
|
||||||
|
|
||||||
def addHeader(self, name, value):
|
def setHeader(self, name, value):
|
||||||
self.headers.append([name, value])
|
self.headers[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', '']
|
}
|
||||||
]
|
|
||||||
|
|
||||||
|
def getHeaders(self):
|
||||||
|
headers = []
|
||||||
|
for name in self.headers:
|
||||||
|
headers.append([name, self.headers[name]])
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
def advance(self):
|
def advance(self):
|
||||||
@ -257,8 +263,8 @@ class AjaxServer:
|
|||||||
|
|
||||||
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