[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>
changeset691cbfc89f83
branchdefault
phasedraft
hiddenyes
parent revision#f79ce7b39ee9 [web/ajax] Always return a json dict with a 'reason' key in case of ajax errors
child revision<not specified>
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 691cbfc89f83aa0b583497e249246e8e1bc8fbdd
# Parent f79ce7b39ee9e4cebb9a3eb7bef1e465c3de566a
[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                 ]