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

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:365:    void check_for_cookies()    {    if (!con->ok || !con->headers || !cookie_encountered) return;       foreach (con->headers["set-cookie"]||({});;string cookie)    cookie_encountered(cookie,url_requested);    }      // ----------------    + #pragma no_deprecation_warnings   //! But since this clears the HTTP connection from the Request object,   //! it can also be used to reuse a @[Request] object.    void destroy()    {    if (con) return_connection(url_requested,con);    con=0;    } -  + #pragma deprecation_warnings      //! @[_destruct] is called when an object is destructed.    protected void _destruct()    {    destroy();    }      // ----------------    -  string _sprintf(int t) +  protected string _sprintf(int t)    {    if (t=='O')    return sprintf("Request(%O",(string)url_requested)+    (!con?" - no connection"    :((con->con?" - connected":"")+    (!con->ok?" - failed"    :" - "+(sizeof(con->buf)+" bytes received"))))+    ")";    }   }
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:412:   class Cookie   {    string key="?";    string data="?";    string site="?";    int expires=-1;    string path="/";    string domain="";    int secure=0;    -  string _sprintf(int t) +  protected string _sprintf(int t)    {    if (t=='O')    return sprintf(    "Cookie(%O: %O=%O; expires=%s; path=%O; domain=%O; secure=%d)",    site,    key,data,    RUNTIME_RESOLV(Calendar.ISO.Second)(expires)->format_http(),    path,domain,secure);    }   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:608:   //! (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. <2 means no reuse at all.   int maximum_connection_reuse=1000000;      // internal (but readable for debug purposes)   mapping(string:array(KeptConnection)) connection_cache=([]); + Thread.Mutex connection_cache_mux = Thread.Mutex();   int connections_kept_n=0;   int connections_inuse_n=0;   mapping(string:int) connections_host_n=([]);      protected class KeptConnection   {    string lookup;    Query q;    -  void create(string _lookup,Query _q) +  protected void create(string _lookup,Query _q)    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    lookup=_lookup;    q=_q;       call_out(disconnect,time_to_keep_unused_connections);    connection_cache[lookup]=    (connection_cache[lookup]||({}))+({this});    connections_kept_n++;    }       void disconnect()    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    connection_cache[lookup]-=({this});    if (!sizeof(connection_cache[lookup]))    m_delete(connection_cache,lookup);    remove_call_out(disconnect); // if called externally       if (q->con) destruct(q->con);    connections_kept_n--;    if (!--connections_host_n[lookup])    m_delete(connections_host_n,lookup);    destruct(q);    destruct(this);    }       Query use()    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    connection_cache[lookup]-=({this});    if (!sizeof(connection_cache[lookup]))    m_delete(connection_cache,lookup);    remove_call_out(disconnect);       connections_kept_n--;    return q; // subsequently, this object is removed (no refs)    }   }   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:666:   {    return url->scheme+"://"+url->host+":"+url->port;   }      //! Request a @[Query] object suitable to use for the   //! given URL. This may be a reused object from a keep-alive   //! connection.   Query give_me_connection(Standards.URI url)   {    Query q; +  Query old_q;    -  +  Thread.MutexKey key = connection_cache_mux->lock(); +     if (array(KeptConnection) v =    connection_cache[connection_lookup(url)])    { -  q=v[0]->use(); // removes itself -  // clean up -  q->buf=""; -  q->headerbuf=""; -  q->n_used++; +  old_q = v[0]->use(); // removes itself    } -  +  +  q = SessionQuery(); +  q->hostname_cache=hostname_cache; +  if (old_q) { +  // Transfer connection from the old Query object to the new. +  foreach(({ "con", "host", "port", + #if constant(SSL.Cipher) +  "https", "context", "ssl_session", + #endif +  }), string field) { +  q[field] = old_q[field]; +  } +  q->n_used = old_q->n_used+1; +  old_q->con = 0; +  destruct(old_q); +  }    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=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      // queue of what to call when we get new free connections
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:1002:   class SessionURL   {    inherit Standards.URI;      //! the referer to this URL    URL referer;      //! instantiate a SessionURL object;   //! when fed to Protocols.HTTP.Session calls, will add   //! referer to the HTTP handshaking variables -  void create(URL uri, +  protected 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;   }