[web.views] add Link alternate in HTTP response header in HTML view
authorFabien Amarger <fabien.amarger@logilab.fr>
Tue, 10 Mar 2020 17:37:43 +0100
changeset 12912 3966f09d5f5c
parent 12911 a17cbf539a69
child 12913 ebf4806e4ab7
[web.views] add Link alternate in HTTP response header in HTML view Team: famarger, schabot, nchauvat, fferry, ethieblin
cubicweb/web/views/basecontrollers.py
--- a/cubicweb/web/views/basecontrollers.py	Tue Mar 10 23:47:50 2020 +0100
+++ b/cubicweb/web/views/basecontrollers.py	Tue Mar 10 17:37:43 2020 +0100
@@ -23,7 +23,7 @@
 
 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
                       AuthenticationError, UndoTransactionException,
-                      Forbidden)
+                      Forbidden, rdf)
 from cubicweb.utils import json_dumps
 from cubicweb.predicates import (authenticated_user, anonymous_user,
                                 match_form_params)
@@ -101,6 +101,10 @@
             else:
                 rset = None
         vid = req.form.get('vid') or vid_from_rset(req, rset, self._cw.vreg.schema)
+        if rset and len(rset) == 1:
+            for mimetype in rdf.RDF_MIMETYPE_TO_FORMAT:
+                req.headers_out.addRawHeader(
+                    'Link', "<%s>;rel=alternate;type=%s" % (rset.one().cwuri, mimetype))
         try:
             view = self._cw.vreg['views'].select(vid, req, rset=rset)
         except ObjectNotFound: