Patchwork serve: don't send any content headers for 304

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 15, 2013, 4:48 p.m.
Message ID <daefbb3a094b919dc92a.1358268491@mk-desktop>
Download mbox | patch
Permalink /patch/630/
State Accepted
Headers show

Comments

Mads Kiilerich - Jan. 15, 2013, 4:48 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1358267982 -3600
# Node ID daefbb3a094b919dc92af3c9bf9bcb45a8b32607
# Parent  404feac78b8a4ee77d13ac7b5271e1606b580797
serve: don't send any content headers for 304

Fixes protocol violation when content haven't been modified.
Thomas Arendsen Hein - Jan. 15, 2013, 7:49 p.m.
* Mads Kiilerich <mads@kiilerich.com> [20130115 17:49]:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1358267982 -3600
> # Node ID daefbb3a094b919dc92af3c9bf9bcb45a8b32607
> # Parent  404feac78b8a4ee77d13ac7b5271e1606b580797
> serve: don't send any content headers for 304
> 
> Fixes protocol violation when content haven't been modified.

Works for me.

Regards,
Thomas
Mads Kiilerich - Jan. 15, 2013, 8:02 p.m.
On 01/15/2013 08:49 PM, Thomas Arendsen Hein wrote:
> * Mads Kiilerich <mads@kiilerich.com> [20130115 17:49]:
>> # HG changeset patch
>> # User Mads Kiilerich <madski@unity3d.com>
>> # Date 1358267982 -3600
>> # Node ID daefbb3a094b919dc92af3c9bf9bcb45a8b32607
>> # Parent  404feac78b8a4ee77d13ac7b5271e1606b580797
>> serve: don't send any content headers for 304
>>
>> Fixes protocol violation when content haven't been modified.
> Works for me.
>

In crew

/Mads

Patch

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -153,7 +153,8 @@ 
             self.send_header(*h)
             if h[0].lower() == 'content-length':
                 self.length = int(h[1])
-        if self.length is None:
+        if (self.length is None and
+            saved_status[0] != common.HTTP_NOT_MODIFIED):
             self._chunked = (not self.close_connection and
                              self.request_version == "HTTP/1.1")
             if self._chunked:
diff --git a/tests/get-with-headers.py b/tests/get-with-headers.py
--- a/tests/get-with-headers.py
+++ b/tests/get-with-headers.py
@@ -31,6 +31,8 @@ 
     conn.request("GET", '/' + path, None, headers)
     response = conn.getresponse()
     print response.status, reasons.get(response.reason, response.reason)
+    if show[:1] == ['-']:
+        show = [h for h, v in response.getheaders() if h.lower() not in show]
     for h in [h.lower() for h in show]:
         if response.getheader(h, None) is not None:
             print "%s: %s" % (h, response.getheader(h))
diff --git a/tests/test-hgweb.t b/tests/test-hgweb.t
--- a/tests/test-hgweb.t
+++ b/tests/test-hgweb.t
@@ -310,8 +310,10 @@ 
 
 static file
 
-  $ "$TESTDIR/get-with-headers.py" --twice localhost:$HGPORT 'static/style-gitweb.css'
+  $ "$TESTDIR/get-with-headers.py" --twice localhost:$HGPORT 'static/style-gitweb.css' - date etag server
   200 Script output follows
+  content-length: 4619
+  content-type: text/css
   
   body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
   a { color:#0000cc; }