@@ -115,6 +115,7 @@ def TrueGet(self, reqUri):
115
115
urlLangName = None
116
116
retry = False
117
117
isValidIntl = False
118
+ isStripped = False
118
119
119
120
# Try to retrieve the user's lang pref from the cookie. If there is no
120
121
# lang pref cookie in the request, add set-cookie to the response with the
@@ -124,7 +125,7 @@ def TrueGet(self, reqUri):
124
125
except KeyError :
125
126
resetLangCookie = True
126
127
#logging.info('==========================EXCEPTION: NO LANG COOKIE FOUND, USING [%s]', langName)
127
- logging .info ('==========================REQ INIT name [%s] langName [%s]' , reqUri , langName )
128
+ logging .info ('==========================REQ INIT name [%s] langName [%s] resetLangCookie [%s] ' , reqUri , langName , resetLangCookie )
128
129
129
130
# Preprocess the req url. If it references a directory or the domain itself,
130
131
# append '/index.html' to the url and 302 redirect. Otherwise, continue
@@ -142,19 +143,23 @@ def TrueGet(self, reqUri):
142
143
if isValidIntl :
143
144
urlLangName = sections [1 ]
144
145
contentUri = sections [2 ]
145
- if (langName != urlLangName ):
146
+ logging .info (' Content URI is [%s]...' , contentUri )
147
+ if (urlLangName != langName ) or (langName == 'en' ):
146
148
# if the lang code in the request is different from that in
147
- # the cookie, reset the cookie to the url lang value.
148
- langName = urlLangName
149
- resetLangCookie = True
150
- #logging.info('INTL PREP resetting langName to urlLangName [%s]', langName)
151
- #else:
152
- # logging.info('INTL PREP no need to reset langName')
149
+ # the cookie, or if the target lang is en, strip the
150
+ # intl/nn substring. It will later be redirected to
151
+ # the user's preferred language url.
152
+ # logging.info(' Handling a MISMATCHED intl request')
153
+ name = contentUri
154
+ isStripped = True
155
+ isValidIntl = False
156
+ isIntl = False
153
157
154
158
# Send for processing
155
- if self .isCleanUrl (name , langName , isValidIntl ):
159
+ if self .isCleanUrl (name , langName , isValidIntl , isStripped ):
156
160
# handle a 'clean' request.
157
161
# Try to form a response using the actual request url.
162
+ # logging.info(' Request being handled as clean: [%s]', name)
158
163
if not self .CreateResponse (name , langName , isValidIntl , resetLangCookie ):
159
164
# If CreateResponse returns False, there was no such document
160
165
# in the intl/lang tree. Before going to 404, see if there is an
@@ -167,7 +172,7 @@ def TrueGet(self, reqUri):
167
172
# for processing (so as to get 404 as appropriate). This is needed
168
173
# because intl urls are passed through clean and retried in English,
169
174
# if necessary.
170
- logging .info (' Handling an invalid intl request...' )
175
+ # logging.info(' Handling an invalid intl request...')
171
176
self .CreateResponse (name , langName , isValidIntl , resetLangCookie )
172
177
173
178
else :
@@ -178,7 +183,7 @@ def TrueGet(self, reqUri):
178
183
# request will be handled as a clean url.
179
184
self .RedirToIntl (name , self .intlString , langName )
180
185
181
- def isCleanUrl (self , name , langName , isValidIntl ):
186
+ def isCleanUrl (self , name , langName , isValidIntl , isStripped ):
182
187
"""Determine whether to pass an incoming url straight to processing.
183
188
184
189
Args:
@@ -187,13 +192,14 @@ def isCleanUrl(self, name, langName, isValidIntl):
187
192
Returns:
188
193
boolean: Whether the URL should be sent straight to processing
189
194
"""
190
- if (langName == 'en' ) or isValidIntl or not ('.html' in name ) or (not isValidIntl and not langName ):
195
+ # logging.info(' >>>> isCleanUrl name [%s] langName [%s] isValidIntl [%s]', name, langName, isValidIntl)
196
+ if (langName == 'en' and not isStripped ) or isValidIntl or not ('.html' in name ) or (not isValidIntl and not langName ):
191
197
return True
192
198
193
199
def PreprocessUrl (self , name , langName ):
194
200
"""Any preprocessing work on the URL when it comes in.
195
201
196
- Put any work related to interpretting the incoming URL here. For example,
202
+ Put any work related to interpreting the incoming URL here. For example,
197
203
this is used to redirect requests for a directory to the index.html file
198
204
in that directory. Subclasses should override this method to do different
199
205
preprocessing.
@@ -216,7 +222,7 @@ def PreprocessUrl(self, name, langName):
216
222
# if this is a directory or the domain itself, redirect to /index.html
217
223
if not name or (name [len (name ) - 1 :] == '/' ):
218
224
uri = '' .join (['/' , name , 'index.html' ])
219
- logging .info ('--->PREPROCESSING REDIRECT [%s] to [%s] with langName [%s]' , name , uri , langName )
225
+ # logging.info('--->PREPROCESSING REDIRECT [%s] to [%s] with langName [%s]', name, uri, langName)
220
226
self .redirect (uri , False )
221
227
return False
222
228
else :
@@ -225,18 +231,21 @@ def PreprocessUrl(self, name, langName):
225
231
def RedirToIntl (self , name , intlString , langName ):
226
232
"""Redirect an incoming request to the appropriate intl uri.
227
233
228
- Builds the intl/lang string from a base (en) string
229
- and redirects (302) the request to look for a version
230
- of the file in the language that matches the client-
231
- supplied cookie value .
234
+ For non-en langName, builds the intl/lang string from a
235
+ base (en) string and redirects (302) the request to look for
236
+ a version of the file in langName. For en langName, simply
237
+ redirects a stripped uri string (intl/nn removed) .
232
238
233
239
Args:
234
240
name: The incoming, preprocessed URL
235
241
236
242
Returns:
237
243
The lang-specific URL
238
244
"""
239
- builtIntlLangUri = '' .join ([intlString , langName , '/' , name , '?' , self .request .query_string ])
245
+ if not (langName == 'en' ):
246
+ builtIntlLangUri = '' .join ([intlString , langName , '/' , name , '?' , self .request .query_string ])
247
+ else :
248
+ builtIntlLangUri = name
240
249
uri = '' .join (['/' , builtIntlLangUri ])
241
250
logging .info ('-->>REDIRECTING %s to %s' , name , uri )
242
251
self .redirect (uri , False )
@@ -313,7 +322,7 @@ def CreateResponse(self, name, langName, isValidIntl, resetLangCookie):
313
322
# revalidate html files -- workaround for cache inconsistencies for
314
323
# negotiated responses
315
324
mustRevalidate = True
316
- logging .info (' Adding [Vary: Cookie] to response...' )
325
+ # logging.info(' Adding [Vary: Cookie] to response...')
317
326
self .response .headers .add_header ('Vary' , 'Cookie' )
318
327
content_type , encoding = mimetypes .guess_type (name )
319
328
if content_type :
@@ -491,7 +500,7 @@ def SetCachingHeaders(self, revalidate):
491
500
max_age = self .MAX_AGE
492
501
#self.response.headers['Expires'] = email.Utils.formatdate(
493
502
# time.time() + max_age, usegmt=True)
494
- cache_control = []
503
+ cache_control = []
495
504
if self .PUBLIC :
496
505
cache_control .append ('public' )
497
506
cache_control .append ('max-age=%d' % max_age )
0 commit comments