Branch: Tag:

2000-08-31

2000-08-31 20:52:21 by Per Hedbor <ph@opera.com>

Added support for destruct-cache object and callbacks to limit the cacheability of things

Rev: server/protocols/http.pike:1.265

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2000, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.264 2000/08/31 03:16:37 per Exp $"; + constant cvs_version = "$Id: http.pike,v 1.265 2000/08/31 20:52:21 per Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
541:    }   }    + class CacheKey {} +    void things_to_do_when_not_sending_from_cache( )   {   #ifdef OLD_RXML_CONFIG
550:    string contents;    misc->pref_languages=PrefLanguages();    +  misc->cachekey = CacheKey(); +  misc->_cachecallbacks = ({});    if( contents = request_headers[ "accept-language"] )    {    array alang=(contents-" ") / ",";
1811: Inside #if defined(RAM_CACHE)
  #ifdef RAM_CACHE    if( (misc->cacheable > 0) && (file->data || file->file) )    { -  if( (file->len + strlen( head_string )) < conf->datacache->max_file_size ) +  if( ((file->len + strlen( head_string )) < +  conf->datacache->max_file_size) +  && misc->cachekey )    {    string data = head_string;    if( file->file ) data += file->file->read();
1819: Inside #if defined(RAM_CACHE)
   conf->datacache->set( raw_url, data,    ([    "hs":strlen(head_string), +  "key":misc->cachekey, +  "callbacks":misc->_cachecallbacks,    "len":file->len,    // fix non-keep-alive when sending from cache    "raw":(file->raw||misc->connection=="close"),
1999:    if( !conf || !(path = port_obj->path )    || (sizeof( path )    && not_query[..sizeof(path) - 1] != path) ) +     {    // FIXME: port_obj->name & port_obj->default_port are constant    // consider caching them?
2056: Inside #if defined(RAM_CACHE)
   array cv;    if( misc->cacheable && (cv = conf->datacache->get( raw_url )) )    { +  if( !cv[1]->key ) +  conf->datacache->expire_entry( raw_url ); +  else +  { +  int can_cache = 1;    if(!leftovers)    leftovers = data||"";       string d = cv[ 0 ];    file = cv[1]; -  +  +  if( sizeof(file->callbacks) ) +  { +  if( mixed e = catch +  { +  foreach( file->callbacks, function f ) +  if( !f() ) +  { +  can_cache = 0; +  break; +  } +  } ) +  { +  can_cache = 0; +  INTERNAL_ERROR( e ); +  send_result(); +  return; +  } +  } +  if( can_cache ) +  {   #ifndef RAM_CACHE_ASUME_STATIC_CONTENT    Stat st;    if( !file->rf || !file->mtime ||
2081: Inside #if defined(RAM_CACHE)
   }    return;    } +  }    file = 0;    } -  +  }   #endif       things_to_do_when_not_sending_from_cache( );
2120:    c->time = time;    c->raw_url = raw_url;    c->variables = copy_value(variables); -  c->misc = copy_value(misc); +  c->misc = copy_value( misc );    c->misc->orig = t;       c->prestate = prestate;