📄 mod_gzip.c
字号:
mod_gzip_printf( "%s: 'gzip' value NOT seen...", cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } } else /* No 'Accept-encoding:' field present... */ { #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:NO_ACCEPT_ENCODING")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'Accept-Encoding' field NOT seen...", cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: accept_encoding_gzip_seen = %ld", cn, accept_encoding_gzip_seen ); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: dconf->imap_total_entries = %d", cn, (int) dconf->imap_total_entries ); #endif /* There must be at least 1 IMAP inclusion/exclusion record... */ if ( dconf->imap_total_entries < 1 ) { #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:NO_ITEMS_DEFINED")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: There are no IMAP entries. Unable to include/exclude",cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: dconf->imap_total_isreqheader = %d", cn, (int) dconf->imap_total_isreqheader ); #endif /* See if we need to examine 'special' input request headers... */ if ( dconf->imap_total_isreqheader > 0 ) { const apr_array_header_t *elts_arr = apr_table_elts( ( apr_table_t * ) r->headers_in ); const apr_table_entry_t *elts = (apr_table_entry_t *) elts_arr->elts; #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Checking inbound REQUEST header fields...", cn ); #endif for (i = 0; i < elts_arr->nelts; ++i) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: %3.3d key=[%s] val=[%s]", cn,i,mod_gzip_npp(elts[i].key),mod_gzip_npp(elts[i].val)); #endif tablekey = elts[i].key; tablestring = elts[i].val; if (( tablekey && tablestring )) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Checking key[%s] string[%s]", cn,mod_gzip_npp(tablekey),mod_gzip_npp(tablestring)); mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn); #endif field_ok = mod_gzip_validate1( (request_rec *) r, (mod_gzip_conf *) dconf, NULL, /* r->filename (Not used here) */ NULL, /* r->uri (Not used here) */ NULL, /* r->content_type (Not used here) */ NULL, /* r->handler (Not used here) */ (char *) tablekey, /* (Field key ) */ (char *) tablestring, /* (Field string ) */ MOD_GZIP_REQUEST /* (Direction ) */ ); #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn); mod_gzip_printf( "%s: field_ok = %d",cn,field_ok); #endif if ( field_ok == MOD_GZIP_IMAP_DECLINED1 ) { #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:REQ_HEADER_FIELD_EXCLUDED")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: This request is EXCLUDED...",cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } }/* End 'if(( tablekey && tablestring ))' */ }/* End 'i' loop */ }/* End 'if ( dconf->imap_total_isreqheader > 0 )' */ #ifdef MOD_GZIP_DEBUG1 else { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: NO CHECK required on inbound REQUEST header fields...", cn ); #endif } #endif /* Validate the request... */ #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 1 ***: r->uri =[%s]", cn, mod_gzip_npp(r->uri )); mod_gzip_printf( "%s: 1 ***: r->unparsed_uri=[%s]", cn, mod_gzip_npp(r->unparsed_uri )); mod_gzip_printf( "%s: 1 ***: r->filename =[%s]", cn, mod_gzip_npp(r->filename )); mod_gzip_printf( "%s: 1 ***: r->handler =[%s]", cn, mod_gzip_npp(r->handler )); mod_gzip_printf( "%s: 1 ***: r->content_type=[%s]", cn, mod_gzip_npp(r->content_type )); mod_gzip_printf( "%s: 2 ***: r->uri =[%s]", cn, mod_gzip_npp(r->uri )); mod_gzip_printf( "%s: 2 ***: r->unparsed_uri=[%s]", cn, mod_gzip_npp(r->unparsed_uri )); mod_gzip_printf( "%s: 2 ***: r->filename =[%s]", cn, mod_gzip_npp(r->filename )); mod_gzip_printf( "%s: 2 ***: r->content_type=[%s]", cn, mod_gzip_npp(r->content_type )); mod_gzip_printf( "%s: 2 ***: r->handler =[%s]", cn, mod_gzip_npp(r->handler )); mod_gzip_printf( "%s: Call mod_gzip_validate1()...",cn); #endif /* MOD_GZIP_DEBUG1 */ action_flag = mod_gzip_validate1( (request_rec *) r, (mod_gzip_conf *) dconf, (char *) r->filename, (char *) r->uri, (char *) r->content_type, (char *) r->handler, NULL, /* Field key (Not used here) */ NULL, /* Field string (Not used here) */ 0 /* Direction (Not used here) */ ); #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Back mod_gzip_validate1()...",cn); mod_gzip_printf( "%s: action_flag = %d",cn,action_flag); if ( action_flag == MOD_GZIP_IMAP_DYNAMIC1 ) { mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC1",cn); } else if ( action_flag == MOD_GZIP_IMAP_DYNAMIC2 ) { mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DYNAMIC2",cn); } else if ( action_flag == MOD_GZIP_IMAP_STATIC1 ) { mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_STATIC1",cn); } else if ( action_flag == MOD_GZIP_IMAP_DECLINED1 ) { mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_DECLINED1",cn); } else { mod_gzip_printf( "%s: action_flag = MOD_GZIP_IMAP_??? Unknown action",cn); } #endif /* MOD_GZIP_DEBUG1 */ if ( action_flag != MOD_GZIP_IMAP_DECLINED1 ) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: This transaction is a valid candidate...",cn); mod_gzip_printf( "%s: Exit > return( OK ) >", cn ); mod_gzip_printf( " " ); #endif return OK; } else /* 'action_flag' is 'MOD_GZIP_IMAP_DECLINED1' */ { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: This transaction is NOT a valid candidate...",cn); #endif #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:EXCLUDED")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn ); mod_gzip_printf( " " ); #endif return DECLINED; }}/* End of mod_gzip_echeck1() */int mod_gzip_echeck2( request_rec *r, mod_gzip_conf *dconf ){ /* Secondary eligibility checks... */ /* NOTE: This routine should only be called following the */ /* primary eligibility check(s) and only when the 'r->headers_out' */ /* table is valid and the response headers are available for */ /* examination... */ int i = 0; int field_ok = 0; const char *tablekey = 0; const char *tablestring = 0; #ifdef MOD_GZIP_DEBUG1 char cn[]="mod_gzip_echeck2()"; mod_gzip_conf *sconf = 0; #endif /* Start... */ #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( " " ); mod_gzip_printf( "%s: #### Entry...",cn); mod_gzip_printf( "%s: r = %ld", cn,(long)r); mod_gzip_printf( "%s: r->main = %ld", cn,(long)r->main); mod_gzip_printf( "%s: r->next = %ld", cn,(long)r->next); mod_gzip_printf( "%s: r->prev = %ld", cn,(long)r->prev); mod_gzip_printf( "%s: r->header_only = %ld", cn,(long)r->header_only ); mod_gzip_printf( "%s: r->method_number = %ld", cn,(long)r->method_number ); mod_gzip_printf( "%s: r->method = [%s]",cn,mod_gzip_npp(r->method)); mod_gzip_printf( "%s: r->unparsed_uri = [%s]",cn,mod_gzip_npp(r->unparsed_uri)); mod_gzip_printf( "%s: r->uri = [%s]",cn,mod_gzip_npp(r->uri)); mod_gzip_printf( "%s: r->filename = [%s]",cn,mod_gzip_npp(r->filename)); mod_gzip_printf( "%s: r->handler = [%s]",cn,mod_gzip_npp(r->handler)); mod_gzip_printf( "%s: r->content_type = [%s]",cn,mod_gzip_npp(r->content_type)); sconf = ( mod_gzip_conf * ) ap_get_module_config( r->server->module_config, &gzip_module ); mod_gzip_printf( "%s: r->server->server_hostname = [%s]", cn,mod_gzip_npp(r->server->server_hostname)); if ( sconf ) { mod_gzip_printf( "%s: sconf = %ld", cn,(long)sconf); mod_gzip_printf( "%s: sconf->loc = [%s]",cn,mod_gzip_npp(sconf->loc)); mod_gzip_printf( "%s: sconf->is_on = %ld", cn,(long)sconf->is_on); } if ( dconf) { mod_gzip_printf( "%s: dconf = %ld", cn,(long)dconf); mod_gzip_printf( "%s: dconf->loc = [%s]",cn,mod_gzip_npp(dconf->loc)); mod_gzip_printf( "%s: dconf->is_on = %ld", cn,(long)dconf->is_on); } /* Show the request headers at this point in time... */ mod_gzip_printf( "%s: REQUEST HEADERS",cn); mod_gzip_dump_a_table( (request_rec *) r, (apr_table_t *) r->headers_in ); /* Show the response headers at this point in time... */ mod_gzip_printf( "%s: RESPONSE HEADERS",cn); mod_gzip_dump_a_table( (request_rec *) r, (apr_table_t *) r->headers_out ); #endif /* MOD_GZIP_DEBUG1 */ /* Begin checks... */ if ( !dconf ) /* Sanity check... */ { #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:NO_DCONF")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'dconf' is NULL. Unable to continue.",cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } if ( !dconf->is_on ) /* Sanity check... */ { #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:OFF")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'dconf->is_on' is FALSE",cn); mod_gzip_printf( "%s: mod_gzip is not turned ON for this location...",cn); mod_gzip_printf( "%s: This transaction will be ignored...",cn); mod_gzip_printf( "%s: Exit > return( DECLINED ) >",cn); #endif return DECLINED; } /* Check for pre-existing Content-Encodings... */ #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Checking for [Content-Encoding: xxx]", cn ); #endif tablestring = apr_table_get( r->headers_out, "Content-Encoding" ); #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: r->headers_out->Content-Encoding = [%s]", cn,mod_gzip_npp(tablestring)); #endif if ( tablestring ) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'Content-Encoding' field seen...", cn); #endif /* There is no need to check the field value(s). */ /* As of this writing no browser can handle multiple */ /* Content-Encodings of any kind. */ /* Just DECLINE and don't add multiple Content-Encdodings... */ #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:HAS_CE")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } else /* No 'Content-Encoding:' field present... */ { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'Content-Encoding' field NOT seen...", cn); #endif } /* Check for pre-existing Transfer-Encodings... */ #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Checking for [Transfer-Encoding: xxx]", cn ); #endif tablestring = apr_table_get( r->headers_out, "Transfer-Encoding" ); #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: r->headers_out->Transfer-Encoding = [%s]", cn,mod_gzip_npp(tablestring)); #endif if ( tablestring ) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'Transfer-Encoding' field seen...", cn); mod_gzip_printf( "%s: Checking header value...", cn); #endif if ( mod_gzip_stringcontains( (char *)tablestring, "chunked" ) ) { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'chunked' value seen...", cn); mod_gzip_printf( "%s: dconf->dechunk = %d", cn, (int)dconf->dechunk ); #endif #ifdef MOD_GZIP_CAN_DECHUNK /* If we are able to strip pre-existing 'chunking' information */ /* then check the flag to see if we should do so... */ if ( dconf->dechunk == 1 ) { /* The configuration says it's OK to remove any */ /* pre-existing chunking information so the response */ /* can be compressed... continue... */ } else /* dechunk flag is FALSE */ { /* We are unable to remove the pre-existing chunking */ /* information so EXCLUDE this response from compression... */ #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:TE_CHUNKED")); #endif #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: Exit > return( DECLINED ) >", cn); #endif return DECLINED; } #else /* !MOD_GZIP_CAN_DECHUNK */ /* ZLIB is unable to remove the pre-existing chunking information */ /* if it exists so just EXCLUDE this request for now... */ /* TODO: Add code to strip pre-existing Transfer_Encoding */ /* prior to ZLIB deflate() calls in the filter itself. */ #ifdef MOD_GZIP_USES_APACHE_LOGS apr_table_setn( r->notes,"mod_gzip_result", apr_pstrdup(r->pool,"DECLINED:TE_CHUNKED")); #endif #endif /* MOD_GZIP_CAN_DECHUNK */ }/* End 'if TE chunked' */ else /* Other TE encodings... */ { /* For now other Transfer-Encodings other than */ /* 'chunked' will not disqualify this request. */ /* Just fall-through and continue checks... */ } } else /* No 'Transfer-Encoding:' field present... */ { #ifdef MOD_GZIP_DEBUG1 mod_gzip_printf( "%s: 'Transfer-Encoding' field NOT seen...", cn); #endif } /* See if we need to validate any response headers... */ if ( dconf->im
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -