wagtailtrans icon indicating copy to clipboard operation
wagtailtrans copied to clipboard

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

Open Quadric opened this issue 5 years ago • 1 comments

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

Quadric avatar Nov 14 '19 11:11 Quadric

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.

mikedingjan avatar Jun 25 '20 17:06 mikedingjan