[web.views] add Link alternate in HTTP response header in HTML view
Team: famarger, schabot, nchauvat, fferry, ethieblin
--- 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: