def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.response_access_control: c.response.headers['Access-Control'] = c.response_access_control if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' #return #set content cache if (g.page_cache_time and request.method == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and not c.dontcache and response.status_code != 503 and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k,v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key = k, value = quote(v.value), domain = v.domain, expires = v.expires) if g.usage_sampling <= 0.0: return if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") amqp.add_kw("usage_q", start_time = c.start_time, end_time = datetime.now(g.tz), sampling_rate = g.usage_sampling, action = action)
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.response_access_control: c.response.headers['Access-Control'] = c.response_access_control if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' #return #set content cache if (g.page_cache_time and request.method == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and not c.dontcache and response.status_code != 503 and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k, v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key=k, value=quote(v.value), domain=v.domain, expires=v.expires) if g.usage_sampling <= 0.0: return if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") amqp.add_kw("usage_q", start_time=c.start_time, end_time=datetime.now(g.tz), sampling_rate=g.usage_sampling, action=action)
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' if c.deny_frames: response.headers["X-Frame-Options"] = "DENY" #return #set content cache if (g.page_cache_time and request.method.upper() == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code not in (429, 503) and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k,v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key = k, value = quote(v.value), domain = v.domain, expires = v.expires) end_time = datetime.now(g.tz) if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: amqp.add_kw("usage_q", start_time = c.start_time, end_time = end_time, sampling_rate = g.usage_sampling, action = action) check_request(end_time) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches() # push data to statsd if 'pylons.action_method' in request.environ: # only report web timing data if an action handler was called g.stats.transact('web.%s' % action, (end_time - c.start_time).total_seconds()) g.stats.flush_timing_stats()
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' if c.deny_frames: response.headers["X-Frame-Options"] = "DENY" #return #set content cache if (g.page_cache_time and request.method.upper() == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code not in (429, 503) and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k, v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key=k, value=quote(v.value), domain=v.domain, expires=v.expires) end_time = datetime.now(g.tz) if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: amqp.add_kw("usage_q", start_time=c.start_time, end_time=end_time, sampling_rate=g.usage_sampling, action=action) check_request(end_time) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches() # push data to statsd if 'pylons.action_method' in request.environ: # only report web timing data if an action handler was called g.stats.transact('web.%s' % action, (end_time - c.start_time).total_seconds()) g.stats.flush_timing_stats()
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.response_access_control: c.response.headers['Access-Control'] = c.response_access_control if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' #return #set content cache if (g.page_cache_time and request.method.upper() == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code != 503 and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k,v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key = k, value = quote(v.value), domain = v.domain, expires = v.expires) if g.logans_run_limit: if c.start_time > g.logans_run_limit and not g.shutdown: g.log.info("Time to restart. It's been an honor serving with you.") g.shutdown = 'init' if g.usage_sampling <= 0.0: return if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") amqp.add_kw("usage_q", start_time = c.start_time, end_time = datetime.now(g.tz), sampling_rate = g.usage_sampling, action = action) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches()
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = "".join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers["Content-Type"] = c.response_content_type if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers["Cache-Control"] = "no-cache" response.headers["Pragma"] = "no-cache" if c.deny_frames: response.headers["X-Frame-Options"] = "DENY" # return # set content cache if ( g.page_cache_time and request.method.upper() == "GET" and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code not in (429, 503) and response.content and response.content[0] ): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError as e: # this codepath will actually never be hit as long as # the pagecache memcached client is in no_reply mode. g.log.warning("Ignored exception (%r) on pagecache " "write for %r", e, request.path) # send cookies for k, v in c.cookies.iteritems(): if v.dirty: response.set_cookie( key=k, value=quote(v.value), domain=v.domain, expires=v.expires, secure=getattr(v, "secure", False), httponly=getattr(v, "httponly", False), ) end_time = datetime.now(g.tz) # update last_visit if c.user_is_loggedin and not g.disallow_db_writes and request.path != "/validuser": c.user.update_last_visit(c.start_time) if "pylons.routes_dict" in request.environ and "action" in request.environ["pylons.routes_dict"]: action = str(request.environ["pylons.routes_dict"]["action"]) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: amqp.add_kw( "usage_q", start_time=c.start_time, end_time=end_time, sampling_rate=g.usage_sampling, action=action ) check_request(end_time) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches() # push data to statsd if "pylons.action_method" in request.environ: # only report web timing data if an action handler was called g.stats.transact("web.%s" % action, (end_time - c.start_time).total_seconds()) g.stats.flush()
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = ''.join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers['Content-Type'] = c.response_content_type if c.response_access_control: c.response.headers['Access-Control'] = c.response_access_control if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers['Cache-Control'] = 'no-cache' response.headers['Pragma'] = 'no-cache' #return #set content cache if (g.page_cache_time and request.method.upper() == 'GET' and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code != 503 and response.content and response.content[0]): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k, v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key=k, value=quote(v.value), domain=v.domain, expires=v.expires) if g.logans_run_limit: if c.start_time > g.logans_run_limit and not g.shutdown: g.log.info( "Time to restart. It's been an honor serving with you.") g.shutdown = 'init' if g.usage_sampling <= 0.0: return if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: if ('pylons.routes_dict' in request.environ and 'action' in request.environ['pylons.routes_dict']): action = str(request.environ['pylons.routes_dict']['action']) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") amqp.add_kw("usage_q", start_time=c.start_time, end_time=datetime.now(g.tz), sampling_rate=g.usage_sampling, action=action) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches()
def post(self): response = c.response content = filter(None, response.content) if isinstance(content, (list, tuple)): content = "".join(content) for w in c.response_wrappers: content = w(content) response.content = content if c.response_content_type: response.headers["Content-Type"] = c.response_content_type if c.user_is_loggedin and not c.allow_loggedin_cache: response.headers["Cache-Control"] = "no-cache" response.headers["Pragma"] = "no-cache" if c.deny_frames: response.headers["X-Frame-Options"] = "DENY" # return # set content cache if ( g.page_cache_time and request.method.upper() == "GET" and (not c.user_is_loggedin or c.allow_loggedin_cache) and not c.used_cache and response.status_code != 503 and response.content and response.content[0] ): try: g.rendercache.set(self.request_key(), (response, c.cookies), g.page_cache_time) except MemcachedError: # the key was too big to set in the rendercache g.log.debug("Ignored too-big render cache") # send cookies for k, v in c.cookies.iteritems(): if v.dirty: response.set_cookie(key=k, value=quote(v.value), domain=v.domain, expires=v.expires) if g.usage_sampling <= 0.0: return if g.usage_sampling >= 1.0 or rand.random() < g.usage_sampling: if "pylons.routes_dict" in request.environ and "action" in request.environ["pylons.routes_dict"]: action = str(request.environ["pylons.routes_dict"]["action"]) else: action = "unknown" log_text("unknown action", "no action for %r" % path_info, "warning") amqp.add_kw( "usage_q", start_time=c.start_time, end_time=datetime.now(g.tz), sampling_rate=g.usage_sampling, action=action, ) # this thread is probably going to be reused, but it could be # a while before it is. So we might as well dump the cache in # the mean time so that we don't have dead objects hanging # around taking up memory g.reset_caches()