new HTTP_Header package?
| From: | Wolfram Kriesing | Date: | Mon, 13 Jan 2003 12:12:53 +0000 |
| Subject: | new HTTP_Header package? | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-12328@lists.php.net to get a copy of this message | ||
i needed to handle http-caching properly, so i started a package, which (one day) shall handle any http-header operations, such as caching, etc.
there is one base-class HTTP_Header which implements common header methods
and the first class, that i needed is the HTTP_Header_Cache, which wraps http-caching, see example below
i could imagine other http-handlings to be implemented in HTTP_Header_* classes to make http-header handling a bit easier
source is here
http://os.visionp.de/tmp/HTTP_Header/Header.php.txt
http://os.visionp.de/tmp/HTTP_Header/Cache.php.txt
what do you think?
example use of HTTP_Header_Cache
$httpCache = new HTTP_Header_Cache();
// we have a css-file here
$httpCache->setHeader( 'Content-Type' , 'text/css' );
// if the file is cached in the user-agent
// and the template was not compiled again, we exit here
$httpCache->exitIfCached( !$tpl->compiled() );
// otherwise we send all the headers
$httpCache->sendHeaders();
... and keep on working the scriptimplemented by hand, without class:
header('Pragma: cache');
header('Cache-Control: public');
if( !$tpl->compiled() && $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
{
header('HTTP/1.1 304 Not Modified');
exit;
}
header('Content-Type: text/css');
// the header has to loo like this:
// Last-Modified: Mon, 27 Nov 2000 00:00:00 GMT
header('Last-Modified: '.date('D, d M Y H:i:s T') );
--
Wolfram
... opensource @ vision:produktion ...
http://opensource.visionp.de
... translating template engine ....
http://sf.net/projects/simpletpl
... authentication system ....
http://sf.net/projects/auth