def test_cache_control_set_control_obj_is_not_None(): class DummyCacheControl(object): def __init__(self): self.header_value = 1 self.properties = {'bleh':1} res = Response() res._cache_control_obj = DummyCacheControl() res.cache_control = {} eq_(res.cache_control.properties, {})
def handle_request(wrapper, request): #user_agent = request.environ.get('HTTP_USER_AGENT') response = Response() response.status_code = 200 response.text = "Empty Response" handler, kwargs = wrapper.find_handler(request) compress = True if handler is not None: if (inspect.isclass(handler)): handler = getattr(handler(), request.method.lower(), None) if handler is not None: handler(request, response, **kwargs) else: wrapper.err503(response) else: handler(request, response, **kwargs) if compress: response.body = brotli.compress(response.text.encode()) response.content_encoding = "br" else: try: try: FileType, noText = wrapper.getFileType(request.path) print(FileType, noText) response.content_type = FileType if (noText): print("\n\n****************\n\n") print("loc:", wrapper.root + "/static" + request.path) response.body = open( wrapper.root + "/static" + request.path, "rb").read() else: print("\n\n****************\n\n") print("loc:", wrapper.root + "/static" + request.path) response.text = open(wrapper.root + "/static" + request.path).read() response.cache_control = "max-age=" + str( wrapper.staticCache) except Exception as e: print(e) wrapper.err404(response) except Exception as e: print(e) response.text = "Well My Work Was Not Clean Enough, but...<br><b>Thats A Server Problem</b>" response.status_code = 500 return response
def feed(request, get_feed=get_feed): with shows_db() as shows: show_list = shows.values() d = PyQuery(get_feed(), parser="xml") for item in d("item"): ditem = PyQuery(item) title = ditem.find("title").text() match = detect_show(show_list, title) if match: name, episode = match # TODO: Record episode in the feed so that future versions of this episod will be ignored else: ditem.remove() response = Response() response.content_type = "application/rss+xml" response.ubody = unicode(d) response.cache_control = "no-cache" return response
def hdr_nocache(self): res = Response() res.expires = "Fri, 01 Jan 1980 00:00:00 GMT" res.pragma = "no-cache" res.cache_control = "no-cache, max-age=0, must-revalidate" return Response()
def hdr_cache_forever(self): res = Response() res.date = datetime.now().isoformat() res.expires = 0 res.cache_control = "public, max-age=31536000" return res
def test_cache_control_set_unicode(): res = Response() res.cache_control = u'abc' eq_(repr(res.cache_control), "<CacheControl 'abc'>")
def test_cache_control_set_None(): res = Response() res.cache_control = None eq_(repr(res.cache_control), "<CacheControl ''>")
def test_cache_control_set_dict(): res = Response() res.cache_control = {'a':'b'} eq_(repr(res.cache_control), "<CacheControl 'a=b'>")