wagtail / wagtailtrans

A Wagtail add-on for supporting multilingual sites
http://wagtailtrans.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
104 stars 60 forks source link

Is it necessary to set language cookie on every response in TranslationMiddleware? #171

Open Quadric opened 4 years ago

Quadric commented 4 years ago

Issue summary

In TranslationMiddleware on process_response "set_cookie" is executed on every response - even when proper cookie for specific language is already set. This leads to problem with proxies and caching. If response sets a cookie most standard proxy configuration will prevent this response from being cached (304 Not modfied etc)

How to reproduce?

1) Open a TranslateableSite with enabled TranslationMiddleware 2) You'll see "set-cookie: django_language=pl; Path=/" 3) You'll see above everytime in response

Technical details

Python version: 3.6.4 Django version: 2.2.6 Wagtail version: 2.6.3 Wagtaltrans version: 2.0.6

mikedingjan commented 4 years ago

If a proper check can be implemented for the cookie if the value doesn't change, I don't see any problems with changing this to only set it when the value changes.