pike.git / lib / modules / Protocols.pmod / HTTP.pmod / Session.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:1:   #pike __REAL_VERSION__    - // $Id: Session.pike,v 1.8 2003/03/13 22:47:02 nilsson Exp $ + // $Id: Session.pike,v 1.9 2003/03/20 20:05:54 mirar Exp $      import Protocols.HTTP;      typedef string|Standards.URI|SessionURL URL;      //! The number of redirects to follow, if any.   //! This is the default to the created Request objects.   //!   //! A redirect automatically turns into a GET request,   //! and all header, query, post or put information is dropped.
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:85: Inside #if constant(SSL.sslfile)
   "protocols than HTTP or HTTPS\n",    url->scheme);       con_https= (url->scheme=="https")? 1 : 0;   #else    if(url->scheme!="http" )    error("Protocols.HTTP can't handle %O or any other "    "protocol than HTTP\n",    url->scheme);   #endif -  mapping request_headers = default_headers; +  mapping request_headers = copy_value(default_headers);    if (url->referer)    request_headers->referer=(string)url->referer;       if(url->user || url->passwd)    request_headers->authorization = "Basic "    + MIME.encode_base64(url->user + ":" +    (url->password || ""));       request_headers->connection=    (time_to_keep_unused_connections<=0)?"Close":"Keep-Alive";
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:424:       if (sizeof(v)<1) return;    v=v[0];    if (sizeof(v)<1) return;    [key,data]=v[0];       foreach (v[1..];;[string what,string value])    switch (lower_case(what))    {    case "expires": -  werror("%O\n",value); +     expires=    (Calendar.ISO.parse("%e, %D %M %Y %h:%m:%s %z",value)||    Calendar.ISO.parse("%e, %D-%M-%y %h:%m:%s %z",value) )    ->unix_time();    break;       case "path":    path=value;    break;    }
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:487:   // fixme: insert security checks here       mapping sc=([]);    if ( (sc=cookie_lookup[cookie->site]) )    {    Cookie old=sc[cookie->key];    if (old) all_cookies[old]=0;    }    else    sc=cookie_lookup[cookie->site]=([]); +     sc[cookie->key]=cookie;    all_cookies[cookie]=1;   }      //! @decl string encode_cookies()   //! @decl void decode_cookies(string data,void no_clear)   //! Dump all cookies to a string and read them back. This is useful to   //! store cookies in between sessions (on disk, for instance).   //! @[decode_cookies] will throw an error upon parse failures.   //! Also note, @[decode_cookies] will clear out any previously
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:583:   //! Used only by async requests.   //! Defaults to 10 connections.   int maximum_connections_per_server=10;      //! Maximum total number of connections. Limits only   //! async requests, and the number of kept-alive connections   //! (live connections + kept-alive connections <= this number)   //! Defaults to 50 connections.   int maximum_total_connections=50;    + //! Maximum times a connection is reused. + //! Defaults to 1000000. &lt;2 means no reuse at all. + int maximum_connection_reuse=1000000;    -  +    // internal (but readable for debug purposes)   mapping(string:array(KeptConnection)) connection_cache=([]);   int connections_kept_n=0;   int connections_inuse_n=0;   mapping(string:int) connections_host_n=([]);      static class KeptConnection   {    string lookup;    Query q;
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:653:   {    Query q;       if (array(KeptConnection) v =    connection_cache[connection_lookup(url)])    {    q=v[0]->use(); // removes itself    // clean up    q->buf="";    q->headerbuf=""; +  q->n_used++;    }    else    {    if (connections_kept_n+connections_inuse_n+1    >= maximum_total_connections &&    sizeof(connection_cache))    {    // close one if we have it kept    array(KeptConnection) all=`+(@values(connection_cache));    KeptConnection one=all[random(sizeof(all))];    one->disconnect(); // removes itself    }    -  q=Query(); +  q=SessionQuery();    q->hostname_cache=hostname_cache;    connections_host_n[connection_lookup(url)]++; // new    }    connections_inuse_n++;    return q;   }      //   // called when there might be a free connection   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:707:    }   }      //! Return a previously used Query object to the keep-alive   //! storage. This function will determine if the given object   //! is suitable to keep or not by checking status and headers.   void return_connection(Standards.URI url,Query query)   {    connections_inuse_n--;    string lookup=connection_lookup(url); -  if (query->con) +  if (query->con && query->is_sessionquery)    {    if (query->headers->connection &&    lower_case(query->headers->connection)=="keep-alive" &&    connections_kept_n+connections_inuse_n    < maximum_total_connections && -  time_to_keep_unused_connections>0) +  time_to_keep_unused_connections>0 && +  query->n_used < maximum_connection_reuse)    {    // clean up    query->set_callbacks(0,0);    KeptConnection(lookup,query);    freed_connection(lookup);    return;    }    destruct(query->con);    }    destruct(query);
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:983:   //! when fed to Protocols.HTTP.Session calls, will add   //! referer to the HTTP handshaking variables    void create(URL uri,    URL base_uri,    URL _referer)    {    ::create(uri,base_uri);    referer=_referer;    }   } +  + class SessionQuery + { +  inherit Query; +  +  int n_used=1; +  constant is_sessionquery=1; + }