Don't send body or content-length header under certain conditions

We have to include this check for the content-length header (since it's auto generated), however, the script is supposed to take care of not sending any message body; but we've taken care of that anyways, to conform a little more to standards.
1.4
IceArmy 2011-12-04 22:44:39 -08:00
parent 18e9575f9d
commit 7567752d2b
1 changed files with 6 additions and 2 deletions

View File

@ -156,10 +156,14 @@ class WebServerHandler(BaseHTTPRequestHandler):
# send content-length if not already sent
if self.protocol_version == 'HTTP/1.1':
if 'content-length' not in self.m_headers:
self.send_header('Content-Length', self.m_wfile.tell())
if self.m_statusCode >= 200 and self.m_statusCode not in (204, 304):
self.send_header('Content-Length', self.m_wfile.tell())
self.end_headers() #finish sending the headers
self.wfile.write(self.m_wfile.getvalue()) #write body to page
# check if body should be written to response
if self.command != 'HEAD' and self.m_statusCode >= 200 and self.m_statusCode not in (204, 304):
self.wfile.write(self.m_wfile.getvalue()) #write body to page
def handleRequest(self):
request = WebServerRequest(self)