Commit cf562437 authored by Julien Cristau's avatar Julien Cristau
Browse files

[web] only set "Vary: Accept-Language" when we translate something

Some requests never go through gettext, so their result doesn't depend
on the selected language.
parent cfb2f0251316
Pipeline #39562 passed with stages
in 35 minutes and 9 seconds
......@@ -27,6 +27,7 @@ import http.client
from io import BytesIO
from urllib.parse import urlsplit, quote as urlquote
from http.cookies import SimpleCookie
from functools import wraps
from rql.utils import rqlvar_maker
......@@ -842,6 +843,22 @@ class _CubicWebRequestBase(RequestSessionBase):
return lang
return None
def set_language_from_req(self, lang):
# The chosen language comes from the request's Accept-Language header:
# if we ever translate something, set Vary to indicate that our response
# depends on that request header.
self.set_language(lang)
def add_headers_on_call(func):
@wraps(func)
def tr(*args, **kwargs):
self.headers_out.addHeader('Vary', 'Accept-Language')
return func(*args, **kwargs)
return tr
self._ = add_headers_on_call(self._)
self.__ = add_headers_on_call(self.__)
self.pgettext = add_headers_on_call(self.pgettext)
def _cnx_func(name):
def proxy(req, *args, **kwargs):
......
......@@ -129,7 +129,10 @@ class URLPublisherComponent(component.Component):
# negotiated language
lang = req.negotiated_language()
if lang:
req.set_language(lang)
if language_mode == 'http-negotiation':
req.set_language_from_req(lang)
else:
req.set_language(lang)
origin_rql = req.form.get('rql')
if origin_rql:
if parts[0] in self.vreg['controllers']:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment