コード例 #1
0
ファイル: cache.py プロジェクト: Cerdic/myCDN
	def POST(self, request):
		if self.ignoreQueryString is False:
			request += web.ctx.query
		url = self.origin + request
		if self.forwardPost is False:
			raise web.SeeOther(url, absolute=True)
		response = forward.forwardRequest(url, method=web.ctx.method)
		forward.forwardResponse(response)
コード例 #2
0
 def POST(self, request):
     if self.ignoreQueryString is False:
         request += web.ctx.query
     url = self.origin + request
     if self.forwardPost is False:
         raise web.SeeOther(url, absolute=True)
     response = forward.forwardRequest(url, method=web.ctx.method)
     forward.forwardResponse(response)
コード例 #3
0
ファイル: cache.py プロジェクト: Cerdic/myCDN
			if cache:
				return cache
			logging.warning('urlfetch error, redirect to origin. (%s: %s)' % (type(e), e))
			raise web.SeeOther(url, absolute=True)
		if response.status_code == 304:
			logging.debug('304, update cache meta')
			cache.lastRefresh = datetime.datetime.utcnow()
			cache.expires = cache.lastRefresh + datetime.timedelta(seconds=cache.maxAge)
			cache.put()
			self.memcacheSet(key=request, value=cache, time=cache.expires)
			return cache
		elif response.status_code == 404:
			if cache:
				cache.delete()
				memcache.delete(request)
			forward.forwardResponse(response)
		elif cache and response.status_code >= 500:
			logging.warning('500, serving cache copy')
			return cache
		elif response.status_code != 200:
			forward.forwardResponse(response)
		cache = self.cache(key_name=request)
		cache.data = db.Blob(response.content)
		cache.maxAge = self.getMaxAge(response.headers)
		cache.lastRefresh = datetime.datetime.utcnow()
		if not 'last-modified' in response.headers:
			cache.lastModified = cache.lastRefresh
		else:
			cache.lastModified = web.parsehttpdate(response.headers['last-modified'])
		cache.expires = cache.lastRefresh + datetime.timedelta(seconds=cache.maxAge)
		for h in self.headerBlacklist:
コード例 #4
0
     if cache:
         return cache
     logging.warning('urlfetch error, redirect to origin. (%s: %s)' % (type(e), e))
     raise web.SeeOther(url, absolute=True)
 if response.status_code == 304:
     logging.debug('304, update cache meta')
     cache.lastRefresh = datetime.datetime.utcnow()
     cache.expires = cache.lastRefresh + datetime.timedelta(seconds=cache.maxAge)
     cache.put()
     self.memcacheSet(key=request, value=cache, time=cache.expires)
     return cache
 elif response.status_code == 404:
     if cache:
         cache.delete()
         memcache.delete(request)
     forward.forwardResponse(response)
 elif cache and response.status_code >= 500:
     logging.warning('500, serving cache copy')
     return cache
 elif response.status_code != 200:
     forward.forwardResponse(response)
 # got 200, new content
 cache = self.cache(key_name=request)
 data = response.content
 if not _beforeWriteCache is None:
     data = _beforeWriteCache(data)
 cache.data = db.Blob(data)
 if self.prefetch:
     self.prefetchContent(response)
 cache.maxAge = self.getMaxAge(response.headers)
 cache.lastRefresh = datetime.datetime.utcnow()