• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python http.is_resource_modified函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中werkzeug.http.is_resource_modified函数的典型用法代码示例。如果您正苦于以下问题:Python is_resource_modified函数的具体用法?Python is_resource_modified怎么用?Python is_resource_modified使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_resource_modified函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_is_resource_modified

    def test_is_resource_modified(self):
        env = create_environ()

        # ignore POST
        env["REQUEST_METHOD"] = "POST"
        assert not http.is_resource_modified(env, etag="testing")
        env["REQUEST_METHOD"] = "GET"

        # etagify from data
        self.assert_raises(TypeError, http.is_resource_modified, env, data="42", etag="23")
        env["HTTP_IF_NONE_MATCH"] = http.generate_etag(b"awesome")
        assert not http.is_resource_modified(env, data=b"awesome")

        env["HTTP_IF_MODIFIED_SINCE"] = http.http_date(datetime(2008, 1, 1, 12, 30))
        assert not http.is_resource_modified(env, last_modified=datetime(2008, 1, 1, 12, 00))
        assert http.is_resource_modified(env, last_modified=datetime(2008, 1, 1, 13, 00))
开发者ID:homeworkprod,项目名称:werkzeug,代码行数:16,代码来源:http.py


示例2: make_conditional

    def make_conditional(self, request_or_environ):
        """Make the response conditional to the request.  This method works
        best if an etag was defined for the response already.  The `add_etag`
        method can be used to do that.  If called without etag just the date
        header is set.

        This does nothing if the request method in the request or enviorn is
        anything but GET or HEAD.

        It does not remove the body of the response because that's something
        the `__call__` function does for us automatically.

        Returns self so that you can do ``return resp.make_conditional(req)``
        but modifies the object in-place.
        """
        environ = getattr(request_or_environ, 'environ', request_or_environ)
        if environ['REQUEST_METHOD'] not in ('GET', 'HEAD'):
            return
        self.headers['Date'] = http_date()
        if 'content-length' in self.headers:
            self.headers['Content-Length'] = len(self.data)
        if not is_resource_modified(environ, self.headers.get('etag'), None,
                                    self.headers.get('last-modified')):
            self.status_code = 304
        return self
开发者ID:danaspiegel,项目名称:softball_stat_manager,代码行数:25,代码来源:wrappers.py


示例3: make_conditional

 def make_conditional(self, request_or_environ):
     environ = _get_environ(request_or_environ)
     if environ['REQUEST_METHOD'] in ('GET', 'HEAD'):
         self.headers['Date'] = http_date()
         if 'content-length' in self.headers:
             self.headers['Content-Length'] = len(self.data)
         if not is_resource_modified(environ, self.headers.get('etag'), None, self.headers.get('last-modified')):
             self.status_code = 304
     return self
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:9,代码来源:wrappers.py


示例4: startupnews

def startupnews():
    dt = models.LastUpdated.get('startupnews')
    if dt and not is_resource_modified(request.environ, None, None, last_modified=dt):
        return Response(status=304)
    resp = Response(render_template(
                'startupnews.html',
                news_list=models.StartupNews.query.order_by('rank').all(),
                last_updated=dt))
    set_cache(resp, dt)
    return resp
开发者ID:ideonexus,项目名称:hacker-news-digest,代码行数:10,代码来源:index.py


示例5: validate_cache

def validate_cache(request):
    etag = sha1(repr(sorted(request.cache_key.items()))).hexdigest()
    mod_time = request.cache_key.get("modified")
    if request.method != "GET":
        return etag, mod_time
    if not is_resource_modified(request.environ, etag=etag, last_modified=mod_time):
        raise NotModified()
    if request.if_none_match == etag:
        raise NotModified()
    return etag, mod_time
开发者ID:jmorenoamor,项目名称:grano,代码行数:10,代码来源:util.py


示例6: test_is_resource_modified

    def test_is_resource_modified(self):
        env = create_environ()

        # ignore POST
        env['REQUEST_METHOD'] = 'POST'
        assert not http.is_resource_modified(env, etag='testing')
        env['REQUEST_METHOD'] = 'GET'

        # etagify from data
        self.assert_raises(TypeError, http.is_resource_modified, env,
                           data='42', etag='23')
        env['HTTP_IF_NONE_MATCH'] = http.generate_etag(b'awesome')
        assert not http.is_resource_modified(env, data=b'awesome')

        env['HTTP_IF_MODIFIED_SINCE'] = http.http_date(datetime(2008, 1, 1, 12, 30))
        assert not http.is_resource_modified(env,
            last_modified=datetime(2008, 1, 1, 12, 00))
        assert http.is_resource_modified(env,
            last_modified=datetime(2008, 1, 1, 13, 00))
开发者ID:211sandiego,项目名称:calllog211,代码行数:19,代码来源:http.py


示例7: __call__

    def __call__(self, environ, start_response):
        cleaned_path = get_path_info(environ)
        if PY2:
            cleaned_path = cleaned_path.encode(sys.getfilesystemencoding())
        # sanitize the path for non unix systems
        cleaned_path = cleaned_path.strip('/')
        for sep in os.sep, os.altsep:
            if sep and sep != '/':
                cleaned_path = cleaned_path.replace(sep, '/')
        path = '/' + '/'.join(x for x in cleaned_path.split('/')
                              if x and x != '..')
        file_loader = None
        for search_path, loader in iteritems(self.exports):
            if search_path == path:
                real_filename, file_loader = loader(None)
                if file_loader is not None:
                    break
            if not search_path.endswith('/'):
                search_path += '/'
            if path.startswith(search_path):
                real_filename, file_loader = loader(path[len(search_path):])
                if file_loader is not None:
                    break
        if file_loader is None or not self.is_allowed(real_filename):
            return self.app(environ, start_response)

        guessed_type = mimetypes.guess_type(real_filename)
        mime_type = guessed_type[0] or self.fallback_mimetype
        f, mtime, file_size = file_loader()

        headers = [('Date', http_date())]
        if self.cache:
            timeout = self.cache_timeout
            etag = self.generate_etag(mtime, file_size, real_filename)
            headers += [
                ('Etag', '"%s"' % etag),
                ('Cache-Control', 'max-age=%d, public' % timeout)
            ]
            if not is_resource_modified(environ, etag, last_modified=mtime):
                f.close()
                start_response('304 Not Modified', headers)
                return []
            headers.append(('Expires', http_date(time() + timeout)))
        else:
            headers.append(('Cache-Control', 'public'))

        headers.extend((
            ('Content-Type', mime_type),
            ('Content-Length', str(file_size)),
            ('Last-Modified', http_date(mtime))
        ))
        start_response('200 OK', headers)
        return wrap_file(environ, f)
开发者ID:0x00xw,项目名称:wooyun,代码行数:53,代码来源:wsgi.py


示例8: test_is_resource_modified_for_range_requests

    def test_is_resource_modified_for_range_requests(self):
        env = create_environ()

        env["HTTP_IF_MODIFIED_SINCE"] = http.http_date(datetime(2008, 1, 1, 12, 30))
        env["HTTP_IF_RANGE"] = http.generate_etag(b"awesome_if_range")
        # Range header not present, so If-Range should be ignored
        assert not http.is_resource_modified(
            env,
            data=b"not_the_same",
            ignore_if_range=False,
            last_modified=datetime(2008, 1, 1, 12, 30),
        )

        env["HTTP_RANGE"] = ""
        assert not http.is_resource_modified(
            env, data=b"awesome_if_range", ignore_if_range=False
        )
        assert http.is_resource_modified(
            env, data=b"not_the_same", ignore_if_range=False
        )

        env["HTTP_IF_RANGE"] = http.http_date(datetime(2008, 1, 1, 13, 30))
        assert http.is_resource_modified(
            env, last_modified=datetime(2008, 1, 1, 14, 00), ignore_if_range=False
        )
        assert not http.is_resource_modified(
            env, last_modified=datetime(2008, 1, 1, 13, 30), ignore_if_range=False
        )
        assert http.is_resource_modified(
            env, last_modified=datetime(2008, 1, 1, 13, 30), ignore_if_range=True
        )
开发者ID:pallets,项目名称:werkzeug,代码行数:31,代码来源:test_http.py


示例9: handle_cache

def handle_cache(response):
    """On 302 redirect, set no-cache headers. If resource is the same, return 304."""
    if response.status_code == 302:
        response.headers['Last-Modified'] = datetime.now()
        response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
        response.headers['Pragma'] = 'no-cache'
        response.headers['Expires'] = '-1'
        return response

    elif response.status_code != 200:
        return response

    # If we set max-age=0, then make sure the response is not locally cached
    if response.cache_control.max_age == 0:
        response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
        response.headers['Pragma'] = 'no-cache'
        response.headers['Expires'] = '-1'

    matched = not is_resource_modified(request.environ, etag=response.headers.get('etag'))
    unmodified = not is_resource_modified(request.environ, last_modified=response.headers.get('last-modified'))
    return_304 = matched or unmodified
    return return_304 and Response(status=304) or response
开发者ID:jonjlee,项目名称:tutorme,代码行数:22,代码来源:tutorme.py


示例10: validate_cache

def validate_cache(keys=None, last_modified=None):
    if isinstance(last_modified, (list, tuple)):
        last_modified = max(last_modified)
    if keys is None or not isinstance(keys, dict):
        keys = {'keys': keys}
    keys['last_modified'] = last_modified
    request._grano_etag = generate_etag(keys)
    request._grano_modified = last_modified
    if not is_resource_modified(request.environ,
        etag=request._grano_etag,
        last_modified=last_modified):
        raise NotModified()
    if request.if_none_match == request._grano_etag:
        raise NotModified()
开发者ID:eocaollai,项目名称:grano,代码行数:14,代码来源:cache.py


示例11: __call__

    def __call__(self, environ, start_response):
        cleaned_path = get_path_info(environ)
        if PY2:
            cleaned_path = cleaned_path.encode(get_filesystem_encoding())
        # sanitize the path for non unix systems
        cleaned_path = cleaned_path.strip("/")
        for sep in os.sep, os.altsep:
            if sep and sep != "/":
                cleaned_path = cleaned_path.replace(sep, "/")
        path = "/" + "/".join(x for x in cleaned_path.split("/") if x and x != "..")
        file_loader = None
        for search_path, loader in iteritems(self.exports):
            if search_path == path:
                real_filename, file_loader = loader(None)
                if file_loader is not None:
                    break
            if not search_path.endswith("/"):
                search_path += "/"
            if path.startswith(search_path):
                real_filename, file_loader = loader(path[len(search_path) :])
                if file_loader is not None:
                    break
        if file_loader is None or not self.is_allowed(real_filename):
            return self.app(environ, start_response)

        guessed_type = mimetypes.guess_type(real_filename)
        mime_type = guessed_type[0] or self.fallback_mimetype
        f, mtime, file_size = file_loader()

        headers = [("Date", http_date())]
        if self.cache:
            timeout = self.cache_timeout
            etag = self.generate_etag(mtime, file_size, real_filename)
            headers += [("Etag", '"%s"' % etag), ("Cache-Control", "max-age=%d, public" % timeout)]
            if not is_resource_modified(environ, etag, last_modified=mtime):
                f.close()
                start_response("304 Not Modified", headers)
                return []
            headers.append(("Expires", http_date(time() + timeout)))
        else:
            headers.append(("Cache-Control", "public"))

        headers.extend(
            (("Content-Type", mime_type), ("Content-Length", str(file_size)), ("Last-Modified", http_date(mtime)))
        )
        start_response("200 OK", headers)
        return wrap_file(environ, f)
开发者ID:codeaditya,项目名称:werkzeug,代码行数:47,代码来源:wsgi.py


示例12: startupnews

def startupnews():
    dt = models.LastUpdated.get('startupnews')
    if dt and not is_resource_modified(request.environ, None, None, last_modified=dt):
        return Response(status=304)
    resp = Response(render_template('index.html',
                title='Startup News Digest',
                news_list=models.StartupNews.query.order_by('rank').all(),
                navs=[
                    ('Startup News', 'http://news.dbanotes.net/news'),
                    ('New', 'http://news.dbanotes.net/newest'),
                    ('Comments', 'http://news.dbanotes.net/newcomments'),
                    ('Leaders', 'http://news.dbanotes.net/leaders'),
                    ('Submit', 'http://news.dbanotes.net/submit')],
                last_updated = dt and human(dt, 1)
            ))
    set_cache(resp, dt)
    return resp
开发者ID:nospy,项目名称:hacker-news-digest,代码行数:17,代码来源:index.py


示例13: hackernews

def hackernews():
    dt = models.LastUpdated.get('hackernews')
    if dt and not is_resource_modified(request.environ, None, None, last_modified=dt):
        return Response(status=304)
    resp = Response(render_template('index.html',
                title='Hacker News Digest',
                news_list=models.HackerNews.query.order_by('rank').all(),
                navs=[
                    ('Hacker News', 'https://news.ycombinator.com/news'),
                    ('New', 'https://news.ycombinator.com/newest'),
                    ('Comments', 'https://news.ycombinator.com/newcomments'),
                    ('Show', 'https://news.ycombinator.com/show'),
                    ('Ask', 'https://news.ycombinator.com/ask'),
                    ('Jobs', 'https://news.ycombinator.com/jobs'),
                    ('Submit', 'https://news.ycombinator.com/submit')],
                last_updated = dt and human(dt, 1)
            ))
    set_cache(resp, dt)
    return resp
开发者ID:nospy,项目名称:hacker-news-digest,代码行数:19,代码来源:index.py


示例14: prepare_response

    def prepare_response(self, request=None):
        if request is None:
            environ = dict()
        else:
            environ = request.environ

        guessed_type = mimetypes.guess_type(self.filename)
        mime_type = guessed_type[0] or 'text/plain'

        stream = open(self.filename)

        self.headers['Date'] = http_date()

        if self.cache_timeout and request:
            self.headers.extend((
                ('Etag', '"{:s}"'.format(self.etag)),
                ('Cache-Control', 'max-age={:d}, public'.format(
                    self.cache_timeout)),
            ))

            if not is_resource_modified(environ, self.etag):
                stream.close()
                self.status_code = 304
                return []

            self.headers['Expires'] = http_date(time() + self.cache_timeout)
        else:
            self.headers['Cache-Control'] = 'public'

        self.headers.extend((
            ('Content-Type', mime_type),
            ('Content-Length', str(self.size)),
            ('Last-Modified', http_date(self.mtime))
        ))

        if self.as_attachment:
            self.headers.set('Content-Disposition', 'attachment',
                             filename=self.attachment_filename)

        return wrap_file(environ, stream)
开发者ID:CorverDevelopment,项目名称:Poort,代码行数:40,代码来源:response.py


示例15: filedown

def filedown(environ, filename, cache=True, cache_timeout=None, download=False, inline=False, real_filename=None):
    guessed_type = mimetypes.guess_type(filename)
    mime_type = guessed_type[0] or 'text/plain'
    real_filename = real_filename or filename
    f, mtime, file_size = _opener(real_filename)

    headers = [('Date', http_date())]
    
    d_filename = os.path.basename(filename)
    if download:
        headers.append(('Content-Disposition', 'attachment; filename=%s' % d_filename))
    if inline:
        headers.append(('Content-Disposition', 'inline; filename=%s' % d_filename))
    
    if cache:
        etag = _generate_etag(mtime, file_size, real_filename)
        headers += [
            ('ETag', '"%s"' % etag),
        ]
        if cache_timeout:
            headers += [
                ('Cache-Control', 'max-age=%d, public' % cache_timeout),
                ('Expires', http_date(time() + cache_timeout))
            ]
        if not is_resource_modified(environ, etag, last_modified=mtime):
            f.close()
            return Response(status=304, headers=headers)
    else:
        headers.append(('Cache-Control', 'public'))
    

    headers.extend((
        ('Content-Type', mime_type),
        ('Content-Length', str(file_size)),
        ('Last-Modified', http_date(mtime))
    ))
    
    return Response(wrap_file(environ, f), status=200, headers=headers,
        direct_passthrough=True)
开发者ID:datakungfu,项目名称:uliweb,代码行数:39,代码来源:filedown.py


示例16: resp

        def resp(environ, start_response):
            headers = [("Date", http_date())]
            if self.cache:
                timeout = self.cache_timeout
                etag = self.generate_etag(file.mtime, file.size, file.name)
                headers += [("Etag", '"%s"' % etag), ("Cache-Control", "max-age=%d, public" % timeout)]
                if not is_resource_modified(environ, etag, last_modified=file.mtime):
                    file.handle.close()
                    start_response("304 Not Modified", headers)
                    return []
                headers.append(("Expires", http_date(time() + timeout)))
            else:
                headers.append(("Cache-Control", "public"))

            headers.extend(
                (
                    ("Content-Type", file.mimetype),
                    ("Content-Length", str(file.size)),
                    ("Last-Modified", http_date(file.mtime)),
                )
            )
            start_response("200 OK", headers)
            return wrap_file(environ, file.handle)
开发者ID:pawpro,项目名称:spa,代码行数:23,代码来源:handlers.py


示例17: resp

        def resp(environ, start_response):
            file = self.get_file(filepath)
            try:
                headers = [('Date', http_date())]
                if self.cache:
                    timeout = self.cache_timeout
                    etag = self.generate_etag(file.mtime, file.size, file.name)
                    headers += [
                        ('Etag', '"%s"' % etag),
                        ('Cache-Control', 'max-age=%d, public' % timeout)
                    ]
                    if not is_resource_modified(environ, etag, last_modified=file.mtime):
                        start_response('304 Not Modified', headers)
                        return []
                    headers.append(('Expires', http_date(time() + timeout)))
                else:
                    headers.append(('Cache-Control', 'public'))

                contents = self.hash_cache.get_contents(filepath)

                if contents is None:
                    contents = file.handle.read().decode('utf-8')
                    for pat, tpl in self.css_url_patterns:
                        converter = self.get_converter(tpl)
                        contents = pat.sub(converter, contents)
                    self.hash_cache.set_contents(filepath, contents)

                headers.extend((
                    ('Content-Type', file.mimetype),
                    ('Content-Length', len(contents)),
                    ('Last-Modified', http_date(file.mtime))
                ))
                start_response('200 OK', headers)

                return [contents.encode('utf-8')]
            finally:
                file.handle.close()
开发者ID:btubbs,项目名称:spa,代码行数:37,代码来源:smart.py


示例18: resp

        def resp(environ, start_response):
            headers = [('Date', http_date())]
            if self.cache:
                timeout = self.cache_timeout
                etag = self.generate_etag(file.mtime, file.size, file.name)
                headers += [
                    ('Etag', '"%s"' % etag),
                    ('Cache-Control', 'max-age=%d, public' % timeout)
                ]
                if not is_resource_modified(environ, etag, last_modified=file.mtime):
                    file.handle.close()
                    start_response('304 Not Modified', headers)
                    return []
                headers.append(('Expires', http_date(time() + timeout)))
            else:
                headers.append(('Cache-Control', 'public'))

            headers.extend((
                ('Content-Type', file.mimetype),
                ('Content-Length', str(file.size)),
                ('Last-Modified', http_date(file.mtime))
            ))
            start_response('200 OK', headers)
            return wrap_file(environ, file.handle)
开发者ID:btubbs,项目名称:spa,代码行数:24,代码来源:handlers.py


示例19: filedown

def filedown(environ, filename, cache=True, cache_timeout=None, 
    action=None, real_filename=None, x_sendfile=False,
    x_header_name=None, x_filename=None, fileobj=None,
    default_mimetype='application/octet-stream'):
    """
    @param filename: is used for display in download
    @param real_filename: if used for the real file location
    @param x_urlfile: is only used in x-sendfile, and be set to x-sendfile header
    @param fileobj: if provided, then returned as file content 
    @type fileobj: (fobj, mtime, size)
    
    filedown now support web server controlled download, you should set
    xsendfile=True, and add x_header, for example:
    
    nginx
        ('X-Accel-Redirect', '/path/to/local_url')
    apache
        ('X-Sendfile', '/path/to/local_url')
    """
    from werkzeug.http import parse_range_header
    
    guessed_type = mimetypes.guess_type(filename)
    mime_type = guessed_type[0] or default_mimetype
    real_filename = real_filename or filename
    
    #make common headers
    headers = []
    headers.append(('Content-Type', mime_type))
    d_filename = _get_download_filename(environ, os.path.basename(filename))
    if action == 'download':
        headers.append(('Content-Disposition', 'attachment; %s' % d_filename))
    elif action == 'inline':
        headers.append(('Content-Disposition', 'inline; %s' % d_filename))
    if x_sendfile:
        if not x_header_name or not x_filename:
            raise Exception, "x_header_name or x_filename can't be empty"
        headers.append((x_header_name, x_filename))
        return Response('', status=200, headers=headers,
            direct_passthrough=True)
    else:
        request = environ.get('werkzeug.request')
        if request:
            range = request.range
        else:
            range = parse_range_header(environ.get('HTTP_RANGE'))
        #when request range,only recognize "bytes" as range units
        if range!=None and range.units=="bytes":
            rbegin,rend = range.ranges[0]
            try:
                fsize = os.path.getsize(real_filename)
            except OSError,e:
                return Response("Not found",status=404)
            if (rbegin+1)<fsize:
                if rend == None:
                    rend = fsize-1
                headers.append(('Content-Length',str(rend-rbegin+1)))
                headers.append(('Content-Range','%s %d-%d/%d' %(range.units,rbegin, rend, fsize)))
                return Response(FileIterator(real_filename,rbegin,rend),
                    status=206, headers=headers, direct_passthrough=True)
        
        #process fileobj
        if fileobj:
            f, mtime, file_size = fileobj
        else:
            f, mtime, file_size = _opener(real_filename)
        headers.append(('Date', http_date()))
    
        if cache:
            etag = _generate_etag(mtime, file_size, real_filename)
            headers += [
                ('ETag', '"%s"' % etag),
            ]
            if cache_timeout:
                headers += [
                    ('Cache-Control', 'max-age=%d, public' % cache_timeout),
                    ('Expires', http_date(time() + cache_timeout))
                ]
            if not is_resource_modified(environ, etag, last_modified=mtime):
                f.close()
                return Response(status=304, headers=headers)
        else:
            headers.append(('Cache-Control', 'public'))
    

        headers.extend((
            ('Content-Length', str(file_size)),
            ('Last-Modified', http_date(mtime))
        ))
    
        return Response(wrap_file(environ, f), status=200, headers=headers,
            direct_passthrough=True)
开发者ID:08haozi,项目名称:uliweb,代码行数:91,代码来源:filedown.py


示例20: filedown

def filedown(environ, filename, cache=True, cache_timeout=None, 
    action=None, real_filename=None, x_sendfile=False,
    x_header_name=None, x_filename=None, fileobj=None,
    default_mimetype='application/octet-stream'):
    """
    @param filename: is used for display in download
    @param real_filename: if used for the real file location
    @param x_urlfile: is only used in x-sendfile, and be set to x-sendfile header
    @param fileobj: if provided, then returned as file content 
    @type fileobj: (fobj, mtime, size)
    
    filedown now support web server controlled download, you should set
    xsendfile=True, and add x_header, for example:
    
    nginx
        ('X-Accel-Redirect', '/path/to/local_url')
    apache
        ('X-Sendfile', '/path/to/local_url')
    """
    guessed_type = mimetypes.guess_type(filename)
    mime_type = guessed_type[0] or default_mimetype
    real_filename = real_filename or filename
    
    #make common headers
    headers = []
    headers.append(('Content-Type', mime_type))
    d_filename = os.path.basename(filename)
    if action == 'download':
        headers.append(('Content-Disposition', 'attachment; filename=%s' % d_filename))
    elif action == 'inline':
        headers.append(('Content-Disposition', 'inline; filename=%s' % d_filename))
    if x_sendfile:
        if not x_header_name or not x_filename:
            raise Exception, "x_header_name or x_filename can't be empty"
        headers.append((x_header_name, x_filename))
        return Response('', status=200, headers=headers,
            direct_passthrough=True)
    else:
        #process fileobj
        if fileobj:
            f, mtime, file_size = fileobj
        else:
            f, mtime, file_size = _opener(real_filename)
        headers.append(('Date', http_date()))
    
        if cache:
            etag = _generate_etag(mtime, file_size, real_filename)
            headers += [
                ('ETag', '"%s"' % etag),
            ]
            if cache_timeout:
                headers += [
                    ('Cache-Control', 'max-age=%d, public' % cache_timeout),
                    ('Expires', http_date(time() + cache_timeout))
                ]
            if not is_resource_modified(environ, etag, last_modified=mtime):
                f.close()
                return Response(status=304, headers=headers)
        else:
            headers.append(('Cache-Control', 'public'))
    

        headers.extend((
            ('Content-Length', str(file_size)),
            ('Last-Modified', http_date(mtime))
        ))
    
        return Response(wrap_file(environ, f), status=200, headers=headers,
            direct_passthrough=True)
开发者ID:victorlv,项目名称:uliweb,代码行数:69,代码来源:filedown.py



注:本文中的werkzeug.http.is_resource_modified函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python http.parse_accept_header函数代码示例发布时间:2022-05-26
下一篇:
Python http.http_date函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap