Added HttpSuccess exception which can be thrown when a scriptlet is done executing normally
authorDan
Wed, 02 Jul 2008 11:57:13 -0400
changeset 24 d275dc8f4203
parent 23 08225c2eb0b6
child 25 5c377ceb0e4c
child 26 300d374d89b0
Added HttpSuccess exception which can be thrown when a scriptlet is done executing normally
webserver.php
--- a/webserver.php	Tue Jul 01 04:17:46 2008 -0400
+++ b/webserver.php	Wed Jul 02 11:57:13 2008 -0400
@@ -29,7 +29,7 @@
 define('HTTPD_ICON_FILE', 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAINSURBVBgZBcG/r55zGAfg6/4+z3va01NHlYgzEfE7MdCIGISFgS4Gk8ViYyM2Mdlsko4GSf8Do0FLRCIkghhYJA3aVBtEz3nP89wf11VJvPDepdd390+8Nso5nESBQoq0pfvXm9fzWf19453LF85vASqJlz748vInb517dIw6EyYBIIG49u+xi9/c9MdvR//99MPPZ7+4cP4IZhhTPbwzT2d+vGoaVRRp1rRliVvHq+cfvM3TD82+7mun0o/ceO7NT+/4/KOXjwZU1ekk0840bAZzMQ2mooqh0A72d5x/6sB9D5zYnff3PoYBoWBgFKPKqDKqjCpjKr//dcu9p489dra88cydps30KswACfNEKanSaxhlntjJ8Mv12Paie+vZ+0+oeSwwQ0Iw1xAR1CiFNJkGO4wu3ZMY1AAzBI0qSgmCNJsJUEOtJSMaCTBDLyQ0CknAGOgyTyFFiLI2awMzdEcSQgSAAKVUmAeNkxvWJWCGtVlDmgYQ0GFtgg4pNtOwbBcwQy/Rife/2yrRRVI0qYCEBly8Z+P4qMEMy7JaVw72N568e+iwhrXoECQkfH91kY7jwwXMsBx1L93ZruqrK6uuiAIdSnTIKKPLPFcvay8ww/Hh+ufeznTXu49v95IMoQG3784gYXdTqvRmqn/Wpa/ADFX58MW3L71SVU9ETgEIQQQIOOzub+fhIvwPRDgeVjWDahIAAAAASUVORK5CYII=');
 
 /**
- * Simple web server written in PHP.
+ * Simple but full-featured embedded web server written in PHP.
  * @package Amarok
  * @subpackage WebControl
  * @author Dan Fuhry
@@ -889,20 +889,30 @@
         // throw an HttpExceptionFatal when you need to break out of an in-progress scriptlet due to an error, use it in place of die() or exit()
         catch ( HttpExceptionFatal $e )
         {
+          ob_end_clean();
           restore_error_handler();
           $this->send_http_error($socket, 500, "A handler crashed reporting a fatal exception; see the command line for details.");
           if ( function_exists('status') )
             status("fatal exception in handler {$handler['id']}:\n$e");
           return true;
         }
+        catch ( HttpSuccess $e )
+        {
+          // just finish with success
+          $this->in_scriptlet = false;
+          $output = ob_get_contents();
+          ob_end_clean();
+        }
         catch ( Exception $e )
         {
+          ob_end_clean();
           restore_error_handler();
           $this->send_http_error($socket, 500, "There was an uncaught exception during the execution of a scripted handler function. See the command line for details.");
           if ( function_exists('status') )
             status("uncaught exception in handler {$handler['id']}:\n$e");
           return true;
         }
+        
         restore_error_handler();
         
         // the handler function should return this magic string if it writes its own headers and socket data
@@ -1473,6 +1483,14 @@
 }
 
 /**
+ * Exception class that will be treated as a scriptlet ending with success.
+ */
+
+class HttpSuccess extends Exception
+{
+}
+
+/**
  * Array of known HTTP status/error codes
  */
  
@@ -1491,7 +1509,7 @@
   );
 
 /**
- * Array of default mime type->html mappings
+ * Array of default extension->mimetype mappings
  */
 
 $mime_types = array(