oseawey / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

HTTP_IF_MODIFIED_SINCE in nginx #180

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set up the timthumb script on a machine with nginx as the webserver
2. Try to load an image with it

What is the expected output? What do you see instead?
Should see the image. Instead, get a 500 error.

What version of the product are you using? On what operating system?
Running PHP v. 5.3.3 on Ubuntu 10.10 with nginx v. 0.7.6 & PHP-FPM

Please provide any additional information below.
nginx always sets HTTP_IF_MODIFIED SINCE, even when it is not passed. Thus, in 
show_cache_file(), the 304 header will always be returned:

function show_cache_file ($mime_type) {
   // use browser cache if available to speed up page load
   if (isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {

      // Code will always execute here

      if (strtotime ($_SERVER['HTTP_IF_MODIFIED_SINCE']) <   
          strtotime('now')
      ) {
         header ('HTTP/1.1 304 Not Modified');
         die ();
      }
   }
.
.
.

To fix, check for non-null (or better yet, a valid time string) in the first 
condition as well:

function show_cache_file ($mime_type) {
   // use browser cache if available to speed up page load
   if (isset ($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
       $_SERVER['HTTP_IF_MODIFIED_SINCE']
      ) {

      // Code will execute here if non-null if-modified-since
      // header passed

      if (strtotime ($_SERVER['HTTP_IF_MODIFIED_SINCE']) <   
          strtotime('now')
      ) {
         header ('HTTP/1.1 304 Not Modified');
         die ();
      }
   }
.
.
.

Original issue reported on code.google.com by brahmac...@gmail.com on 17 Apr 2011 at 5:23

GoogleCodeExporter commented 9 years ago
This is not limited to your php or nginx setup. Your proposed fix makes sense.

Original comment by michi...@gmail.com on 19 Apr 2011 at 8:53

GoogleCodeExporter commented 9 years ago
I've added this to the latest version. Thanks for the pointer

Original comment by BinaryMoon on 21 Apr 2011 at 10:22