> I want to create a program that checks if the request conditions are met (if
> the page wanted is newer than the one in the cache) and if yes, to return
> the new page, or if it was not modified since the specified date and time,
> to return 304 Not Modified.

didn't I show how to do that the other day?  basically, don't worry about
doing anything yourself - just set the appropriate headers and let apache
deal with everything else

  # set the content type
  $r->content_type('text/html');


  # figure out what the latest time to check on the filesystem is
  # and use that in the last-modified header
  $r->update_mtime($some_important_time);
  $r->update_mtime($some_other_important_time);
  $r->set_last_modified;

  # Now, if all the If-* headers say we're good to go, send the response.
  # Otherwise, return a status and let Apache handle it from here.
  if ((my $status = $r->meets_conditions) == OK) {
    # send new content
    return OK;
  }
  else {
    return $status;  # most likely 304
  }

that's pretty much all there is to it.  chapter 6 in the cookbook goes into
this a bit more, like if you want to do byteserving or some other things,
but this is the crux of it.  and it should be pretty much the same with mp2
as the mp1 example here.

> 
> I have tried searching with Google for "custom_response" but until now I
> couldn't find helpful data about using the caching and generating correct
> HTTP headers...

it has nothing to do with custom_response, which is really only for error
pages.  ok, so 304 is technically an error, but it's a special case...

--Geoff

Reply via email to