# HG changeset patch # User paulb # Date 1087424822 0 # Node ID b6d245b617b1adf1f04ce49a49fe0577e28fa118 # Parent ae12964c4cba2c0ae7d4b732353c5c050202a545 [project @ 2004-06-16 22:27:02 by paulb] Added Content-Length header setting according to the length of the written body content. diff -r ae12964c4cba -r b6d245b617b1 WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Fri Jun 20 22:24:10 2008 +0200 +++ b/WebStack/BaseHTTPRequestHandler.py Wed Jun 16 22:27:02 2004 +0000 @@ -63,9 +63,18 @@ for morsel in self.cookies_out.values(): self.trans.send_header("Set-Cookie", morsel.OutputString()) - self.trans.end_headers() + # Add possibly missing content length information. + # NOTE: This is really inefficient, but we need to buffer things to + # NOTE: permit out of order header setting. + self.content.seek(0) - self.trans.wfile.write(self.content.read()) + content = self.content.read() + + if not self.headers_out.has_key("Content-Length"): + self.trans.send_header("Content-Length", str(len(content))) + + self.trans.end_headers() + self.trans.wfile.write(content) # Request-related methods.