Пример #1
0
 def __call__(self, REQUEST):
     """ serve a static file """
     # print "the path is [%s]; the zipfile is [%s]" % (self._path, self._zipfile)
     zf = ZipFile(self._zipfile)
     
     try:
         data = zf.read(self._path)
         content_type = mimetype_from_filename(self._path)
         if content_type:
             REQUEST.RESPONSE.setHeader('content-type', content_type)
             REQUEST.RESPONSE.setHeader('Cache-Control', 'max-age=31556926')
     except KeyError:
         data = "Not Found"
         REQUEST.RESPONSE.setStatus(404)
     
     zf.close()
     return data
Пример #2
0
    def callback(context, path, REQUEST):
        filepath = os.path.join(_path, *path)
        try:
            fd = open(filepath)
        except IOError:
            REQUEST.RESPONSE.setStatus(404)
            return "Not Found"

        try:
            data = fd.read()
            content_type = mimetype_from_filename(filepath)
            if content_type:
                REQUEST.RESPONSE.setHeader('content-type', content_type)
                if cache:
                    REQUEST.RESPONSE.setHeader('Cache-Control', 'max-age=31556926')
                else:
                    REQUEST.RESPONSE.setHeader('Cache-Control', 'no-cache')
        except KeyError:
            data = "Not Found"
            REQUEST.RESPONSE.setStatus(404)

        fd.close()
        return data