def get(self, path): response = None langQS = self.request.get('hl', None) langCookie = self.request.cookies.get('hl') if langQS: lang = langQS elif langCookie: lang = langCookie else: lang = DEFAULT_LANG self.response.set_cookie('hl', lang, max_age=3600, path='/') fullPath = self.request.path memcacheKey = fullPath + '?hl=' + lang logging.info('GET ' + memcacheKey) if USE_MEMCACHE: response = memcache.get(memcacheKey) if response: logging.info('304 ' + fullPath) if response is None: try: if path.endswith('/') or path == '': response = devsiteIndex.getPage(path, lang) else: response = devsitePage.getPage(path, lang) if response is None: # No file found, check for redirect redirectTo = devsiteHelper.checkForRedirect( fullPath, lang, USE_MEMCACHE) if redirectTo: logging.info('301 ' + redirectTo) self.redirect(redirectTo, permanent=True) return # No redirect found, send the 404 page. response = render('gae/404.tpl', {'requestPath': fullPath}) logging.error('404 ' + fullPath) self.response.set_status(404) else: logging.info('200 ' + fullPath) if USE_MEMCACHE: memcache.set(memcacheKey, response) except Exception as ex: context = {'content': ex, 'requestPath': fullPath} response = render('gae/500.tpl', context) logging.exception('500 ' + fullPath) self.response.set_status(500) self.response.out.write(response)
def get(self, path): response = None langQS = self.request.get('hl', None) langCookie = self.request.cookies.get('hl') if langQS: lang = langQS elif langCookie: lang = langCookie else: lang = DEFAULT_LANG self.response.set_cookie('hl', lang, max_age=3600, path='/') fullPath = self.request.path memcacheKey = fullPath + '?hl=' + lang logging.info('GET ' + memcacheKey) if USE_MEMCACHE: response = memcache.get(memcacheKey) if response: logging.info('304 ' + fullPath) if response is None: try: if path.endswith('/') or path == '': response = devsiteIndex.getPage(path, lang) else: response = devsitePage.getPage(path, lang) if response is None: # No file found, check for redirect redirectTo = devsiteHelper.checkForRedirect(fullPath, lang, USE_MEMCACHE) if redirectTo: logging.info('301 ' + redirectTo) self.redirect(redirectTo, permanent=True) return # No redirect found, send the 404 page. response = render('gae/404.tpl', {'requestPath': fullPath}) logging.error('404 ' + fullPath) self.response.set_status(404) else: logging.info('200 ' + fullPath) if USE_MEMCACHE: memcache.set(memcacheKey, response) except Exception as ex: context = {'content': ex, 'requestPath': fullPath} response = render('gae/500.tpl', context) logging.exception('500 ' + fullPath) self.response.set_status(500) self.response.out.write(response)
def get(self, path): self.response.headers.add('x-frame-options', 'SAMEORIGIN') if path.endswith('.html') or path.endswith('.md'): redirectTo = '/web/' + os.path.splitext(path)[0] self.redirect(redirectTo, permanent=True) return response = None langQS = self.request.get('hl', None) langCookie = self.request.cookies.get('hl') if langQS: lang = langQS elif langCookie: lang = langCookie else: lang = DEFAULT_LANG self.response.set_cookie('hl', lang, max_age=3600, path='/') fullPath = self.request.path memcacheKey = self.request.host + fullPath + '?hl=' + lang logging.info('GET ' + memcacheKey) if USE_MEMCACHE: response = memcache.get(memcacheKey) if response: logging.info('304 ' + fullPath) if response is None: try: if os.path.isdir(os.path.join(SOURCE_PATH, 'en', path)): # Make sure the directory ends with a /, as required by devsite if len(path) > 0 and not path.endswith('/'): redirectTo = '/web/' + path + '/' logging.info('301 ' + redirectTo) self.redirect(redirectTo, permanent=True) return response = devsiteIndex.getPage(path, lang) if (response is None) and (path.startswith('showcase') or path.startswith('shows') or path.startswith('updates')): response = devsiteIndex.getDirIndex(path) else: response = devsitePage.getPage(path, lang) if response is None: # No file found, check for redirect redirectTo = devsiteHelper.checkForRedirect(fullPath, lang, USE_MEMCACHE) if redirectTo: logging.info('301 ' + redirectTo) self.redirect(redirectTo, permanent=True) return # No redirect found, send the 404 page. response = render('gae/404.tpl', {'requestPath': fullPath}) logging.error('404 ' + fullPath) self.response.set_status(404) else: logging.info('200 ' + fullPath) if USE_MEMCACHE: memcache.set(memcacheKey, response) except Exception as ex: context = {'content': ex, 'requestPath': fullPath} response = render('gae/500.tpl', context) logging.exception('500 ' + fullPath) self.response.set_status(500) self.response.out.write(response)