From 7567752d2bef4972e4036419453e57900afd719e Mon Sep 17 00:00:00 2001 From: IceArmy Date: Sun, 4 Dec 2011 22:44:39 -0800 Subject: [PATCH] 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. --- python/pyphantomjs/webserver.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/pyphantomjs/webserver.py b/python/pyphantomjs/webserver.py index 3574566b..76ac91fe 100644 --- a/python/pyphantomjs/webserver.py +++ b/python/pyphantomjs/webserver.py @@ -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)