@@ -196,17 +196,15 @@ function wp_cache_serve_cache_file() {
196
196
197
197
// don't try to match modified dates if using dynamic code.
198
198
if ( $ wp_cache_mfunc_enabled == 0 && $ wp_supercache_304 ) {
199
- if ( function_exists ( 'apache_request_headers ' ) ) {
200
- $ request = apache_request_headers ();
201
- $ remote_mod_time = ( isset ( $ request [ 'If-Modified-Since ' ] ) ) ? $ request [ 'If-Modified-Since ' ] : null ;
202
- } else {
203
- if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE ' ] ) )
204
- $ remote_mod_time = $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE ' ];
205
- else
206
- $ remote_mod_time = null ;
199
+ $ headers = apache_request_headers ();
200
+ $ remote_mod_time = isset ( $ headers ['If-Modified-Since ' ] ) ? $ headers ['If-Modified-Since ' ] : null ;
201
+
202
+ if ( is_null ( $ remote_mod_time ) && isset ( $ _SERVER ['HTTP_IF_MODIFIED_SINCE ' ] ) ) {
203
+ $ remote_mod_time = $ _SERVER ['HTTP_IF_MODIFIED_SINCE ' ];
207
204
}
205
+
208
206
$ local_mod_time = gmdate ("D, d M Y H:i:s " ,filemtime ( $ file )).' GMT ' ;
209
- if ( !is_null ($ remote_mod_time ) && $ remote_mod_time == $ local_mod_time ) {
207
+ if ( !is_null ($ remote_mod_time ) && $ remote_mod_time == $ local_mod_time ) {
210
208
header ( $ _SERVER [ 'SERVER_PROTOCOL ' ] . " 304 Not Modified " );
211
209
exit ();
212
210
}
@@ -1355,15 +1353,21 @@ function wpcache_logged_in_message() {
1355
1353
function wp_cache_user_agent_is_rejected () {
1356
1354
global $ cache_rejected_user_agent ;
1357
1355
1358
- if (!function_exists ('apache_request_headers ' )) return false ;
1356
+ if ( empty ( $ cache_rejected_user_agent ) || ! is_array ( $ cache_rejected_user_agent ) ) {
1357
+ return false ;
1358
+ }
1359
+
1359
1360
$ headers = apache_request_headers ();
1360
- if (!isset ($ headers ["User-Agent " ])) return false ;
1361
- if ( false == is_array ( $ cache_rejected_user_agent ) )
1361
+ if ( empty ( $ headers ['User-Agent ' ] ) ) {
1362
1362
return false ;
1363
- foreach ($ cache_rejected_user_agentas $ expr ) {
1364
- if (strlen ($ expr ) > 0 && stristr ($ headers ["User-Agent " ], $ expr ))
1363
+ }
1364
+
1365
+ foreach ( $ cache_rejected_user_agentas $ user_agent ) {
1366
+ if ( ! empty ( $ user_agent ) && stristr ( $ headers ['User-Agent ' ], $ user_agent ) ) {
1365
1367
return true ;
1368
+ }
1366
1369
}
1370
+
1367
1371
return false ;
1368
1372
}
1369
1373
@@ -3057,4 +3061,23 @@ function wp_cache_gc_watcher() {
3057
3061
}
3058
3062
}
3059
3063
3060
- ?>
3064
+ if ( ! function_exists ( 'apache_request_headers ' ) ) {
3065
+ /**
3066
+ * A fallback for get request headers.
3067
+ * Based on comments from http://php.net/manual/en/function.apache-request-headers.php
3068
+ *
3069
+ * @return array List of request headers
3070
+ */
3071
+ function apache_request_headers () {
3072
+ $ headers = array ();
3073
+
3074
+ foreach ( array_keys ( $ _SERVER ) as $ skey ) {
3075
+ if ( 0 === strncmp ( $ skey , 'HTTP_ ' ) ) {
3076
+ $ header = implode ( '- ' , array_map ( 'ucfirst ' , array_slice ( explode ( '_ ' , strtolower ( $ skey ) ) , 1 ) ) );
3077
+ $ headers [ $ header ] = $ _SERVER [ $ skey ];
3078
+ }
3079
+ }
3080
+
3081
+ return $ headers ;
3082
+ }
3083
+ }
0 commit comments