MidCOM svn: r17501 - in branches/MidCOM_2_8/midcom.core/midcom: . services/cache/module
rambo
midcom-commits at lists.midgard-project.org
Thu Sep 11 21:38:01 CEST 2008
Author: rambo
Date: Thu Sep 11 21:38:01 2008
New Revision: 17501
URL: http://trac.midgard-project.org/software/changeset/17501
Log:
fix 304 checks for attachments
Modified:
branches/MidCOM_2_8/midcom.core/midcom/application.php
branches/MidCOM_2_8/midcom.core/midcom/services/cache/module/content.php
Modified: branches/MidCOM_2_8/midcom.core/midcom/application.php
==============================================================================
--- branches/MidCOM_2_8/midcom.core/midcom/application.php (original)
+++ branches/MidCOM_2_8/midcom.core/midcom/application.php Thu Sep 11 21:38:01 2008
@@ -2467,10 +2467,12 @@
|| $expires < -1)
{
debug_pop();
- $this->generate_error(MIDCOM_ERRCRIT, "\$expires has to be a positive integer or -1.");
+ $this->generate_error(MIDCOM_ERRCRIT, "\$expires has to be a positive integer or zero or -1.");
// This will exit()
}
+ // Doublecheck that this is registered
+ $this->cache->content->register($attachment->guid);
$stats = $attachment->stat();
$last_modified =& $stats[9];
@@ -2498,17 +2500,17 @@
}
$this->header("ETag: {$etag}");
- $this->cache->content->register_sent_header("ETag: {$etag}");
+ //$this->cache->content->register_sent_header("ETag: {$etag}");
$this->cache->content->content_type($attachment->mimetype);
- $this->header("Content-Type: {$attachment->mimetype}");
+ //$this->header("Content-Type: {$attachment->mimetype}");
$this->cache->content->register_sent_header("Content-Type: {$attachment->mimetype}");
$this->header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified) . ' GMT');
- $this->cache->content->register_sent_header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified) . ' GMT');
+ //$this->cache->content->register_sent_header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified) . ' GMT');
$this->header("Content-Length: " . $stats[7]);
- $this->cache->content->register_sent_header("Content-Length: " . $stats[7]);
+ //$this->cache->content->register_sent_header("Content-Length: " . $stats[7]);
// PONDER: Support ranges ("continue download") somehow ?
$this->header("Accept-Ranges: none");
- $this->cache->content->register_sent_header("Accept-Ranges: none");
+ //$this->cache->content->register_sent_header("Accept-Ranges: none");
if ($expires > 0)
{
@@ -2533,6 +2535,14 @@
/* live mode automatically enters no_cache, so we disable buffers ourself
$this->cache->content->enable_live_mode();
*/
+
+ // Store metadata in cache so _check_hit() can help us
+ if ( !$this->cache->content->_uncached
+ && !$this->cache->content->_no_cache)
+ {
+ $this->cache->content->write_meta_cache('A-' . $etag, $etag);
+ }
+
while(@ob_end_flush());
fpassthru($f);
$attachment->close();
Modified: branches/MidCOM_2_8/midcom.core/midcom/services/cache/module/content.php
==============================================================================
--- branches/MidCOM_2_8/midcom.core/midcom/services/cache/module/content.php (original)
+++ branches/MidCOM_2_8/midcom.core/midcom/services/cache/module/content.php Thu Sep 11 21:38:01 2008
@@ -298,6 +298,7 @@
/**
* This can leak data usefull for attacker, OTOH it's very handy for debugging
+ *
if ($context === 0)
{
header("X-MidCOM-request-id-source: {$identifier_source}");
@@ -306,7 +307,7 @@
debug_add("Generating context {$context} request-identifier from: {$identifier_source}");
debug_print_r('$customdata was: ', $customdata);
debug_pop();
- */
+ /* */
return 'R-' . md5($identifier_source);
}
@@ -940,7 +941,7 @@
* has been called, the cache file will not be written, but the header stuff will be added like
* usual to allow for browser-side caching.
*/
- function _finish_caching()
+ function _finish_caching($etag=null)
{
if ( $this->_no_cache
|| $this->_live_mode)
@@ -982,52 +983,13 @@
}
else
{
- // Construct cache identifiers
- $context = $_MIDCOM->get_current_context();
- $request_id = $this->generate_request_identifier($context);
/**
* See the FIXME in generate_content_identifier on why we use the content hash
$content_id = $this->generate_content_identifier($context);
*/
$content_id = 'C-' . $etag;
-
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_add("Creating cache entry for {$content_id} as {$request_id}", MIDCOM_LOG_INFO);
- debug_pop();
-
- if (!is_null($this->_expires))
- {
- $entry_data['expires'] = $this->_expires;
- }
- else
- {
- // Use default expiry for cache entry, most components don't bother calling expires() properly
- /*
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_add("explicit expires is not set, using \$this->_default_lifetime: {$this->_default_lifetime}");
- debug_pop();
- */
- $entry_data['expires'] = time() + $this->_default_lifetime;
- }
- $entry_data['etag'] = $etag;
- $entry_data['last_modified'] = $this->_last_modified;
- $entry_data['sent_headers'] = $this->_sent_headers;
- /**
- * Remove comment to debug cache
- */
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_print_r("Writing meta-cache entry {$content_id}", $entry_data);
- debug_pop();
- /* */
- $this->_meta_cache->open(true);
- $this->_meta_cache->put($content_id, $entry_data);
+ $this->write_meta_cache($content_id, $etag);
$this->_data_cache->put($content_id, $cache_data);
- $this->_meta_cache->put($request_id, $content_id);
- $this->_meta_cache->close();
-
- // Cache where the object have been
- $this->store_context_guid_map($context, $content_id, $request_id);
-
}
// Finish caching.
@@ -1039,6 +1001,54 @@
}
}
+ /**
+ * Writes meta-cache entry from context data using given content id
+ * Used to be part of _finish_caching, but needed by serve-attachment method in midcom_application as well
+ */
+ function write_meta_cache($content_id, $etag)
+ {
+ // Construct cache identifiers
+ $context = $_MIDCOM->get_current_context();
+ $request_id = $this->generate_request_identifier($context);
+
+ debug_push_class(__CLASS__, __FUNCTION__);
+ debug_add("Creating cache entry for {$content_id} as {$request_id}", MIDCOM_LOG_INFO);
+ debug_pop();
+
+ if (!is_null($this->_expires))
+ {
+ $entry_data['expires'] = $this->_expires;
+ }
+ else
+ {
+ // Use default expiry for cache entry, most components don't bother calling expires() properly
+ /*
+ debug_push_class(__CLASS__, __FUNCTION__);
+ debug_add("explicit expires is not set, using \$this->_default_lifetime: {$this->_default_lifetime}");
+ debug_pop();
+ */
+ $entry_data['expires'] = time() + $this->_default_lifetime;
+ }
+ $entry_data['etag'] = $etag;
+ $entry_data['last_modified'] = $this->_last_modified;
+ $entry_data['sent_headers'] = $this->_sent_headers;
+ /**
+ * Remove comment to debug cache
+ */
+ debug_push_class(__CLASS__, __FUNCTION__);
+ debug_print_r("Writing meta-cache entry {$content_id}", $entry_data);
+ debug_pop();
+ /* */
+ $this->_meta_cache->open(true);
+ $this->_meta_cache->put($content_id, $entry_data);
+ $this->_meta_cache->put($request_id, $content_id);
+ $this->_meta_cache->close();
+
+ // Cache where the object have been
+ $this->store_context_guid_map($context, $content_id, $request_id);
+ }
+
+
function store_context_guid_map($context, $content_id, $request_id)
{
$this->_meta_cache->open(true);
More information about the midcom-commits
mailing list