Branch: Tag:

2004-04-04

2004-04-04 00:13:11 by Martin Nilsson <mani@lysator.liu.se>

WebServer sync [1.388]

Rev: server/plugins/protocols/http.pike:1.394

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2001, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.393 2003/01/23 16:21:02 mani Exp $"; + constant cvs_version = "$Id: http.pike,v 1.394 2004/04/04 00:13:11 mani Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
55:      private static array(string) cache;   private static int wanted_data, have_data; + private static String.Buffer data_buffer;      #include <roxen.h>   #include <module.h>
71:      mapping (string:mixed) misc =   ([ - #if 0 +    #ifdef REQUEST_DEBUG    "trace_enter":lambda(mixed ...args) {    REQUEST_WERR(sprintf("TRACE_ENTER(%{%O,%})", args));
80: Inside #if 0 and #if defined(REQUEST_DEBUG)
   REQUEST_WERR(sprintf("TRACE_LEAVE(%{%O,%})", args));    }   #endif // REQUEST_DEBUG - #endif +    ]);   mapping (string:string) cookies = ([ ]);   mapping (string:string) request_headers = ([ ]);
331:    pipe->set_throttler( throttler || conf->throttler );    pipe->set_done_callback( do_log );    pipe->start( ); +  data_buffer = 0;    pipe = 0;   }   
548: Inside #if undefined(DISABLE_SUPPORTS)
   }    if ( client_var->charset && client_var->charset != "iso-8859-1" )    { -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    set_output_charset( client_var->charset );    input_charset = client_var->charset;    decode_charset_encoding( client_var->charset );
665:    }    s = data = ""; // no headers or extra data...    sscanf( f, "%s%*[\r\n]", f ); -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    break;       case 0:
1111:      void internal_error(array _err)   { -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    mixed err = _err;    _err = 0; // hide in backtrace, they are bad enough anyway...    array err2;
1438:    if(elapsed > p[2]) p[2]=elapsed;   #endif    -  REQUEST_WERR(sprintf("HTTP: response: prot %O, method %O, file %O", -  prot, method, file)); +  REQUEST_WERR(sprintf("HTTP: response: prot %O, method %O, file %O, misc: %O", +  prot, method, file, misc));    -  +  if( prot == "HTTP/0.9" ) misc->no_proto_cache = 1; +     if(!leftovers)    leftovers = data||"";       if(!mappingp(file))    { -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    if(misc->error_code)    file = Roxen.http_low_answer(misc->error_code, errors[misc->error]);    else if(err = catch {
1493:    misc->last_modified = fstat[ST_MTIME];    }    -  if( misc->cacheable < INITIAL_CACHEABLE ) { +  if( !zero_type(misc->cacheable) && +  misc->cacheable < INITIAL_CACHEABLE ) {    if (misc->cacheable == 0) {    heads["Expires"] = Roxen.http_date( 0 );   
1518:    if ( (since_info[0] >= misc->last_modified) &&    ((since_info[1] == -1) || (since_info[1] == file->len))    // never say 'not modified' if cacheable has been lowered. -  && (misc->cacheable >= INITIAL_CACHEABLE) ) +  && (zero_type(misc->cacheable) || +  misc->cacheable >= INITIAL_CACHEABLE) )    {    file->error = 304;    file->file = 0;
1576:    array ranges = parse_range_header(file->len);    if(ranges) // No incorrect syntax...    { -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    if(sizeof(ranges)) // And we have valid ranges as well.    {    file->error = 206; // 206 Partial Content
1810:       if(wanted_data)    { -  data += s; +     if(strlen(s) + have_data < wanted_data)    { -  +  if(!data_buffer) { +  // The 16384 is some reasonable extra padding to +  // avoid having to realloc. +  data_buffer = String.Buffer(wanted_data + 16384); +  data_buffer->add(data); +  data = ""; +  } +  data_buffer->add(s);    have_data += strlen(s); -  +     // Reset timeout.    remove_call_out(do_timeout);    call_out(do_timeout, 90);    REQUEST_WERR("HTTP: We want more data.");    return;    } -  +  if(data_buffer) { +  data_buffer->add(s); +  data = (string)data_buffer; +  data_buffer = 0;    } -  +  else +  data += s; +  }       if (mixed err = catch {    MARK_FD("HTTP got data");
1863:    return;    }    -  if( method == "GET" ) +  if( (< "GET", "HEAD" >)[method] )    misc->cacheable = INITIAL_CACHEABLE; // FIXME: Make configurable.       TIMER_START(find_conf);
1917:    if (rawauth)    {    /* Need to authenticate with the configuration */ -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    array(string) y = rawauth / " ";    realauth = 0;    auth = 0;
1932:    if( misc->proxyauth )    {    /* Need to authenticate with the configuration */ -  misc->cacheable = 0; +  misc->no_proto_cache = 1;    if (sizeof(misc->proxyauth) >= 2)    {    // misc->proxyauth[1] = MIME.decode_base64(misc->proxyauth[1]);
2035: Inside #if defined(RAM_CACHE)
   st ? "mtime " + st->mtime : "gone", file->mtime));   #endif    } else -  misc->cacheable = 0; // Never cache in this case. +  misc->no_proto_cache = 1; // Never cache in this case.    file = 0;    }    }