[web] Fix HEAD request handling (closes #3677949)

Don't special-case HEAD in CubicWebRequestBase.is_client_cache_valid so we don't return garbage. HEAD is supposed to return the actual headers that a GET would return, which we can't do if we bypass all the normal cubicweb logic. In particular, we no longer always return 200, and return the right Content-Length/Content-Type/...

authorJulien Cristau <julien.cristau@logilab.fr>
changesete0b3fcf1c205
branchdefault
phasepublic
hiddenno
parent revision#8347e6d613c9 [web/test] add a test for some http response codes
child revision#c6f47e635845 [wsgi] look at wsgi.url_scheme to decide if we're on https
files modified by this revision
web/request.py
web/test/unittest_http.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1395653698 -3600
# Mon Mar 24 10:34:58 2014 +0100
# Node ID e0b3fcf1c205ca1aa464bf680ba73624a3155d2a
# Parent 8347e6d613c9066547478fae9d464e99d0467386
[web] Fix HEAD request handling (closes #3677949)

Don't special-case HEAD in CubicWebRequestBase.is_client_cache_valid so
we don't return garbage. HEAD is supposed to return the actual headers
that a GET would return, which we can't do if we bypass all the normal
cubicweb logic. In particular, we no longer always return 200, and
return the right Content-Length/Content-Type/...

diff --git a/web/request.py b/web/request.py
@@ -767,14 +767,10 @@
1          # Forge expected response
2          if modified:
3              if 'Expires' not in self.headers_out:
4                  # Expires header seems to be required by IE7 -- Are you sure ?
5                  self.add_header('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
6 -            if self.http_method() == 'HEAD':
7 -                self.status_out = 200
8 -                # XXX replace by True once validate_cache bw compat method is dropped
9 -                return 200
10              # /!\ no raise, the function returns and we keep processing the request
11          else:
12              # overwrite headers_out to forge a brand new not-modified response
13              self.headers_out = self._forge_cached_headers()
14              if self.http_method() in ('HEAD', 'GET'):
diff --git a/web/test/unittest_http.py b/web/test/unittest_http.py
@@ -225,11 +225,11 @@
15          hin  = [('if-none-match', 'babar'),
16                 ]
17          hout = [('etag', 'rhino/really-not-babar'),
18                 ]
19          req = _test_cache(hin, hout, method='HEAD')
20 -        self.assertCache(200, req.status_out, 'modifier HEAD verb')
21 +        self.assertCache(None, req.status_out, 'modifier HEAD verb')
22          # not modified
23          hin  = [('if-none-match', 'babar'),
24                 ]
25          hout = [('etag', 'babar'),
26                 ]