def process_request(self, base_url, post_data=None): assert base_url translated_address = self.get_translated_address() mirrored_url = translated_address base_url = self.get_base(mirrored_url) # Log the user-agent and referrer, to see who is linking to us. logging.debug('User-Agent = "%s", Referrer = "%s"', self.request.user_agent, self.request.referer) #logging.debug('Base_url = "%s", url = "%s"', base_url, self.request.url) #logging.info('Base_url = "%s", url = "%s"', base_url, self.request.url) # Use sha256 hash instead of mirrored url for the key name, since key # names can only be 500 bytes in length; URLs may be up to 2KB. key_name = get_url_key_name(mirrored_url) logging.info(u"\n\nHandling request for '%s' = '%s'", mirrored_url, key_name) content = CookieHelper.useCache( self) and MirroredContent.get_by_key_name(key_name) or None if content is None: logging.debug("Cache miss") ChineseWordsencoding = CookieHelper.ChineseWordsencoding(self) EncodingWhiteList = CookieHelper.EncodingWhiteList(self) content = MirroredContent.fetch_and_store(key_name, base_url, translated_address, mirrored_url, post_data, ChineseWordsencoding, EncodingWhiteList) if content is None: #return self.error(404) self.response.out.write( template.render( "default_error.html", { 'msg': 'Sorry, Error occurred!!', 'change_url': self.get_change_root(), })) return for key, value in content.headers.iteritems(): self.response.headers[key] = value if not mirror_const.DEBUG: self.response.headers['cache-control'] = \ 'max-age=%d' % mirror_const.EXPIRATION_DELTA_SECONDS self.response.out.write(content.data)
def get(self): #load from cookie ChineseWordsencoding = CookieHelper.ChineseWordsencoding(self) useCache = CookieHelper.useCache(self) EncodingWhiteList = CookieHelper.EncodingWhiteList(self) logging.info(EncodingWhiteList) cookies = { 'ChineseWordsencoding': ChineseWordsencoding, 'useCache': useCache, 'EncodingWhiteList': EncodingWhiteList.replace('$', '\n'), } self.response.out.write( template.render( "mirror_setup.html", { 'msg': 'SETUP', 'cookies': cookies, 'change_url': self.get_change_root(), }))