Compare commits

..

1 Commits

Author SHA1 Message Date
Jonas Schäfer
20abe4b903 Add Vary: Accept-Language to all pages using that information
It was found during testing that some user agents cache aggressively
even between switches of the UI language. To properly indicate that the
pages actually depend on that information, we add the correct Vary
header.

Fixes #106.
2022-01-22 15:19:29 +01:00
4 changed files with 18 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import quart.flask_patch # noqa:F401
from quart import (
current_app,
request,
g,
)
import flask_babel
@@ -34,6 +35,9 @@ BYTE_UNIT_SCALE_MAP = [
@babel.localeselector # type:ignore
def selected_locale() -> str:
# Needs mypy ignore because this is a free-for-all object and has no
# publicly known attributes.
g.language_header_accessed = True # type: ignore
selected = request.accept_languages.best_match(
current_app.config['LANGUAGES']
) or current_app.config['LANGUAGES'][0]
@@ -68,6 +72,12 @@ def format_bytes(n: float) -> str:
return "{}{}".format(n, unit)
def add_vary_language_header(resp: quart.Response) -> quart.Response:
if getattr(g, "language_header_accessed", False):
resp.vary.add("Accept-Language")
return resp
def init_templating(app: quart.Quart) -> None:
app.template_filter("repr")(repr)
app.template_filter("format_datetime")(flask_babel.format_datetime)
@@ -78,6 +88,7 @@ def init_templating(app: quart.Quart) -> None:
app.template_filter("format_bytes")(format_bytes)
app.template_filter("flatten")(flatten)
app.template_filter("circle_name")(circle_name)
app.after_request(add_vary_language_header)
def generate_error_id() -> str:

View File

@@ -28,12 +28,12 @@
</div>
<div class="f-ebox">
{{ form.password.label }}
{{ form.password(autocomplete="new-password") }}
{{ form.password }}
<p class="field-desc weak">{% trans %}Enter a secure password that you do not use anywhere else.{% endtrans %}</p>
</div>
<div class="f-ebox">
{{ form.password_confirm.label }}
{{ form.password_confirm(autocomplete="new-password") }}
{{ form.password_confirm }}
</div>
<div class="f-bbox">
{%- call form_button("done", form.action_register, class="primary") -%}{%- endcall -%}

View File

@@ -17,11 +17,11 @@
{%- call render_errors(form) %}{% endcall -%}
<div class="f-ebox">
{{ form.password.label }}
{{ form.password(autocomplete="new-password") }}
{{ form.password }}
</div>
<div class="f-ebox">
{{ form.password_confirm.label }}
{{ form.password_confirm(autocomplete="new-password") }}
{{ form.password_confirm }}
</div>
<div class="f-bbox">
{%- call form_button("passwd", form.action_reset, class="primary") -%}{%- endcall -%}

View File

@@ -9,15 +9,15 @@
{%- endcall -%}
<div class="f-ebox">
{{ form.current_password.label(class="required") }}
{{ form.current_password(class=("has-error" if form.current_password.name in form.errors else ""), autocomplete="current-password") }}
{{ form.current_password(class=("has-error" if form.current_password.name in form.errors else "")) }}
</div>
<div class="f-ebox">
{{ form.new_password.label(class="required") }}
{{ form.new_password(autocomplete="new-password") }}
{{ form.new_password }}
</div>
<div class="f-ebox">
{{ form.new_password_confirm.label(class="required") }}
{{ form.new_password_confirm(class=("has-error" if form.new_password_confirm.name in form.errors else ""), autocomplete="new-password") }}
{{ form.new_password_confirm(class=("has-error" if form.new_password_confirm.name in form.errors else "")) }}
</div>
<div class="box warning">
<header>{% trans %}Warning{% endtrans %}</header>