Vary caching on Accept-Language header if it is used
If we use the Accept-Language header to determine the interface language, we need to vary caching on it so that a user with a different Accept-Language header won't get the wrong language out of the cache. Note that for optimal cache hitrates, you might want to implement parsing of the header in your cache itself. Bug: T203179 Change-Id: I976696cf20a5da5b2767c87e0d754a901b711a46
This commit is contained in:
@@ -223,6 +223,14 @@ class UniversalLanguageSelectorHooks {
|
||||
public static function getLanguage( User $user, &$code, IContextSource $context ) {
|
||||
global $wgULSAnonCanChangeLanguage, $wgULSLanguageDetection;
|
||||
|
||||
if ( $wgULSLanguageDetection ) {
|
||||
// Vary any caching based on the header value. Note that
|
||||
// we need to vary regardless of whether we end up using
|
||||
// the header or not, so that requests without the header
|
||||
// don't show up for people with it.
|
||||
$context->getOutput()->addVaryHeader( 'Accept-Language' );
|
||||
}
|
||||
|
||||
if ( !self::isToolbarEnabled( $user ) ) {
|
||||
return;
|
||||
}
|
||||
@@ -276,6 +284,8 @@ class UniversalLanguageSelectorHooks {
|
||||
|
||||
// As last resort, try Accept-Language headers if allowed
|
||||
if ( $wgULSLanguageDetection ) {
|
||||
// We added a Vary header at the top of this function,
|
||||
// since we're depending upon the Accept-Language header
|
||||
$preferred = $request->getAcceptLang();
|
||||
$default = self::getDefaultLanguage( $preferred );
|
||||
if ( $default !== '' ) {
|
||||
|
||||
Reference in New Issue
Block a user