[PATCH 12 of 12] serve: don't close connections with chunked encoding

Mads Kiilerich mads at kiilerich.com
Fri Jan 11 17:32:56 CST 2013


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1357947110 -3600
# Node ID c554ae0503419c8c5fc2a888da9ed48afda451a8
# Parent  d4104616205bc3d9fa665a6cae85bc702774987c
serve: don't close connections with chunked encoding

Problem:
The WSGI server/middleware tried to be smart and both observe and control
data flow and connection lifetime ... but it wasn't smart enough and didn't
forward transfer encodings and connection state correctly.

Solution:
Drop code that didn't work and tried to do things it shouldn't try to do. 'hg
serve' will now trust the WSGI app more and control less.  As a consequence of
this http connections will often be kept alive longer.

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -151,6 +151,9 @@
             if h[0].lower() == 'content-length':
                 should_close = False
                 self.length = int(h[1])
+            elif (h[0].lower() == 'transfer-encoding' and
+                  h[1].lower() == 'chunked'):
+                should_close = False
         # The value of the Connection header is a list of case-insensitive
         # tokens separated by commas and optional whitespace.
         if should_close:
diff --git a/tests/test-https.t b/tests/test-https.t
--- a/tests/test-https.t
+++ b/tests/test-https.t
@@ -124,7 +124,6 @@
   adding manifests
   adding file changes
   added 1 changesets with 4 changes to 4 files
-  warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting)
   updating to branch default
   4 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg verify -R copy-pull
@@ -152,7 +151,6 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting)
   changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=https://localhost:$HGPORT/
   (run 'hg update' to get a working copy)
   $ cd ..


More information about the Mercurial-devel mailing list