Patchwork [02,of,12] hgweb: send Content-Length 0 for zero length response

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 11, 2013, 11:32 p.m.
Message ID <4f58d5f65b70b060df3f.1357947166@mk-desktop>
Download mbox | patch
Permalink /patch/562/
State Accepted
Commit 590056e0ec2f32106ea174da915d4de534fc4a2c
Headers show

Comments

Mads Kiilerich - Jan. 11, 2013, 11:32 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1357947109 -3600
# Node ID 4f58d5f65b70b060df3f76cfe72a6716a69a40b6
# Parent  0a7d8aa24714c134ebdcb06dc1e583e04fd85d10
hgweb: send Content-Length 0 for zero length response

Before, Content-Length wasn't sent for 0 length responses. Now it is.

This could in principle prevent some unnecessary http connection close.

Patch

diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -70,7 +70,7 @@ 
         for s in util.filechunkiter(self.inp, limit=length):
             pass
 
-    def respond(self, status, type=None, filename=None, length=0):
+    def respond(self, status, type=None, filename=None, length=None):
         if self._start_response is not None:
 
             self.httphdr(type, filename, length)
@@ -125,7 +125,7 @@ 
     def header(self, headers=[('Content-Type','text/html')]):
         self.headers.extend(headers)
 
-    def httphdr(self, type=None, filename=None, length=0, headers={}):
+    def httphdr(self, type=None, filename=None, length=None, headers={}):
         headers = headers.items()
         if type is not None:
             headers.append(('Content-Type', type))
@@ -134,7 +134,7 @@ 
                         .replace('\\', '\\\\').replace('"', '\\"'))
             headers.append(('Content-Disposition',
                             'inline; filename="%s"' % filename))
-        if length:
+        if length is not None:
             headers.append(('Content-Length', str(length)))
         self.header(headers)