Branch: Tag:

2001-10-02

2001-10-02 12:20:31 by Per Hedbor <ph@opera.com>

Some code could be simplified due to the fixes in _Roxen/roxen.c, reindented.

Rev: server/protocols/http.pike:1.338

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2001, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.337 2001/09/28 21:01:42 mast Exp $"; + constant cvs_version = "$Id: http.pike,v 1.338 2001/10/02 12:20:31 per Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
113:      string realfile, virtfile;   string rest_query=""; - string raw; + string raw="";   string query;   string not_query;   string extra_extension = ""; // special hack for the language module
726:   private int parse_got( string new_data )   {    TIMER_START(parse_got); -  multiset (string) sup; -  string a, b, s="", linename, contents; -  +     if( !method )    {    array res; -  while( strlen( new_data ) ) -  { -  string q; -  if( strlen( new_data ) > 4192 ) -  q = new_data[..4191]; -  else -  { -  q = new_data; -  new_data = ""; -  } -  if( catch { res = hpf( q ); } ) return 1; -  if( res && strlen( new_data = new_data[4192..] ) ) -  { -  res[0] += new_data; -  break; -  } -  } +  if( catch( res = hpf( new_data ) ) ) +  return 1;    if( !res )    {    TIMER_END(parse_got); -  return 0; // Not enough data; +  return 0; // Not enough data    } -  /* -  now in res: -  leftovers/data -  first line -  headers -  */ +     data = res[0];    line = res[1];    request_headers = res[2];    } -  string trailer, trailer_trailer; +  return parse_got_2(); + }    -  + private final int parse_got_2( ) + { +  string trailer, trailer_trailer; +  multiset (string) sup; +  string a, b, s="", linename, contents;    array(string) sl = line / " ";    switch( sizeof( sl ) )    {
1958:    data += s;    if(strlen(s) + have_data < wanted_data)    { -  // cache += ({ s }); +     have_data += strlen(s);    REQUEST_WERR("HTTP: We want more data.");    return;
1966:    }       if (mixed err = catch { -  int tmp; -  +     MARK_FD("HTTP got data"); -  if(!raw) raw = s; else raw += s; +  raw += s;    -  +     // The port has been closed, but old (probably keep-alive)    // connections remain. Close those connections.    if( !port_obj )
1986:    return;    }    -  if(strlen(raw)) -  tmp = parse_got( s ); -  -  switch(tmp) +  switch( parse_got( s ) )    {    case 0:    REQUEST_WERR("HTTP: Request needs more data.");
1997:       case 1:    REQUEST_WERR("HTTP: Stupid Client Error"); -  my_fd->write((prot||"HTTP/1.0")+" 500 Stupid Client Error\r\n" -  "Content-Length: 0\r\n\r\n"); +  my_fd->write((prot||"HTTP/1.0")+" 500 Illegal request\r\n" +  "Content-Length: 0\r\n"+ +  "Date: "+Roxen.http_date(predef::time())+"\r\n" +  "\r\n");    end();    return; // Stupid request.   
2007:    end();    return;    } +     if( method == "GET" )    misc->cacheable = INITIAL_CACHEABLE; // FIXME: Make configurable.   
2179:    report_error("Internal server error: " + describe_backtrace(err));    my_fd->set_blocking();    my_fd->close(); -  destruct( my_fd ); +     disconnect();    }   }
2249:      static void create(object f, object c, object cc)   { - // trace(1); +     if(f)    { - // f->set_blocking(); +     MARK_FD("HTTP connection");    f->set_read_callback(got_data);    f->set_close_callback(end);
2261:    if( cc ) conf = cc;    time = predef::time(1);    call_out(do_timeout, 90); - // string q = f->read( 8192, 1 ); - // if( q ) got_data( 0, q ); +     }    root_id = this_object();   }