Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63885 - website/public_html/beta/common/code
From: daniel_james_at_[hidden]
Date: 2010-07-11 13:39:40


Author: danieljames
Date: 2010-07-11 13:39:39 EDT (Sun, 11 Jul 2010)
New Revision: 63885
URL: http://svn.boost.org/trac/boost/changeset/63885

Log:
Better HTTP support.
Text files modified:
   website/public_html/beta/common/code/boost_archive.php | 50 ++++++++++++++++++++++++++++++++++++----
   1 files changed, 45 insertions(+), 5 deletions(-)

Modified: website/public_html/beta/common/code/boost_archive.php
==============================================================================
--- website/public_html/beta/common/code/boost_archive.php (original)
+++ website/public_html/beta/common/code/boost_archive.php 2010-07-11 13:39:39 EDT (Sun, 11 Jul 2010)
@@ -91,8 +91,11 @@
         return;
     }
 
- header('last-modified:'. date(DATE_RFC2822,
- filemtime($params['archive'])));
+ $last_modified = max(strtotime("11 July 2010"),
+ filemtime($params['archive']));
+
+ if (!conditional_get($last_modified))
+ return;
 
     // Extract the file from the zipfile
 
@@ -112,14 +115,16 @@
         file_not_found($params, $params['content']);
         return;
     }
-
+
     if($type == 'text/html') {
         if(html_headers($params['content'])) {
- echo $params['content'];
- exit(0);
+ if($_SERVER['REQUEST_METHOD'] != 'HEAD') echo $params['content'];
+ return;
         }
     }
 
+ if($_SERVER['REQUEST_METHOD'] == 'HEAD') return;
+
     if ($preprocess) {
         $params['content'] = call_user_func($preprocess, $params['content']);
     }
@@ -127,6 +132,36 @@
     echo_filtered($extractor, $params);
 }
 
+function conditional_get($last_modified) {
+ if(!$last_modified) return true;
+
+ $last_modified_text = date(DATE_RFC2822, $last_modified);
+ $etag = '"'.md5($last_modified).'"';
+
+ header("Last-Modified: $last_modified_text");
+ header("ETag: $etag");
+
+ $checked = false;
+
+ if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+ $checked = true;
+ $if_modified_since = strtotime(stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']));
+ if(!$if_modified_since || $if_modified_since < $last_modified)
+ return true;
+ }
+
+ if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
+ $checked = true;
+ if(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'] != $etag)
+ return true;
+ }
+
+ if(!$matched) return true;
+
+ header('HTTP/1.0 304 Not Modified');
+ return false;
+}
+
 class boost_archive_render_callbacks {
     var $content_callback, $params;
     
@@ -157,6 +192,11 @@
 
 function display_raw_file($unzip, $type) {
     header('Content-type: '.$type);
+
+ // Since we're not returning a HTTP error for non-existant files,
+ // might as well not bother checking for the file
+ if($_SERVER['REQUEST_METHOD'] == 'HEAD') return;
+
     ## header('Content-Disposition: attachment; filename="downloaded.pdf"');
     $file_handle = popen($unzip,'rb');
     fpassthru($file_handle);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk