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

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 11, 2013, 11:32 p.m.
Message ID <c554ae0503419c8c5fc2.1357947176@mk-desktop>
Download mbox | patch
Permalink /patch/572/
State Superseded
Headers show

Comments

Mads Kiilerich - Jan. 11, 2013, 11:32 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@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.
Augie Fackler - Jan. 14, 2013, 7:43 p.m.
On Sat, Jan 12, 2013 at 12:32:56AM +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@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

This change fixes these fingerprint warnings? Really? how?

> @@ -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 ..
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Mads Kiilerich - Jan. 14, 2013, 11:53 p.m.
Augie Fackler wrote, On 01/14/2013 08:43 PM:
> On Sat, Jan 12, 2013 at 12:32:56AM +0100, Mads Kiilerich wrote:
>> # HG changeset patch
>> # User Mads Kiilerich <madski@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
> This change fixes these fingerprint warnings? Really? how?

The tests have the same warning a couple of lines before the diff chunk.

The warnings were caused by creating a new connection after hgweb had 
closed the connection after sending the bundle with unknown length. Now 
the connection will be kept alive.

/Mads

>
>> @@ -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 ..
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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 ..