Skip to content

Commit a945cd7

Browse files
author
Bill Stoddard
committed
More mod_expired tuning. Replace the fixup hook with an insert_filter
hook. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@100123 13f79535-47bb-0310-9956-ffa450edef68
1 parent e28ab30 commit a945cd7

2 files changed

Lines changed: 33 additions & 91 deletions

File tree

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Changes with Apache 2.0.47
55
to prefer a certain language. [Andr� Malo]
66

77
*) Make mod_expires' ExpiresByType work properly, including for
8-
dynamically-generated documents. [Ken Coar]
8+
dynamically-generated documents. [Ken Coar, Bill Stoddard]
99

1010
Changes with Apache 2.0.46
1111

modules/metadata/mod_expires.c

Lines changed: 32 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ typedef struct {
212212
apr_table_t *expiresbytype;
213213
} expires_dir_config;
214214

215-
typedef struct {
216-
int defaulted;
217-
apr_table_t *expfields;
218-
} expires_interphase_t;
219-
220215
/* from mod_dir, why is this alias used?
221216
*/
222217
#define DIR_CMD_PERMS OR_INDEXES
@@ -434,10 +429,7 @@ static int set_expiration_fields(request_rec *r, const char *code,
434429
apr_time_t expires;
435430
int additional_sec;
436431
char *timestr;
437-
expires_interphase_t *notes;
438432

439-
notes = (expires_interphase_t *) ap_get_module_config(r->request_config,
440-
&expires_module);
441433
switch (code[0]) {
442434
case 'M':
443435
if (r->finfo.filetype == 0) {
@@ -482,131 +474,81 @@ static int set_expiration_fields(request_rec *r, const char *code,
482474
* according to the content-type of the response -- if it hasn't
483475
* already been set.
484476
*/
485-
static apr_status_t expires_by_type_filter(ap_filter_t *f,
486-
apr_bucket_brigade *b)
477+
static apr_status_t expires_filter(ap_filter_t *f,
478+
apr_bucket_brigade *b)
487479
{
488480
request_rec *r;
489481
expires_dir_config *conf;
490-
expires_interphase_t *notes;
491-
const char *bytype_expiry;
482+
const char *expiry;
492483
apr_table_t *t;
493484

494485
r = f->r;
495486
conf = (expires_dir_config *) ap_get_module_config(r->per_dir_config,
496487
&expires_module);
497-
notes = (expires_interphase_t *) ap_get_module_config(r->request_config,
498-
&expires_module);
499488

500489
/*
501-
* If this filter is getting called, it *should* mean that
502-
* the fixup-phase handler ran and set things up for us.
503490
* Check to see which output header table we should use;
504491
* mod_cgi loads script fields into r->err_headers_out,
505492
* for instance.
506493
*/
507-
bytype_expiry = apr_table_get(r->err_headers_out, "Expires");
508-
if (bytype_expiry != NULL) {
494+
expiry = apr_table_get(r->err_headers_out, "Expires");
495+
if (expiry != NULL) {
509496
t = r->err_headers_out;
510497
}
511498
else {
512-
bytype_expiry = apr_table_get(r->headers_out, "Expires");
499+
expiry = apr_table_get(r->headers_out, "Expires");
513500
t = r->headers_out;
514501
}
515-
if (bytype_expiry == NULL) {
502+
if (expiry == NULL) {
516503
/*
517504
* No expiration has been set, so we can apply any managed by
518-
* this module. Check for one for this content type.
505+
* this module. First, check to see if there is an applicable
506+
* ExpiresByType directive.
519507
*/
520-
bytype_expiry = apr_table_get(conf->expiresbytype,
521-
ap_field_noparam(r->pool,
522-
r->content_type));
523-
if (bytype_expiry != NULL) {
524-
set_expiration_fields(r, bytype_expiry, t);
508+
expiry = apr_table_get(conf->expiresbytype,
509+
ap_field_noparam(r->pool, r->content_type));
510+
if (expiry == NULL) {
511+
/* Use the ExpiresDefault directive */
512+
expiry = conf->expiresdefault;
525513
}
526-
else if ((notes != NULL) && notes->defaulted) {
527-
/*
528-
* None for this type, but there was a default defined --
529-
* so use it. Add the Expires header and add or replace the
530-
* Cache-Control header.
531-
*/
532-
apr_table_overlap(r->headers_out, notes->expfields, APR_OVERLAP_TABLES_SET);
514+
if (expiry != NULL) {
515+
set_expiration_fields(r, expiry, t);
533516
}
534517
}
535518
ap_remove_output_filter(f);
536519
return ap_pass_brigade(f->next, b);
537520
}
538521

539-
static int add_expires(request_rec *r)
522+
static void expires_insert_filter(request_rec *r)
540523
{
541524
expires_dir_config *conf;
542-
expires_interphase_t *notes;
543-
apr_table_t *rfields;
544-
char *code;
545525

546-
if (ap_is_HTTP_ERROR(r->status)) {/* Don't add Expires headers to errors */
547-
return DECLINED;
526+
/* Don't add Expires headers to errors */
527+
if (ap_is_HTTP_ERROR(r->status)) {
528+
return;
548529
}
549-
550-
if (r->main != NULL) { /* Say no to subrequests */
551-
return DECLINED;
530+
/* Say no to subrequests */
531+
if (r->main != NULL) {
532+
return;
552533
}
553-
554534
conf = (expires_dir_config *) ap_get_module_config(r->per_dir_config,
555535
&expires_module);
556-
if (conf == NULL) {
557-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
558-
"internal error: %s", r->filename);
559-
return HTTP_INTERNAL_SERVER_ERROR;
560-
}
561-
562-
if (conf->active != ACTIVE_ON) {
563-
return DECLINED;
564-
}
565536

566-
notes = apr_palloc(r->pool, sizeof(expires_interphase_t));
567-
notes->defaulted = 0;
568-
notes->expfields = apr_table_make(r->pool, 4);
569-
ap_set_module_config(r->request_config, &expires_module, notes);
570-
571-
/*
572-
* If there are any ExpiresByType directives for this scope,
573-
* add the output filter and defer all setting to it. We
574-
* do make a note of any ExpiresDefault value for its use.
537+
/* Check to see if the filter is enabled and if there are any applicable
538+
* config directives for this directory scope
575539
*/
576-
if (! apr_is_empty_table(conf->expiresbytype)) {
577-
ap_add_output_filter("MOD_EXPIRES", NULL, r, r->connection);
578-
rfields = notes->expfields;
540+
if (conf->active != ACTIVE_ON ||
541+
(apr_is_empty_table(conf->expiresbytype) && !conf->expiresdefault)) {
542+
return;
579543
}
580-
else {
581-
rfields = r->headers_out;
582-
}
583-
/*
584-
* Apply the default expiration if there is one; the filter will
585-
* narrow it down later if possible.
586-
*/
587-
code = conf->expiresdefault;
588-
589-
if (code[0] == '\0') {
590-
return OK;
591-
}
592-
else {
593-
/*
594-
* Note that we're setting it from the default, so that
595-
* the output filter (if it runs) knows it can override the
596-
* value. This allows the by-type filter to be able to
597-
* tell the difference between a value set by, say, a
598-
* CGI script and the one we set by default.
599-
*/
600-
notes->defaulted = 1;
601-
}
602-
return set_expiration_fields(r, code, rfields);
544+
ap_add_output_filter("MOD_EXPIRES", NULL, r, r->connection);
545+
return;
603546
}
604-
605547
static void register_hooks(apr_pool_t *p)
606548
{
607-
ap_register_output_filter("MOD_EXPIRES", expires_by_type_filter, NULL,
549+
ap_register_output_filter("MOD_EXPIRES", expires_filter, NULL,
608550
AP_FTYPE_CONTENT_SET);
609-
ap_hook_fixups(add_expires,NULL,NULL,APR_HOOK_MIDDLE);
551+
ap_hook_insert_filter(expires_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
610552
}
611553

612554
module AP_MODULE_DECLARE_DATA expires_module =

0 commit comments

Comments
 (0)