Patchwork [stable] hgweb.cgi: fix internal WSGI emulation (issue3804)

login
register
mail settings
Submitter Mads Kiilerich
Date Feb. 4, 2013, 3:51 p.m.
Message ID <8fff1e69052818a40110.1359993087@mk-desktop>
Download mbox | patch
Permalink /patch/798/
State Superseded
Commit e8efcc8ff5c0b1b16f2a6f22f4375c0002133aff
Headers show

Comments

Mads Kiilerich - Feb. 4, 2013, 3:51 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1359993046 -3600
# Branch stable
# Node ID 8fff1e69052818a40110eb00589742dd40bd2fde
# Parent  12de53323e59ce3e5f31472ee781649669d6ca9c
hgweb.cgi: fix internal WSGI emulation (issue3804)

The internal WSGI emulation in wsgicgi.py was not fully WSGI compliant and
assumed that all responses sent a body. With 3fbdbeab38cc that caused a real
bug when using hgweb.cgi.

wsgicgi.py will now make sure headers always are sent, using the pattern from
PEP 333 and similar to how it is done in c007e5c54b16.
Mads Kiilerich - Feb. 4, 2013, 10:29 p.m.
On 02/04/2013 04:51 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1359993046 -3600
> # Branch stable
> # Node ID 8fff1e69052818a40110eb00589742dd40bd2fde
> # Parent  12de53323e59ce3e5f31472ee781649669d6ca9c
> hgweb.cgi: fix internal WSGI emulation (issue3804)
>
> The internal WSGI emulation in wsgicgi.py was not fully WSGI compliant and
> assumed that all responses sent a body. With 3fbdbeab38cc that caused a real
> bug when using hgweb.cgi.
>
> wsgicgi.py will now make sure headers always are sent, using the pattern from
> PEP 333 and similar to how it is done in c007e5c54b16.

In crew stable

/Mads

Patch

diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py
--- a/mercurial/hgweb/wsgicgi.py
+++ b/mercurial/hgweb/wsgicgi.py
@@ -77,5 +77,7 @@ 
     try:
         for chunk in content:
             write(chunk)
+        if not headers_sent:
+            write('')   # send headers now if body was empty
     finally:
         getattr(content, 'close', lambda : None)()
diff --git a/tests/test-clone-cgi.t b/tests/test-clone-cgi.t
--- a/tests/test-clone-cgi.t
+++ b/tests/test-clone-cgi.t
@@ -29,3 +29,11 @@ 
   $ python hgweb.cgi >page1 2>&1
   $ python "$TESTDIR/md5sum.py" page1
   1f424bb22ec05c3c6bc866b6e67efe43  page1
+
+make sure headers are sent even when there is no body
+
+  $ QUERY_STRING="cmd=listkeys&namespace=nosuchnamespace" python hgweb.cgi
+  Status: 200 Script output follows\r (esc)
+  Content-Type: application/mercurial-0.1\r (esc)
+  Content-Length: 0\r (esc)
+  \r (esc)