⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_cache.c

📁 Apache HTTP Server 是一个功能强大的灵活的与HTTP/1.1相兼容的web服务器.这里给出的是Apache HTTP服务器的源码。
💻 C
📖 第 1 页 / 共 3 页
字号:
        }    }    info->expire = exp;    info->content_type = apr_pstrdup(r->pool, r->content_type);    info->etag = apr_pstrdup(r->pool, etag);    info->lastmods = apr_pstrdup(r->pool, lastmods);    info->filename = apr_pstrdup(r->pool, r->filename);    /*     * Write away header information to cache.     */    rv = cache->provider->store_headers(cache->handle, r, info);    /* Did we actually find an entity before, but it wasn't really stale? */    if (rv == APR_SUCCESS && cache->stale_handle) {        apr_bucket_brigade *bb;        apr_bucket *bkt;        bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);        /* Were we initially a conditional request? */        if (ap_cache_request_is_conditional(cache->stale_headers)) {            /* FIXME: Should we now go and make sure it's really not             * modified since what the user thought?             */            bkt = apr_bucket_eos_create(bb->bucket_alloc);            APR_BRIGADE_INSERT_TAIL(bb, bkt);        }        else {            r->status = info->status;            cache->provider->recall_body(cache->handle, r->pool, bb);        }        cache->block_response = 1;        return ap_pass_brigade(f->next, bb);    }    if (rv == APR_SUCCESS) {        rv = cache->provider->store_body(cache->handle, r, in);    }    if (rv != APR_SUCCESS) {        ap_remove_output_filter(f);    }    return ap_pass_brigade(f->next, in);}/* -------------------------------------------------------------- *//* Setup configurable data */static void * create_cache_config(apr_pool_t *p, server_rec *s){    cache_server_conf *ps = apr_pcalloc(p, sizeof(cache_server_conf));    /* array of URL prefixes for which caching is enabled */    ps->cacheenable = apr_array_make(p, 10, sizeof(struct cache_enable));    /* array of URL prefixes for which caching is disabled */    ps->cachedisable = apr_array_make(p, 10, sizeof(struct cache_disable));    /* maximum time to cache a document */    ps->maxex = DEFAULT_CACHE_MAXEXPIRE;    ps->maxex_set = 0;    /* default time to cache a document */    ps->defex = DEFAULT_CACHE_EXPIRE;    ps->defex_set = 0;    /* factor used to estimate Expires date from LastModified date */    ps->factor = DEFAULT_CACHE_LMFACTOR;    ps->factor_set = 0;    /* default percentage to force cache completion */    ps->complete = DEFAULT_CACHE_COMPLETION;    ps->complete_set = 0;    ps->no_last_mod_ignore_set = 0;    ps->no_last_mod_ignore = 0;    ps->ignorecachecontrol = 0;    ps->ignorecachecontrol_set = 0 ;    return ps;}static void * merge_cache_config(apr_pool_t *p, void *basev, void *overridesv){    cache_server_conf *ps = apr_pcalloc(p, sizeof(cache_server_conf));    cache_server_conf *base = (cache_server_conf *) basev;    cache_server_conf *overrides = (cache_server_conf *) overridesv;    /* array of URL prefixes for which caching is disabled */    ps->cachedisable = apr_array_append(p,                                         base->cachedisable,                                         overrides->cachedisable);    /* array of URL prefixes for which caching is enabled */    ps->cacheenable = apr_array_append(p,                                        base->cacheenable,                                        overrides->cacheenable);    /* maximum time to cache a document */    ps->maxex = (overrides->maxex_set == 0) ? base->maxex : overrides->maxex;    /* default time to cache a document */    ps->defex = (overrides->defex_set == 0) ? base->defex : overrides->defex;    /* factor used to estimate Expires date from LastModified date */    ps->factor =        (overrides->factor_set == 0) ? base->factor : overrides->factor;    /* default percentage to force cache completion */    ps->complete =        (overrides->complete_set == 0) ? base->complete : overrides->complete;    ps->no_last_mod_ignore =        (overrides->no_last_mod_ignore_set == 0)        ? base->no_last_mod_ignore        : overrides->no_last_mod_ignore;    ps->ignorecachecontrol  =        (overrides->ignorecachecontrol_set == 0)        ? base->ignorecachecontrol        : overrides->ignorecachecontrol;    return ps;}static const char *set_cache_ignore_no_last_mod(cmd_parms *parms, void *dummy,                                                int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->no_last_mod_ignore = flag;    conf->no_last_mod_ignore_set = 1;    return NULL;}static const char *set_cache_ignore_cachecontrol(cmd_parms *parms,                                                 void *dummy, int flag){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->ignorecachecontrol = flag;    conf->ignorecachecontrol_set = 1;    return NULL;}static const char *add_cache_enable(cmd_parms *parms, void *dummy,                                     const char *type,                                     const char *url){    cache_server_conf *conf;    struct cache_enable *new;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    new = apr_array_push(conf->cacheenable);    new->type = type;    new->url = url;    new->urllen = strlen(url);    return NULL;}static const char *add_cache_disable(cmd_parms *parms, void *dummy,                                     const char *url){    cache_server_conf *conf;    struct cache_disable *new;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    new = apr_array_push(conf->cachedisable);    new->url = url;    new->urllen = strlen(url);    return NULL;}static const char *set_cache_maxex(cmd_parms *parms, void *dummy,                                   const char *arg){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->maxex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC);    conf->maxex_set = 1;    return NULL;}static const char *set_cache_defex(cmd_parms *parms, void *dummy,                                   const char *arg){    cache_server_conf *conf;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    conf->defex = (apr_time_t) (atol(arg) * MSEC_ONE_SEC);    conf->defex_set = 1;    return NULL;}static const char *set_cache_factor(cmd_parms *parms, void *dummy,                                    const char *arg){    cache_server_conf *conf;    double val;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    if (sscanf(arg, "%lg", &val) != 1) {        return "CacheLastModifiedFactor value must be a float";    }    conf->factor = val;    conf->factor_set = 1;    return NULL;}static const char *set_cache_complete(cmd_parms *parms, void *dummy,                                      const char *arg){    cache_server_conf *conf;    int val;    conf =        (cache_server_conf *)ap_get_module_config(parms->server->module_config,                                                  &cache_module);    if (sscanf(arg, "%u", &val) != 1) {        return "CacheForceCompletion value must be a percentage";    }    conf->complete = val;    conf->complete_set = 1;    return NULL;}static int cache_post_config(apr_pool_t *p, apr_pool_t *plog,                             apr_pool_t *ptemp, server_rec *s){    /* This is the means by which unusual (non-unix) os's may find alternate     * means to run a given command (e.g. shebang/registry parsing on Win32)     */    cache_generate_key = APR_RETRIEVE_OPTIONAL_FN(ap_cache_generate_key);    if (!cache_generate_key) {        cache_generate_key = cache_generate_key_default;    }    return OK;}static const command_rec cache_cmds[] ={    /* XXX     * Consider a new config directive that enables loading specific cache     * implememtations (like mod_cache_mem, mod_cache_file, etc.).     * Rather than using a LoadModule directive, admin would use something     * like CacheModule  mem_cache_module | file_cache_module, etc,     * which would cause the approprpriate cache module to be loaded.     * This is more intuitive that requiring a LoadModule directive.     */    AP_INIT_TAKE2("CacheEnable", add_cache_enable, NULL, RSRC_CONF,                  "A cache type and partial URL prefix below which "                  "caching is enabled"),    AP_INIT_TAKE1("CacheDisable", add_cache_disable, NULL, RSRC_CONF,                  "A partial URL prefix below which caching is disabled"),    AP_INIT_TAKE1("CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF,                  "The maximum time in seconds to cache a document"),     AP_INIT_TAKE1("CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF,                   "The default time in seconds to cache a document"),     AP_INIT_FLAG("CacheIgnoreNoLastMod", set_cache_ignore_no_last_mod, NULL,                   RSRC_CONF,                   "Ignore Responses where there is no Last Modified Header"),     AP_INIT_FLAG("CacheIgnoreCacheControl", set_cache_ignore_cachecontrol,                  NULL,                   RSRC_CONF,                   "Ignore requests from the client for uncached content"),    AP_INIT_TAKE1("CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF,                  "The factor used to estimate Expires date from "                  "LastModified date"),    AP_INIT_TAKE1("CacheForceCompletion", set_cache_complete, NULL, RSRC_CONF,                  "Percentage of download to arrive for the cache to force "                  "complete transfer"),    {NULL}};static void register_hooks(apr_pool_t *p){    /* cache initializer */    /* cache handler */    ap_hook_quick_handler(cache_url_handler, NULL, NULL, APR_HOOK_FIRST);    /* cache filters      * XXX The cache filters need to run right after the handlers and before     * any other filters. Consider creating AP_FTYPE_CACHE for this purpose.     * Make them AP_FTYPE_CONTENT for now.     * XXX ianhH:they should run AFTER all the other content filters.     */    cache_save_filter_handle =         ap_register_output_filter("CACHE_SAVE",                                   cache_save_filter,                                   NULL,                                  AP_FTYPE_CONTENT_SET-1);    /* CACHE_OUT must go into the filter chain before SUBREQ_CORE to     * handle subrequsts. Decrementing filter type by 1 ensures this      * happens.     */    cache_out_filter_handle =         ap_register_output_filter("CACHE_OUT",                                   cache_out_filter,                                   NULL,                                  AP_FTYPE_CONTENT_SET-1);    ap_hook_post_config(cache_post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);}module AP_MODULE_DECLARE_DATA cache_module ={    STANDARD20_MODULE_STUFF,    NULL,                   /* create per-directory config structure */    NULL,                   /* merge per-directory config structures */    create_cache_config,    /* create per-server config structure */    merge_cache_config,     /* merge per-server config structures */    cache_cmds,             /* command apr_table_t */    register_hooks};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -