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

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:1:   #pike __REAL_VERSION__    - //! module Protocols - //! submodule HTTP - //! method object(Protocols.HTTP.Query) get_url(string|Standards.URI url) - //! method object(Protocols.HTTP.Query) get_url(string|Standards.URI url,mapping query_variables) - //! method object(Protocols.HTTP.Query) get_url(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method object(Protocols.HTTP.Query) get_url(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! Sends a HTTP GET request to the server in the URL - //! and returns the created and initialized <ref>Query</ref> object. - //! 0 is returned upon failure. If a query object having - //! request_headers->Connection=="Keep-Alive" from a previous request is - //! provided and the already established server connection can be used for - //! the next request, you may gain some performance. - //! - //! method object(Protocols.HTTP.Query) put_url(string|Standards.URI url) - //! method object(Protocols.HTTP.Query) put_url(string|Standards.URI url,string file) - //! method object(Protocols.HTTP.Query) put_url(string|Standards.URI url,string file,mapping query_variables) - //! method object(Protocols.HTTP.Query) put_url(string|Standards.URI url,string file,mapping query_variables,mapping request_headers) - //! method object(Protocols.HTTP.Query) put_url(string|Standards.URI url,string file,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! Sends a HTTP PUT request to the server in the URL - //! and returns the created and initialized <ref>Query</ref> object. - //! 0 is returned upon failure. If a query object having - //! request_headers->Connection=="Keep-Alive" from a previous request is - //! provided and the already established server connection can be used for - //! the next request, you may gain some performance. - //! - //! method object(Protocols.HTTP.Query) delete_url(string|Standards.URI url) - //! method object(Protocols.HTTP.Query) delete_url(string|Standards.URI url,mapping query_variables) - //! method object(Protocols.HTTP.Query) delete_url(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method object(Protocols.HTTP.Query) delete_url(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! Sends a HTTP DELETE request to the server in the URL - //! and returns the created and initialized <ref>Query</ref> object. - //! 0 is returned upon failure. If a query object having - //! request_headers->Connection=="Keep-Alive" from a previous request is - //! provided and the already established server connection can be used for - //! the next request, you may gain some performance. - //! - //! method array(string) get_url_nice(string|Standards.URI url,mapping query_variables) - //! method array(string) get_url_nice(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method array(string) get_url_nice(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! method string get_url_data(string|Standards.URI url,mapping query_variables) - //! method string get_url_data(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method string get_url_data(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! Returns an array of ({content_type,data}) and just the data - //! string respective, - //! after calling the requested server for the information. - //! 0 is returned upon failure. - //! - //! - //! method array(string) post_url_nice(string|Standards.URI url,mapping query_variables) - //! method array(string) post_url_nice(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method array(string) post_url_nice(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! method string post_url_data(string|Standards.URI url,mapping query_variables) - //! method string post_url_data(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method string post_url_data(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! method object(Protocols.HTTP.Query) post_url(string|Standards.URI url,mapping query_variables) - //! method object(Protocols.HTTP.Query) post_url(string|Standards.URI url,mapping query_variables,mapping request_headers) - //! method object(Protocols.HTTP.Query) post_url(string|Standards.URI url,mapping query_variables,mapping request_headers,object(Protocols.HTTP.Query) query) - //! Similar to the <ref>get_url</ref> class of functions, except that the - //! query variables is sent as a post request instead of a get. - //! -  +    object do_method(string method,    string|Standards.URI url,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con, void|string data)   {    if(!con) {    con = Protocols.HTTP.Query();    }    if(!request_headers)
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:116:    if(path=="") path="/";       con->sync_request(url->host,url->port,    method+" "+path+(query?("?"+query):"")+" HTTP/1.0",    request_headers, data);       if (!con->ok) return 0;    return con;   }    + //! @decl Protocols.HTTP.Query get_url(string|Standards.URI url) + //! @decl Protocols.HTTP.Query get_url(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl Protocols.HTTP.Query get_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl Protocols.HTTP.Query get_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! Sends a HTTP GET request to the server in the URL + //! and returns the created and initialized @[Query] object. + //! 0 is returned upon failure. If a query object having + //! @tt{request_headers->Connection=="Keep-Alive"@} from a previous + //! request is provided and the already established server connection + //! can be used for the next request, you may gain some performance. + //!   object get_url(string|Standards.URI url,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    return do_method("GET", url, query_variables, request_headers, con);   }    -  + //! @decl Protocols.HTTP.Query put_url(string|Standards.URI url) + //! @decl Protocols.HTTP.Query put_url(string|Standards.URI url,string file) + //! @decl Protocols.HTTP.Query put_url(string|Standards.URI url,string file, @ + //! mapping query_variables) + //! @decl Protocols.HTTP.Query put_url(string|Standards.URI url,string file, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl Protocols.HTTP.Query put_url(string|Standards.URI url,string file, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! Sends a HTTP PUT request to the server in the URL + //! and returns the created and initialized @[Query] object. + //! 0 is returned upon failure. If a query object having + //! @tt{request_headers->Connection=="Keep-Alive"@} from a previous + //! request is provided and the already established server connection + //! can be used for the next request, you may gain some performance. + //!   object put_url(string|Standards.URI url,    void|string file,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    return do_method("PUT", url, query_variables, request_headers, con);   }    -  + //! @decl Protocols.HTTP.Query delete_url(string|Standards.URI url) + //! @decl Protocols.HTTP.Query delete_url(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl Protocols.HTTP.Query delete_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl Protocols.HTTP.Query delete_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! Sends a HTTP DELETE request to the server in the URL + //! and returns the created and initialized @[Query] object. + //! 0 is returned upon failure. If a query object having + //! @tt{request_headers->Connection=="Keep-Alive"@} from a previous + //! request is provided and the already established server connection + //! can be used for the next request, you may gain some performance. + //!   object delete_url(string|Standards.URI url,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    return do_method("DELETE", url, query_variables, request_headers, con);   }    -  + //! @decl array(string) get_url_nice(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl array(string) get_url_nice(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl array(string) get_url_nice(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! @decl string get_url_data(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl string get_url_data(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl string get_url_data(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! object(Protocols.HTTP.Query) query) + //! Returns an array of @tt{({content_type,data})@} and just the data + //! string respective, + //! after calling the requested server for the information. + //! 0 is returned upon failure. + //! +    array(string) get_url_nice(string|Standards.URI url,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    object c = get_url(url, query_variables, request_headers, con);    return c && ({ c->headers["content-type"], c->data() });   }      string get_url_data(string|Standards.URI url,    void|mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    object z = get_url(url, query_variables, request_headers, con);    return z && z->data();   }    -  + //! @decl array(string) post_url_nice(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl array(string) post_url_nice(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl array(string) post_url_nice(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! @decl string post_url_data(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl string post_url_data(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl string post_url_data(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! @decl object(Protocols.HTTP.Query) post_url(string|Standards.URI url, @ + //! mapping query_variables) + //! @decl object(Protocols.HTTP.Query) post_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers) + //! @decl object(Protocols.HTTP.Query) post_url(string|Standards.URI url, @ + //! mapping query_variables, @ + //! mapping request_headers, @ + //! Protocols.HTTP.Query query) + //! Similar to the @[get_url()] class of functions, except that the + //! query variables is sent as a POST request instead of as a GET. + //! +    object post_url(string|Standards.URI url,    mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    return do_method("POST", url, 0,    (request_headers||([]))|    (["content-type":    "application/x-www-form-urlencoded"]),    con,
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:190:      string post_url_data(string|Standards.URI url,    mapping query_variables,    void|mapping request_headers,    void|Protocols.HTTP.Query con)   {    object z = post_url(url, query_variables, request_headers, con);    return z && z->data();   }    - //! - //! method string unentity(string s) +    //! Helper function for replacing HTML entities   //! with the corresponding iso-8859-1 characters. - //! note: - //! All characters isn't replaced, only those with + //! @note + //! All characters aren't replaced, only those with   //! corresponding iso-8859-1 characters. -  +    string unentity(string s)   {    return replace(    s,       ({"&AElig;", "&Aacute;", "&Acirc;", "&Agrave;", "&Aring;", "&Atilde;",    "&Auml;", "&Ccedil;", "&ETH;", "&Eacute;", "&Ecirc;", "&Egrave;",    "&Euml;", "&Iacute;", "&Icirc;", "&Igrave;", "&Iuml;", "&Ntilde;",    "&Oacute;", "&Ocirc;", "&Ograve;", "&Oslash;", "&Otilde;", "&Ouml;",    "&THORN;", "&Uacute;", "&Ucirc;", "&Ugrave;", "&Uuml;", "&Yacute;",
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:240:    "!", "½", "¼", "¾", "&frac18;", "&frac38;", "&frac58;",    "&frac78;", ">", ">", "&half;", "&hyphen;", "í", "î", "¡", "ì", "¿",    "ï", "«", "(", "&lsqb;", "<", "<", "&mdash;", "µ", "·", "",    "&ndash;", "¬", "ñ", "ó", "ô", "ò", "ø", "õ", "ö", "¶", "%",    ".", "+", "±", "£", "?", "\"", "»", "®", ")",    "&rsqb;", "§", "&semi;", "­", "¹", "²", "³", "ß", "þ", "~",    "&trade;", "ú", "û", "ù", "ü", "ý", "¥", "ÿ", "&verbar;", "&", }),    );   }    - //! method string http_encode_query(mapping variables) +    //! Encodes a query mapping to a string;   //! this protects odd - in http perspective - characters   //! like '&' and '#' and control characters,   //! and packs the result together in a HTTP query string.   //!   //! Example: - //! <pre> - //! &gt; Protocols.HTTP.http_encode_query( (["anna":"eva","lilith":"blue"]) ); + //! @pre{ + //! > Protocols.HTTP.http_encode_query( (["anna":"eva","lilith":"blue"]) );   //! Result: "lilith=blue&anna=eva" - //! &gt; Protocols.HTTP.http_encode_query( (["&amp;":"&","'=\"":"\0\0\0"]) ); + //! > Protocols.HTTP.http_encode_query( (["&amp;":"&","'=\"":"\0\0\0"]) );   //! Result: "%26amp%3b=%26&%27%3d%22=%00%00%00" - //! </pre> -  -  + //! @}   string http_encode_query(mapping(string:int|string) variables)   {    return Array.map((array)variables,    lambda(array(string|int) v)    {    if (intp(v[1]))    return http_encode_string(v[0]);    return http_encode_string(v[0])+"="+    http_encode_string(v[1]);    })*"&";   }    - //! method string http_encode_string(string in) - //! This protects all odd - see <ref>http_encode_query</ref> - + //! This protects all odd - see @[http_encode_query()] -   //! characters for transfer in HTTP.   //!   //! Do not use this function to protect URLs, since - //! it will protect URL characters like '/' and '?'. -  - string http_encode_string(string f) + //! it will protect URL characters like @tt{'/'@} and @tt{'?'@}. + string http_encode_string(string in)   {    return replace( -  f, +  in,    ({ "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",    "\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",    "\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",    "\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",    "\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207",    "\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",    "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",    "\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237",    " ", "%", "'", "\"", "+", "&", "=", "/",    "#", ";", "\\", "<", ">" }),