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__      import Protocols.HTTP;    + //! A URL which is either a string a @[Standards.URI] or a @[SessionURL].   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.   //!   //! Default is 20 redirects. A negative number will mean infinity.   //! @bugs   //! Loops will currently not be detected, only the limit   //! works to stop loops.   //! @seealso   //! @[Request.follow_redirects]   int follow_redirects=20;    -  + #define RUNTIME_RESOLV(X) master()->resolv(#X) +    //! Default HTTP headers.   mapping default_headers = ([    "user-agent":"Mozilla/5.0 (compatible; MSIE 6.0; Pike HTTP client)"    " Pike/"+__REAL_MAJOR__+"."+__REAL_MINOR__+"."+__REAL_BUILD__,   ]);      //! Request   class Request   {   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:67:    string method,    URL url,    void|mapping query_variables,    void|mapping extra_headers,    void|string data)    {    if(stringp(url))    url=Standards.URI(url);    url_requested=url;    - #if constant(SSL.sslfile) + #if constant(SSL.File)    if(url->scheme!="http" && url->scheme!="https")    error("Protocols.HTTP can't handle %O or any other "    "protocols than HTTP or HTTPS\n",    url->scheme);       if(!con) con=give_me_connection(url_requested);    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 + #endif /* constant(SSL.File) */    mapping request_headers = copy_value(default_headers);    if (url->referer)    request_headers->referer=(string)url->referer;       if(url->user || url->password)    request_headers->authorization = "Basic "    + MIME.encode_base64((url->user || "") + ":" + -  (url->password || "")); +  (url->password || ""), 1);       request_headers->connection=    (time_to_keep_unused_connections<=0)?"Close":"Keep-Alive";       request_headers->host=url->host;    -  +  if (url->scheme == "http" && url->port != 80) { +  request_headers->host += ":" + url->port; +  } +  else if (url->scheme == "https" && url->port != 443) { +  request_headers->host += ":" + url->port; +  } +     if (extra_headers)    request_headers|=extra_headers;       array v=get_cookies(url_requested);    if (v && sizeof(v))    if (request_headers->cookie)    request_headers->cookie+="; "+v*"; ";    else    request_headers->cookie=v*"; ";   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:355:    void check_for_cookies()    {    if (!con->ok || !con->headers || !cookie_encountered) return;       foreach (con->headers["set-cookie"]||({});;string cookie)    cookie_encountered(cookie,url_requested);    }      // ----------------    - //! @[destroy] is called when an object is destructed. +    //! 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;    }    -  + //! @[_destruct] is called when an object is destructed. +  protected void _destruct() +  { +  destroy(); +  } +    // ----------------       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:404:    string domain="";    int secure=0;       string _sprintf(int t)    {    if (t=='O')    return sprintf(    "Cookie(%O: %O=%O; expires=%s; path=%O; domain=%O; secure=%d)",    site,    key,data, -  Calendar.ISO.Second(expires)->format_http(), +  RUNTIME_RESOLV(Calendar.ISO.Second)(expires)->format_http(),    path,domain,secure);    }       void from_http(string s,Standards.URI at)    {    array v=array_sscanf(s,"%{%s=%[^;]%*[; ]%}%s");       site=at->host+":"+at->port;       if (sizeof(v)>=2 && lower_case(v[1])=="secure")    secure=1;       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": -  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(); +  case "expires": { +  object tmp = +  (RUNTIME_RESOLV(Calendar.ISO.parse)("%e, %D %M %Y %h:%m:%s %z",value)|| +  RUNTIME_RESOLV(Calendar.ISO.parse)("%e, %D-%M-%y %h:%m:%s %z",value) ); +  /* Some servers send malformed expiry dates. +  * We treat those as if no expiry date had been set */ +  if (tmp) expires=tmp->unix_time();    break; -  +  }    case "path":    path=value;    break;       case "domain":    domain=value;    break;    }    }