当前位置: 首页>>代码示例>>Python>>正文


Python DrupyPHP.header方法代码示例

本文整理汇总了Python中lib.drupy.DrupyPHP.header方法的典型用法代码示例。如果您正苦于以下问题:Python DrupyPHP.header方法的具体用法?Python DrupyPHP.header怎么用?Python DrupyPHP.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.drupy.DrupyPHP的用法示例。


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

示例1: drupal_page_header

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import header [as 别名]
def drupal_page_header():
    """
   Set HTTP headers in preparation for a page response.
  
   Authenticated users are always given a 'no-cache' php.header, and will
   fetch a fresh page on every request.  This prevents authenticated
   users seeing locally cached pages that show them as logged out.
  
   @see page_set_cache()
  """
    php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT")
    php.header("Last-Modified: " + php.gmdate("%D, %d %M %Y %H:%i:%s") + " GMT")
    php.header("Cache-Control: store, no-cache, must-revalidate")
    php.header("Cache-Control: post-check=0, pre-check=0", False)
开发者ID:sabren,项目名称:drupy,代码行数:16,代码来源:bootstrap.py

示例2: _drupal_bootstrap

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import header [as 别名]
def _drupal_bootstrap(phase):
    if phase == DRUPAL_BOOTSTRAP_CONFIGURATION:
        drupal_initialize_variables()
        # Start a page timer:
        timer_start("page")
        # Initialize the configuration
        conf_init()
    elif phase == DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:
        # Allow specifying special cache handlers in settings.php, like
        # using memcached or files for storing cache information.
        # If the page_cache_fastpath is set to TRUE in settings.php and
        # page_cache_fastpath (implemented in the special implementation of
        # cache.inc) printed the page and indicated this with a returned TRUE
        # then we are done.
        if variable_get("page_cache_fastpath", False) and page_cache_fastpath():
            exit()
    elif phase == DRUPAL_BOOTSTRAP_DATABASE:
        # Initialize the database system.  Note that the connection
        # won't be initialized until it is actually requested.
        # ! do nothing !
        # Register autoload functions so that we can access classes and interfaces.
        # spl_autoload_register('drupal_autoload_class')
        # spl_autoload_register('drupal_autoload_interface')
        pass
    elif phase == DRUPAL_BOOTSTRAP_ACCESS:
        # Deny access to blocked IP addresses - t() is not yet available
        if drupal_is_denied(ip_address()):
            php.header(php.SERVER["SERVER_PROTOCOL"] + " 403 Forbidden")
            print "Sorry, " + check_plain(ip_address()) + " has been banned."
            exit()
    elif phase == DRUPAL_BOOTSTRAP_SESSION:
        php.session_set_save_handler(
            "_sess_open", "_sess_close", "_sess_read", "_sess_write", "_sess_destroy_sid", "_sess_gc"
        )
        php.session_start()
    elif phase == DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
        # Initialize configuration variables, using values from settings.php
        # if available.
        settings.conf = variable_init(({} if (settings.conf == None) else settings.conf))
        # Load plugin handling.
        cache_mode = variable_get("cache", CACHE_DISABLED)
        # Get the page from the cache.
        cache = "" if (cache_mode == CACHE_DISABLED) else page_get_cache()
        # If the skipping of the bootstrap hooks is not enforced, call hook_boot.
        if cache_mode != CACHE_AGGRESSIVE:
            invoke_all("boot")
        # If there is a cached page, display it.
        if cache:
            drupal_page_cache_header(cache)
            # If the skipping of the bootstrap hooks is not enforced, call hook_exit.
            if cache_mode != CACHE_AGGRESSIVE:
                bootstrap_invoke_all("exit")
            # We are done.
            exit()
        # Prepare for non-cached page workflow.
        drupal_page_header()
    elif phase == DRUPAL_BOOTSTRAP_LANGUAGE:
        drupal_init_language()
    elif phase == DRUPAL_BOOTSTRAP_PATH:
        # Initialize php.GET['q'] prior to loading plugins and invoking hook_init().
        # lib_path.drupal_init_path();
        pass
    elif phase == DRUPAL_BOOTSTRAP_FULL:
        lib_common._drupal_bootstrap_full()
开发者ID:sabren,项目名称:drupy,代码行数:66,代码来源:bootstrap.py

示例3: drupal_page_cache_header

# 需要导入模块: from lib.drupy import DrupyPHP [as 别名]
# 或者: from lib.drupy.DrupyPHP import header [as 别名]
def drupal_page_cache_header(cache):
    """
   Set HTTP headers in preparation for a cached page response.
  
   The general approach here is that anonymous users can keep a local
   cache of the page, but must revalidate it on every request.  Then,
   they are given a '304 Not Modified' response as long as they stay
   logged out and the page has not been modified.
  """
    # Set default values:
    last_modified = php.gmdate("D, d M Y H:i:s", cache.created) + " GMT"
    etag = '"' + drupy_md5(last_modified) + '"'
    # See if the client has provided the required HTTP headers:
    if_modified_since = (
        php.stripslashes(php.SERVER["HTTP_IF_MODIFIED_SINCE"])
        if php.isset(php.SERVER, "HTTP_IF_MODIFIED_SINCE")
        else False
    )
    if_none_match = (
        php.stripslashes(php.SERVER["HTTP_IF_NONE_MATCH"]) if php.isset(php.SERVER, "HTTP_IF_NONE_MATCH") else False
    )
    if (
        if_modified_since
        and if_none_match
        and if_none_match == etag  # etag must match
        and if_modified_since == last_modified
    ):  # if-modified-since must match
        php.header(php.SERVER["SERVER_PROTOCOL"] + " 304 Not Modified")
        # All 304 responses must send an etag if the 200 response for the same
        # object contained an etag
        php.header("Etag: %(etag)s" % {"etag": etag})
        exit()
    # Send appropriate response:
    php.header("Last-Modified: %(last_modified)s" % {"last_modified": last_modified})
    php.header("Etag: %(etag)s" % {"etag": etag})
    # The following headers force validation of cache:
    php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT")
    php.header("Cache-Control: must-revalidate")
    if variable_get("page_compression", True):
        # Determine if the browser accepts gzipped data.
        if php.strpos(php.SERVER["HTTP_ACCEPT_ENCODING"], "gzip") == False and php.function_exists("gzencode"):
            # Strip the gzip php.header and run uncompress.
            cache.data = php.gzinflate(php.substr(php.substr(cache.data, 10), 0, -8))
        elif php.function_exists("gzencode"):
            php.header("Content-Encoding: gzip")
    # Send the original request's headers. We send them one after
    # another so PHP's php.header() def can deal with duplicate
    # headers.
    headers = php.explode("\n", cache.headers)
    for php.header_ in headers:
        php.header(php.header_)
    print cache.data
开发者ID:sabren,项目名称:drupy,代码行数:54,代码来源:bootstrap.py


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