Пример #1
0
 def test_near_expiration(self):
     "Cookie will expire when an near expiration time is provided"
     response = Response(self.environ())
     # There is a timing weakness in this test; The
     # expected result for max-age requires that there be
     # a very slight difference between the evaluated expiration
     # time, and the time evaluated in set_cookie(). If this
     # difference doesn't exist, the cookie time will be
     # 1 second larger. To avoid the problem, put in a quick sleep,
     # which guarantees that there will be a time difference.
     expires = datetime.utcnow() + timedelta(seconds=10)
     time.sleep(0.1)
     response.set_cookie('datetime', expires=expires)
     datetime_cookie = response.cookies['datetime']
     self.assertEqual(datetime_cookie['max-age'], 10)
Пример #2
0
 def test_near_expiration(self):
     "Cookie will expire when an near expiration time is provided"
     response = Response(self.environ())
     # There is a timing weakness in this test; The
     # expected result for max-age requires that there be
     # a very slight difference between the evaluated expiration
     # time, and the time evaluated in set_cookie(). If this
     # difference doesn't exist, the cookie time will be
     # 1 second larger. To avoid the problem, put in a quick sleep,
     # which guarantees that there will be a time difference.
     expires = datetime.utcnow() + timedelta(seconds=10)
     time.sleep(0.1)
     response.set_cookie('datetime', expires=expires)
     datetime_cookie = response.cookies['datetime']
     self.assertEqual(datetime_cookie['max-age'], 10)
Пример #3
0
 def serve_file(self, request, fullpath):
     # Respect the If-Modified-Since header.
     statobj = os.stat(fullpath)
     mimetype, encoding = mimetypes.guess_type(fullpath)
     mimetype = mimetype or self.DEFAULT_CONTENT_TYPE
     if not self.was_modified_since(
             request.environ.get('HTTP_IF_MODIFIED_SINCE', None),
             statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
         return Response(status=304,
                         content_type=mimetype,
                         encoding=encoding)
     contents = open(fullpath, 'rb').read()
     response = Response(content=contents,
                         content_type=mimetype,
                         encoding=encoding)
     response.headers["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
     return response
Пример #4
0
 def serve_file(self, request, fullpath):
     # Respect the If-Modified-Since header.
     statobj = os.stat(fullpath)
     mimetype, encoding = mimetypes.guess_type(fullpath)
     mimetype = mimetype or self.DEFAULT_CONTENT_TYPE
     if not self.was_modified_since(request.environ.get(
                                         'HTTP_IF_MODIFIED_SINCE',None),
                                    statobj[stat.ST_MTIME],
                                    statobj[stat.ST_SIZE]):
         return Response(status=304,
                         content_type=mimetype,
                         encoding=encoding)
     contents = open(fullpath, 'rb').read()
     response = Response(content=contents,
                         content_type=mimetype,
                         encoding=encoding)
     response.headers["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
     return response