- md5
- 667f14bcffd8aaa3d0e8876fa25912a6
- sha1
- d1e1f124d3603c52027d6d626b92778052cf2a6d
- sha256
- c65b350c72eb3b97e1609187ca4af6b262b00077b9ed8756434151662655dd7d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
<?php
//*******************************************************************
//php_http_server_generic represents a basic http server
//*******************************************************************
//by John Heinstein
//[email protected]
//*******************************************************************
//Version 0.1
//copyright 2004 Engage Interactive
//http://www.engageinteractive.com/dom_xmlrpc/
//All rights reserved
//*******************************************************************
//Licensed under the GNU General Public License (GPL)
//http://www.gnu.org/copyleft/gpl.html
//*******************************************************************
if (!defined('PHP_HTTP_TOOLS_INCLUDE_PATH')) {
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
}
define ('CRLF', "\r\n"); //end-of-line char as defined in HTTP spec
define ('CR', "\r");
define ('LF', "\n");
class php_http_server_generic {
var $httpStatusCodes;
var $protocol = 'HTTP';
var $protocolVersion = '1.0';
var $statusCode = 200;
var $events = array('onRequest' => null, 'onResponse' => null,
'onGet' => null, 'onHead' => null,
'onPost' => null, 'onPut' => null);
function php_http_server_generic() {
//require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_status_codes.php');
//$this->httpStatusCodes =&new php_http_status_codes();
} //php_http_server_generic
function &getHeaders() {
$headers = headers_list();
$response = '';
if (count($headers) > 0) {
foreach ($headers as $key => $value) {
$response .= $value . CRLF;
}
}
return $response;
} //getHeaders
function setProtocolVersion($version) {
if (($version == '1.0') || ($version == '1.1')) {
$$this->protocolVersion = $version;
return true;
}
return false;
} //setProtocolVersion
function setHeader($name, $value) {
header($name . ': ' . $value);
} //setHeader
function setHeaders() {
//you will want to override this method
$this->setHeader('Content-Type', 'text/html');
$this->setHeader('Server', 'PHP HTTP Server (Generic)/0.1');
} //setHeaders
function fireEvent($target, $data) {
if ($this->events[$target] != null) {
call_user_func($this->events[$target], $data);
}
} //fireEvent
function fireHTTPEvent($target, $data = null) {
if ($this->events[$target] == null) {
//if no handler is assigned,
//delegate the event to the default handler
$this->setHTTPEvent($target);
}
call_user_func($this->events[$target], $data);
} //fireHTTPEvent
function setHTTPEvent($option, $customHandler = null) {
if ($customHandler != null) {
$handler =& $customHandler;
}
else {
$handler = array(&$this, 'defaultHTTPEventHandler');
}
switch($option) {
case 'onGet':
case 'onHead':
case 'onPost':
case 'onPut':
$this->events[$option] =& $handler;
break;
}
} //setHTTPServerEvent
function defaultHTTPHandler() {
//will add functionality for this later
//work with subclasses for the time being
} //defaultHTTPHandler
function setDebug($option, $truthVal, $customHandler = null) {
if ($customHandler != null) {
$handler =& $customHandler;
}
else {
$handler = array(&$this, 'defaultDebugHandler');
}
switch($option) {
case 'onRequest':
case 'onResponse':
$truthVal ? ($this->events[$option] =& $handler) :
($this->events[$option] = null);
break;
}
} //setDebug
function getDebug($option) {
switch($option) {
case 'onRequest':
case 'onResponse':
return ($this->events[$option] != null);
break;
}
} //getDebug
function defaultDebugHandler($data) {
//just write to a log file, since can't display in a browser
$this->writeDebug($data);
} //defaultDebugHandler
function writeDebug($data) {
$filename = 'debug_' . time() . '.txt';
$fileHandle = fopen($fileName, 'a');
fwrite($fileHandle, $data);
fclose($fileHandle);
} //writeDebug
function receive() {
global $HTTP_SERVER_VARS;
$requestMethod = strToUpper($HTTP_SERVER_VARS['REQUEST_METHOD']);
switch ($requestMethod) {
case 'GET':
$this->fireHTTPEvent('onGet');
break;
case 'HEAD':
$this->fireHTTPEvent('onHead');
break;
case 'POST':
$this->fireHTTPEvent('onPost');
break;
case 'PUT':
$this->fireHTTPEvent('onPut');
break;
}
} //receive
function respond($response) {
//build header info
//$response = $this->protocol . '/' . $this->protocolVersion . ' ' .
//$this->statusCode . ' ' . $this->httpStatusCodes->getCodeString($this->statusCode) . CRLF;
if (!headers_sent()) { //avoid generating an error when in debug mode
$this->setHeader('Date', "date('r')");
$this->setHeader('Content-Length', strlen($response));
$this->setHeader('Connection', 'Close');
}
echo $response;
} //respond
} //php_http_server_generic
//To invoke the server, do:
//$httpServer = new php_http_server_generic(); //or instance of a subclass
//$httpServer->receive();
?>
The same content is in 26 releases, Joomla 1.5.1 to 1.5.26. See them all, or every version of this file.