[mod-xhtml-neg-cvs] mod_xhtml_neg-2.0 mod_xhtml_neg.c,1.2,1.3
Brought to you by:
run2000
From: <ru...@us...> - 2004-03-13 09:36:00
|
Update of /cvsroot/mod-xhtml-neg/mod_xhtml_neg-2.0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7825 Modified Files: mod_xhtml_neg.c Log Message: Fixed up Etag handling for 2.0 filters. Index: mod_xhtml_neg.c =================================================================== RCS file: /cvsroot/mod-xhtml-neg/mod_xhtml_neg-2.0/mod_xhtml_neg.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mod_xhtml_neg.c 13 Mar 2004 08:10:31 -0000 1.2 --- mod_xhtml_neg.c 13 Mar 2004 09:27:13 -0000 1.3 *************** *** 522,567 **** */ ! static char *merge_validators(apr_pool_t *p, char *old_variant, char *new_variant) { - char *etag; int old_weak, new_weak; if (mod_xhtml_strempty(old_variant)) { ! etag = new_variant; } else if (mod_xhtml_strempty(new_variant)) { ! etag = old_variant; ! } else { ! /* Merge any two vlist entries: one from any previous module, and ! * one from the current module. This merging makes revalidation ! * somewhat safer, ensures that caches which can deal with ! * Vary will (eventually) be updated if the set of variants is ! * changed, and is also a protocol requirement for transparent ! * content negotiation. ! */ ! /* if the variant list validator is weak, we make the whole ! * structured etag weak. If we would not, then clients could ! * have problems merging range responses if we have different ! * variants with the same non-globally-unique strong etag. ! */ ! old_weak = (old_variant[0] == 'W'); ! new_weak = (new_variant[0] == 'W'); ! /* merge old and new variant_etags into a structured etag */ ! old_variant[strlen(old_variant) - 1] = '\0'; ! if (new_weak) ! new_variant += 3; ! else ! new_variant++; ! if((old_weak == 0) && (new_weak != 0)) { ! etag = apr_pstrcat(p, "W/", old_variant, ";", new_variant, NULL); ! } else { ! etag = apr_pstrcat(p, old_variant, ";", new_variant, NULL); ! } } ! return etag; } --- 522,567 ---- */ ! static const char *merge_validators(apr_pool_t *p, const char *old_variant, ! const char *new_variant) { int old_weak, new_weak; + char *old_variable; if (mod_xhtml_strempty(old_variant)) { ! return new_variant; } else if (mod_xhtml_strempty(new_variant)) { ! return old_variant; ! } ! /* Merge any two vlist entries: one from any previous module, and ! * one from the current module. This merging makes revalidation ! * somewhat safer, ensures that caches which can deal with ! * Vary will (eventually) be updated if the set of variants is ! * changed, and is also a protocol requirement for transparent ! * content negotiation. ! */ ! /* if the variant list validator is weak, we make the whole ! * structured etag weak. If we would not, then clients could ! * have problems merging range responses if we have different ! * variants with the same non-globally-unique strong etag. ! */ ! old_weak = (old_variant[0] == 'W'); ! new_weak = (new_variant[0] == 'W'); ! /* merge old and new variant_etags into a structured etag */ ! old_variable = apr_pstrdup( p, old_variant ); ! old_variable[strlen(old_variable) - 1] = '\0'; ! if ((new_weak) && (mod_xhtml_strlen(old_variable) > 3)) ! new_variant += 3; ! else ! new_variant++; ! ! if((old_weak == 0) && (new_weak != 0)) { ! return apr_pstrcat(p, "W/", old_variable, ";", new_variant, NULL); } ! return apr_pstrcat(p, old_variable, ";", new_variant, NULL); } *************** *** 1070,1082 **** }; - /* Return OK if either active isn't ON, or stars_ignore is 0. */ - if( conf->active != ACTIVE_ON ) { - return OK; - } - - if( conf->stars_ignore == 0 ) { - return OK; - } - /* Only service requests for GET or HEAD methods. */ if( r->method_number != M_GET ) { --- 1070,1073 ---- *************** *** 1084,1094 **** } - /* This module is concerned with rewriting Content-Type, and adding a Vary - * header. For HTTP 0.9, neither of these functions are relevant. - */ - if( r->assbackwards ) { - return OK; - } - /* Retrieve the HTTP request headers table. */ hdrs = r->headers_in; --- 1075,1078 ---- *************** *** 1119,1122 **** --- 1103,1107 ---- /* Do some logging... */ if( xns->log_fd != NULL ) { + logmessage = apr_pstrcat(r->pool, "Filename is ", filename, "\n", *************** *** 1153,1162 **** if( result_rec != NULL ) { ! /* Construct a "suffix" for the ETag, and make sure it gets * appended to the ETag that would normally be returned * by Apache. */ ! r->vlist_validator = merge_validators( r->pool, r->vlist_validator, ! result_rec->hashcode ); r->content_type = reconstruct_content_type( r->pool, result_rec ); --- 1138,1149 ---- if( result_rec != NULL ) { ! /* Construct a new ETag suffix, and make sure it gets * appended to the ETag that would normally be returned * by Apache. */ ! const char *old_etag = apr_table_get( r->headers_out, "Etag" ); ! const char *etag = merge_validators( r->pool, old_etag, ! result_rec->hashcode ); ! apr_table_setn(r->headers_out, "Etag", etag ); r->content_type = reconstruct_content_type( r->pool, result_rec ); *************** *** 1164,1168 **** logmessage = apr_pstrcat(r->pool, "Best content-type: ", r->content_type, "\n", ! "New validator is: ", r->vlist_validator, "\n", NULL ); logsize = mod_xhtml_strlen( logmessage ); --- 1151,1155 ---- logmessage = apr_pstrcat(r->pool, "Best content-type: ", r->content_type, "\n", ! "New validator is: ", etag, "\n", NULL ); logsize = mod_xhtml_strlen( logmessage ); *************** *** 1193,1196 **** --- 1180,1219 ---- } + /* Filter code goes here */ + static void xhtml_neg_insert_output_filter(request_rec *r) + { + xhtml_dir_config *conf = ap_get_module_config(r->per_dir_config, + &xhtml_neg_module); + + if ((conf->active == ACTIVE_ON) && (conf->stars_ignore > 0)) { + ap_add_output_filter("XHTML_NEGOTIATION_OUT", NULL, r, r->connection); + } + } + + /* + * This is the output filter identified by the name "XHTML_NEGOTIATION_OUT" + */ + + static apr_status_t xhtml_negotiation_output_filter(ap_filter_t *f, + apr_bucket_brigade *in) + { + xhtml_dir_config *conf = ap_get_module_config(f->r->per_dir_config, + &xhtml_neg_module); + + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, f->r->server, + "mod_xhtml_neg: xhtml_negotiation_output_filter()"); + + /* do the fixup */ + xhtml_negotiate(f->r); + + /* remove ourselves from the filter chain */ + ap_remove_output_filter(f); + + /* send the data up the stack */ + return ap_pass_brigade(f->next,in); + } + + + /* All Apache configuration file code goes here... */ *************** *** 1427,1431 **** { ap_hook_post_config(init_xhtml_log, NULL, NULL, APR_HOOK_MIDDLE); ! ap_hook_fixups(xhtml_negotiate, NULL, NULL, APR_HOOK_MIDDLE); } --- 1450,1457 ---- { ap_hook_post_config(init_xhtml_log, NULL, NULL, APR_HOOK_MIDDLE); ! ap_hook_insert_filter(xhtml_neg_insert_output_filter, NULL, NULL, APR_HOOK_LAST); ! ap_register_output_filter("XHTML_NEGOTIATION_OUT", ! xhtml_negotiation_output_filter, ! NULL, AP_FTYPE_CONTENT_SET); } |