Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.4

Request #12372 Need a way to set the Expires header
Submitted: 2007-11-01 16:40 UTC
From: redbeard Assigned:
Status: Feedback Package: HTTP_Download (version 1.1.3)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 17 - 10 = ?

 
 [2007-11-01 16:40 UTC] redbeard (Michael Johnson)
Description: ------------ I'm developing a system that puts most data behind a PHP loader page that uses HTTP_Download. Unfortunately, I can't get Firefox to cache anything since it ignores the Cache-Control header. So I will be manually adding Expires headers. It would be nice if this could be done directly via HTTP_Download. I'd recommend a params option as well as an explicit method (setExpires()?).

Comments

 [2007-11-01 17:51 UTC] cwiedmann (Carsten Wiedmann)
| I can't get Firefox to cache anything since it ignores the | Cache-Control header. So I will be manually adding Expires | headers. According to the HTTP/1.1 RFC, the max-age Cache-Control, set from HTTP_Download, overrides an Expires. So I think it's better, if HTTP_Download set Expires itself, calculated from Last-Modified and max-age Cache-Control? | I'd recommend a params option as well as an explicit | method(setExpires()?). Or add a public method setHeader(). So you can set any additional header you want. Regards, Carsten
 [2007-11-02 17:15 UTC] redbeard (Michael Johnson)
I like the idea of HTTP_Download calculating the Expires header. I think it's necessary to have if you've enabled caching (since Firefox doesn't honor Cache-Control), if it's automatic I'd be happy. I also like the idea of a setHeader() method. At the moment I'm calling setHeader() on the HTTP_Header object contained by HTTP_Download, which is marked as protected in the docblock, definitely note the proper way to do it, but it works :)
 [2007-11-02 23:28 UTC] cwiedmann (Carsten Wiedmann)
| I can't get Firefox to cache anything since | it ignores the Cache-Control header. One question. I 've made a short test with this code and Firefox 2.0.0.8/Windows: | <?php | require_once 'HTTP/Download.php'; | | $params = array( | 'file' => 'test.txt', | 'contenttype' => 'text/plain', | 'contentdisposition' => array( | HTTP_DOWNLOAD_INLINE, 'text.txt') | ); | | HTTP_Download::staticSend($params, false); | ?> The LiveHTTPHeaders log looks like: | GET /test/test2.php HTTP/1.1 | | HTTP/1.x 200 OK | Pragma: cache | Cache-Control: public, must-revalidate, max-age=0 | Etag: d168400f474436b65dfe52ab130a4a78-1871518421 | Last-Modified: Sat, 03 Nov 2007 00:05:42 GMT | ---------------------------------------------------------- | GET /test/test2.php HTTP/1.1 | If-Modified-Since: Sat, 03 Nov 2007 00:05:42 GMT | If-None-Match: d168400f474436b65dfe52ab130a4a78-1871518421 | Cache-Control: max-age=0 | | HTTP/1.x 304 Not Modified | Etag: d168400f474436b65dfe52ab130a4a78-1871518421 | Cache-Control: public, must-revalidate, max-age=0 | ---------------------------------------------------------- So in this example, caching is working. Regards, Carsten
 [2007-11-06 18:35 UTC] redbeard (Michael Johnson)
Yes, it is indeed working. However, if you check on the server when accessing the page a second time, Firefox sends a request to the server, even if max-age is set to a non-zero value. My goal was to prevent the browser from hitting the server at all. This helps with server load as well as bandwidth and latency. Since most of the content we're showing is accessed hundreds of times a day from each individual browser it's a huge win. The end result is that caching is required. The cache control options help, but are, at least in part, ignored by at least some versions of Firefox. The Expires header, however, is honored by all browsers.
 [2007-11-07 07:09 UTC] cwiedmann (Carsten Wiedmann)
> However, if you check on the server when accessing > the page a second time, Firefox sends a request > to the server, Correct, this is the second request with the 304 response in my example. > Firefox sends a request to the server, even if max-age > is set to a non-zero value. Right, because if "max-age" is set (>=0), a browser/proxy allways revalidate its cache. I think here is a problem in the script. The script should not set this Cache-Control directive by default. I also don't understand, why "must-revalidate" is set by default. This should be set only in very rare situations. BTW: With F5 or the reload button in your browser, your browser allways revalidate its cache. > The cache control options help, but are, at least in > part, ignored by at least some versions of Firefox. > The Expires header, however, is honored by all browsers. Well, I've made a patch which solve these problems: a) "max-age" and "must-revalidate" is not set by default b) the method setCacheControl() is now: | ($cache='public', $maxage=false, $revalidate=false) - $maxage can be false ("max-age" is not set) or an integer >=0 - according to "max-age", a correct "Expires" header is set. the maximimum value is 1 year in seconds - with $revalidate=true, "must-revalidate" is enabled - "Last-Modified" is now allways set. Also if cache is disabled. - the "Pragma" header is now set correct, according to cache enable/disable. Together with the "Expires" header, it's now more compatible to HTTP/1.0 clients - I've changed the default "Content-Type" to "application/octet-stream", which is IANA registered Regards, Carsten
 [2007-11-07 14:56 UTC] redbeard (Michael Johnson)
That sounds like it'll do what I need. I'll try it out as soon as I get a chance. Thanks for the work! Michael
 [2012-01-14 20:00 UTC] doconnor (Daniel O'Connor)
There's a fair bit of content here, and minor changes to method signatures. With no test coverage... :S Is there any chance you could fork and send a pull request for https://github.com/pear/HTTP_Download2
 [2012-01-14 20:00 UTC] doconnor (Daniel O'Connor)
-Status: Open +Status: Feedback