Navigation Menu

Skip to content

Commit

Permalink
Clean up code for caching generated files
Browse files Browse the repository at this point in the history
When this was first implemented, bypassing headers was needed to avoid
the default no-caching behaavior.

Now that http_caching_headers() can be called to explicitly write
headers to allow caching, there's no need to bypass standard headers
anymore.
  • Loading branch information
cproensa authored and dregad committed Jul 15, 2019
1 parent 97b745d commit d8a8873
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 43 deletions.
16 changes: 5 additions & 11 deletions css/status_config.php
Expand Up @@ -28,20 +28,9 @@
# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

$t_allow_caching = isset( $_GET['cache_key'] );
if( $t_allow_caching ) {
# Suppress default headers. This allows caching as defined in server configuration
$g_bypass_headers = true;
}

@require_once( dirname( dirname( __FILE__ ) ) . '/core.php' );
require_api( 'config_api.php' );

if( $t_allow_caching ) {
# if standard headers were bypassed, add security headers, at least
http_security_headers();
}

/**
* Send correct MIME Content-Type header for css content.
*/
Expand Down Expand Up @@ -91,6 +80,11 @@
exit;
}

# rewrite headers to allow caching
if( gpc_isset( 'cache_key' ) ) {
http_caching_headers( true );
}

$t_status_string = config_get( 'status_enum_string' );
$t_statuses = MantisEnum::getAssocArrayIndexedByValues( $t_status_string );
$t_colors = config_get( 'status_colors' );
Expand Down
15 changes: 4 additions & 11 deletions javascript_config.php
Expand Up @@ -27,20 +27,9 @@
# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

$t_allow_caching = isset( $_GET['cache_key'] );
if( $t_allow_caching ) {
# Suppress default headers. This allows caching as defined in server configuration
$g_bypass_headers = true;
}

require_once( 'core.php' );
require_api( 'config_api.php' );

if( $t_allow_caching ) {
# if standard headers were bypassed, add security headers, at least
http_security_headers();
}

/**
* Print array of configuration option->values for javascript.
* @param string $p_config_key Configuration option.
Expand All @@ -59,6 +48,10 @@ function print_config_value( $p_config_key ) {
# http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
header( 'X-Content-Type-Options: nosniff' );

# rewrite headers to allow caching
if( gpc_isset( 'cache_key' ) ) {
http_caching_headers( true );
}

# WARNING: DO NOT EXPOSE SENSITIVE CONFIGURATION VALUES!
#
Expand Down
16 changes: 5 additions & 11 deletions javascript_translations.php
Expand Up @@ -28,20 +28,9 @@
# Prevent output of HTML in the content if errors occur
define( 'DISABLE_INLINE_ERROR_REPORTING', true );

$t_allow_caching = isset( $_GET['cache_key'] );
if( $t_allow_caching ) {
# Suppress default headers. This allows caching as defined in server configuration
$g_bypass_headers = true;
}

require_once( 'core.php' );
require_api( 'lang_api.php' );

if( $t_allow_caching ) {
# if standard headers were bypassed, add security headers, at least
http_security_headers();
}

/**
* Print Language translation for javascript
* @param string $p_lang_key Language string being translated.
Expand All @@ -60,6 +49,11 @@ function print_translation( $p_lang_key ) {
# http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
header( 'X-Content-Type-Options: nosniff' );

# rewrite headers to allow caching
if( gpc_isset( 'cache_key' ) ) {
http_caching_headers( true );
}

echo "var translations = new Array();\n";
print_translation( 'time_tracking_stopwatch_start' );
print_translation( 'time_tracking_stopwatch_stop' );
Expand Down
15 changes: 5 additions & 10 deletions plugin.php
Expand Up @@ -27,22 +27,12 @@
* @uses plugin_api.php
*/

$t_allow_caching = isset( $_GET['cache_key'] );
if( $t_allow_caching ) {
# Suppress default headers. This allows caching as defined in server configuration
$g_bypass_headers = true;
}

require_once( 'core.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'gpc_api.php' );
require_api( 'plugin_api.php' );

if( $t_allow_caching ) {
http_security_headers();
}

$t_plugin_path = config_get_global( 'plugin_path' );

$f_page = gpc_get_string( 'page' );
Expand Down Expand Up @@ -75,5 +65,10 @@
trigger_error( ERROR_PLUGIN_PAGE_NOT_FOUND, ERROR );
}

# rewrite headers to allow caching
if( gpc_isset( 'cache_key' ) ) {
http_caching_headers( true );
}

plugin_push_current( $t_basename );
include( $t_page );

0 comments on commit d8a8873

Please sign in to comment.