14. Protocols
14.1. HTTP
Module Protocols.HTTP
- Constant
response_codes
constantProtocols.HTTP.response_codes- Description
Mapping from
StatusCodeto descriptive string.- See also
StatusCode
- Method
delete_url
.Querydelete_url(string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Sends a HTTP DELETE request to the server in the URL and returns the created and initialized
Queryobject.0is returned upon failure. If a query object havingrequest_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
do_async_method
voiddo_async_method(stringmethod,string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,Protocols.HTTP.Querycon,void|stringdata)- Description
Low level asynchronous HTTP call method.
- Parameter
method The HTTP method to use, e.g.
"GET".- Parameter
url The URL to perform
methodon. Should be a complete URL, including protocol, e.g."https://pike.lysator.liu.se/".- Parameter
query_variables Calls
http_encode_queryand appends the result to the URL.- Parameter
request_headers The HTTP headers to be added to the request. By default the headers User-agent, Host and, if needed by the url, Authorization will be added, with generated contents. Providing these headers will override the default. Setting the value to 0 will remove that header from the request.
- Parameter
con Previously initialized connection object. In particular the callbacks must have been set (
Query.set_callbacks()).- Parameter
data Data payload to be transmitted in the request.
- See also
do_method(),Query.set_callbacks()
- Method
do_async_proxied_method
voiddo_async_proxied_method(string|Standards.URIproxy,stringuser,stringpassword,stringmethod,string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,Protocols.HTTP.Querycon,void|stringdata)- Description
Low level asynchronous proxied HTTP call method.
Makes an HTTP request through a proxy.
- Parameter
proxy URL for the proxy.
- Parameter
user - Parameter
password Proxy authentication credentials.
- Parameter
method The HTTP method to use, e.g.
"GET".- Parameter
url The URL to perform
methodon. Should be a complete URL, including protocol, e.g."https://pike.lysator.liu.se/".- Parameter
query_variables Calls
http_encode_queryand appends the result to the URL.- Parameter
request_headers The HTTP headers to be added to the request. By default the headers User-agent, Host and, if needed by the url, Authorization will be added, with generated contents. Providing these headers will override the default. Setting the value to 0 will remove that header from the request.
- Parameter
con Previously initialized connection object. In particular the callbacks must have been set (
Query.set_callbacks()).- Parameter
data Data payload to be transmitted in the request.
- See also
do_async_method(),do_proxied_method(),Query.set_callbacks()
- Method
do_method
.Query|zerodo_method(stringmethod,string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon,void|stringdata)- Description
Low level HTTP call method.
- Parameter
method The HTTP method to use, e.g.
"GET".- Parameter
url The URL to perform
methodon. Should be a complete URL, including protocol, e.g."https://pike.lysator.liu.se/".- Parameter
query_variables Calls
http_encode_queryand appends the result to the URL.- Parameter
request_headers The HTTP headers to be added to the request. By default the headers User-agent, Host and, if needed by the url, Authorization will be added, with generated contents. Providing these headers will override the default. Setting the value to 0 will remove that header from the request.
- Parameter
con Old connection object.
- Parameter
data Data payload to be transmitted in the request.
- See also
do_async_method()
- Method
do_proxied_method
.Querydo_proxied_method(string|Standards.URIproxy,stringuser,stringpassword,stringmethod,string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon,void|stringdata)- Description
Makes an HTTP request through a proxy.
- Parameter
proxy URL for the proxy.
- Parameter
user - Parameter
password Proxy authentication credentials.
- Parameter
method - Parameter
url - Parameter
query_variables - Parameter
request_headers - Parameter
con - Parameter
data The remaining arguments are identical to
do_method().- See also
do_method(),do_async_proxied_method()
- Method
get_url
.Queryget_url(string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Sends a HTTP GET request to the server in the URL and returns the created and initialized
Queryobject.0is returned upon failure. If a query object havingrequest_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
get_url_data
stringget_url_data(string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Returns the returned data after calling the requested server for information through HTTP GET.
0is returned upon failure. Redirects (HTTP 302) are automatically followed.
- Method
get_url_nice
array(string)|zeroget_url_nice(string|Standards.URIurl,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Returns an array of
({content_type, data})after calling the requested server for the information.0is returned upon failure. Redirects (HTTP 302) are automatically followed.
- Method
http_encode_query
stringhttp_encode_query(mapping(string:int|string|array(string))variables)- Description
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:
> Protocols.HTTP.http_encode_query( (["anna":"eva","lilith":"blue"]) ); Result: "lilith=blue&anna=eva" > Protocols.HTTP.http_encode_query( (["&":"&","'=\"":"\0\0\0\u0434"]) ); Result: "%27%3D%22=%00%00%00%D0%B4&%26amp%3B=%26"
- Method
iri_encode
stringiri_encode(strings)- Description
Encodes the given string using %XX encoding to be used as a component part in an IRI (Internationalized Resource Identifier, see RFC 3987). This means that all chars outside the IRI iunreserved set are encoded, i.e. this function encodes equivalently to
uri_encodeexcept that all 8-bit and wider characters are left as-is.- Bugs
This function currently does not encode chars in the Unicode private ranges, although that is strictly speaking required in some but not all IRI components. That could change if it turns out to be a problem.
- See also
percent_decode,uri_encode
- Method
percent_decode
stringpercent_decode(strings)- Description
Decodes URI-style %XX encoded chars in the given string.
- See also
percent_encode,uri_decode- Bugs
This function currently does not accept wide string input, which is necessary to work as the reverse of
iri_encode.
- Method
percent_encode
stringpercent_encode(strings)- Description
Encodes the given string using %XX encoding, except that URI unreserved chars are not encoded. The unreserved chars are A-Z, a-z, 0-9, -, ., _, and ~ (see RFC 2396 section 2.3).
8-bit chars are encoded straight, and wider chars are not allowed. That means this encoding is applicable if
sis a binary octet string. If it is a character string thenuri_encodeshould be used instead.It is also slightly faster than
uri_encodeifsis known to contain only US-ASCII.
- Method
post_url
.Querypost_url(string|Standards.URIurl,mapping(string:int|string|array(string))|stringquery_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Similar to
get_url, except that query variables is sent as a POST request instead of a GET request. If query_variables is a simple string, it is assumed to contain the verbatim body of the POST request; Content-Type must be properly specified manually, in this case.
- Method
post_url_data
stringpost_url_data(string|Standards.URIurl,mapping(string:int|string|array(string))|stringquery_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Similar to
get_url_data, except that query variables is sent as a POST request instead of a GET request.
- Method
post_url_nice
array(string) post_url_nice(string|Standards.URIurl,mapping(string:int|string|array(string))|stringquery_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Similar to
get_url_nice, except that query variables is sent as a POST request instead of a GET request.
- Method
put_url
.Queryput_url(string|Standards.URIurl,void|stringfile,void|mapping(string:int|string|array(string))query_variables,void|mapping(string:string|array(string)|int)request_headers,void|Protocols.HTTP.Querycon)- Description
Sends a HTTP PUT request to the server in the URL and returns the created and initialized
Queryobject.0is returned upon failure. If a query object havingrequest_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
quoted_string_decode
stringquoted_string_decode(strings)- Description
Decodes the given string which has been encoded as a quoted-string according to RFC 2616 section 2.2.
sis assumed to not include the surrounding " chars.- See also
quoted_string_encode
- Method
quoted_string_encode
stringquoted_string_encode(strings)- Description
Encodes the given string quoted to be used as content inside a quoted-string according to RFC 2616 section 2.2. The returned string does not include the surrounding " chars.
- Note
The quoted-string quoting rules in RFC 2616 have several problems:
Quoting is inconsistent since " is quoted as \", but \ does not need to be quoted. This is resolved in the HTTP bis update to mandate quoting of \ too, which this function performs.
Many characters are not quoted sufficiently to make the result safe to use in an HTTP header, so this quoting is not enough if
scontains NUL, CR, LF, or any 8-bit or wider character.
- See also
quoted_string_decode
- Method
uri_decode
stringuri_decode(strings)- Description
Decodes URI-style %XX encoded chars in the given string, and then UTF-8 decodes the result. This is the reverse of
uri_encodeanduri_encode_invalids.- See also
uri_encode,uri_encode_invalids
- Method
uri_encode
stringuri_encode(strings)- Description
Encodes the given string using %XX encoding to be used as a component part in a URI. This means that all URI reserved and excluded characters are encoded, i.e. everything except A-Z, a-z, 0-9, -, ., _, and ~ (see RFC 2396 section 2.3).
8-bit chars and wider are encoded using UTF-8 followed by percent-encoding. This follows RFC 3986 section 2.5, the IRI-to-URI conversion method in the IRI standard (RFC 3987) and appendix B.2 in the HTML 4.01 standard. It should work regardless of the charset used in the XML document the URI might be inserted into.
- See also
uri_decode,uri_encode_invalids,iri_encode
- Method
uri_encode_invalids
stringuri_encode_invalids(strings)- Description
Encodes all "dangerous" chars in the given string using %XX encoding, so that it can be included as a URI in an HTTP message or header field. This includes control chars, space and various delimiter chars except those in the URI reserved set (RFC 2396 section 2.2).
Since this function doesn't touch the URI reserved chars nor the escape char %, it can be used on a complete formatted URI or IRI.
8-bit chars and wider are encoded using UTF-8 followed by percent-encoding. This follows RFC 3986 section 2.5, the IRI standard (RFC 3987) and appendix B.2 in the HTML 4.01 standard.
- Note
The characters in the URI reserved set are: :, /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;, =. In addition, this function doesn't touch the escape char %.
- See also
uri_decode,uri_encode
Enum Protocols.HTTP.StatusCode
- Description
HTTP Status codes.
- See also
response_codes, https://www.iana.org/assignments/http-status-codes/http-status-codes.txt
- Constant
DAV_ALREADY_REPORTED
constantProtocols.HTTP.DAV_ALREADY_REPORTED- Description
RFC 5842 section 7.1: 208 Already Reported
- Constant
DAV_FAILED_DEP
constantProtocols.HTTP.DAV_FAILED_DEP- Description
RFC 2518 section 10.5: 424 Failed Dependency
- Constant
DAV_LOCKED
constantProtocols.HTTP.DAV_LOCKED- Description
RFC 2518 section 10.4: 423 Locked
- Constant
DAV_LOOP_DETECTED
constantProtocols.HTTP.DAV_LOOP_DETECTED- Description
RFC 5842 section 7.2: 508 Loop Detected
- Constant
DAV_MULTISTATUS
constantProtocols.HTTP.DAV_MULTISTATUS- Description
RFC 2518 section 10.2: 207 Multi-Status
- Constant
DAV_PROCESSING
constantProtocols.HTTP.DAV_PROCESSING- Description
RFC 2518 section 10.1: 102 Processing
- Constant
DAV_STORAGE_FULL
constantProtocols.HTTP.DAV_STORAGE_FULL- Description
RFC 2518 section 10.6: 507 Insufficient Storage
- Constant
DAV_UNPROCESSABLE
constantProtocols.HTTP.DAV_UNPROCESSABLE- Description
RFC 2518 section 10.3: 422 Unprocessable Entry
- Constant
DELTA_HTTP_IM_USED
constantProtocols.HTTP.DELTA_HTTP_IM_USED- Description
RFC 3229 section 10.4.1: 226 IM Used
- Constant
HTCPCP_TEAPOT
constantProtocols.HTTP.HTCPCP_TEAPOT- Description
RFC 2324 section 2.3.2: 418 I'm a teapot
- Constant
HTTP_ACCEPTED
constantProtocols.HTTP.HTTP_ACCEPTED- Description
RFC 2616 section 10.2.3: 202 Accepted
- Constant
HTTP_BAD
constantProtocols.HTTP.HTTP_BAD- Description
RFC 2616 section 10.4.1: 400 Bad Request
- Constant
HTTP_BAD_GW
constantProtocols.HTTP.HTTP_BAD_GW- Description
RFC 2616 section 10.5.3: 502 Bad Gateway
- Constant
HTTP_BAD_RANGE
constantProtocols.HTTP.HTTP_BAD_RANGE- Description
RFC 2616 section 10.4.17: 416 Requested Range Not Satisfiable
- Constant
HTTP_CONFLICT
constantProtocols.HTTP.HTTP_CONFLICT- Description
RFC 2616 section 10.4.10: 409 Conflict
- Constant
HTTP_CONTINUE
constantProtocols.HTTP.HTTP_CONTINUE- Description
RFC 2616 section 10.1.1: 100 Continue
- Constant
HTTP_CREATED
constantProtocols.HTTP.HTTP_CREATED- Description
RFC 2616 section 10.2.2: 201 Created
- Constant
HTTP_EARLY_HINTS
constantProtocols.HTTP.HTTP_EARLY_HINTS- Description
RFC 8297 section 2: 103 Early Hints
- Constant
HTTP_EXPECT_FAILED
constantProtocols.HTTP.HTTP_EXPECT_FAILED- Description
RFC 2616 section 10.4.18: 417 Expectation Failed
- Constant
HTTP_FORBIDDEN
constantProtocols.HTTP.HTTP_FORBIDDEN- Description
RFC 2616 section 10.4.4: 403 Forbidden
- Constant
HTTP_FOUND
constantProtocols.HTTP.HTTP_FOUND- Description
RFC 2616 section 10.3.3: 302 Found
- Constant
HTTP_GONE
constantProtocols.HTTP.HTTP_GONE- Description
RFC 2616 section 10.4.11: 410 Gone
- Constant
HTTP_GW_TIMEOUT
constantProtocols.HTTP.HTTP_GW_TIMEOUT- Description
RFC 2616 section 10.5.5: 504 Gateway Timeout
- Constant
HTTP_HEADERS_TOO_LARGE
constantProtocols.HTTP.HTTP_HEADERS_TOO_LARGE- Description
RFC 6585 section 5: 431 Request Header Fields Too Large
- Constant
HTTP_INTERNAL_ERR
constantProtocols.HTTP.HTTP_INTERNAL_ERR- Description
RFC 2616 section 10.5.1: 500 Internal Server Error
- Constant
HTTP_LEGALLY_RESTRICTED
constantProtocols.HTTP.HTTP_LEGALLY_RESTRICTED- Description
RFC 7725 section 3: 451 Unavailable For Legal Reasons
- Constant
HTTP_LENGTH_REQ
constantProtocols.HTTP.HTTP_LENGTH_REQ- Description
RFC 2616 section 10.4.12: 411 Length Required
- Constant
HTTP_METHOD_INVALID
constantProtocols.HTTP.HTTP_METHOD_INVALID- Description
RFC 2616 section 10.4.6: 405 Method Not Allowed
- Constant
HTTP_MISDIRECTED_REQ
constantProtocols.HTTP.HTTP_MISDIRECTED_REQ- Description
RFC 7540 section 9.1.2: 421 Misdirected Request
- Constant
HTTP_MOVED_PERM
constantProtocols.HTTP.HTTP_MOVED_PERM- Description
RFC 2616 section 10.3.2: 301 Moved Permanently
- Constant
HTTP_MULTIPLE
constantProtocols.HTTP.HTTP_MULTIPLE- Description
RFC 2616 section 10.3.1: 300 Multiple Choices
- Constant
HTTP_NET_AUTH_REQUIRED
constantProtocols.HTTP.HTTP_NET_AUTH_REQUIRED- Description
RFC 6585 section 6: 511 Network Authentication Required
- Constant
HTTP_NONAUTHORATIVE
constantProtocols.HTTP.HTTP_NONAUTHORATIVE- Description
RFC 2616 section 10.2.4: 203 Non-Authorative Information
- Constant
HTTP_NOT_ACCEPTABLE
constantProtocols.HTTP.HTTP_NOT_ACCEPTABLE- Description
RFC 2616 section 10.4.7: 406 Not Acceptable
- Constant
HTTP_NOT_EXTENDED
constantProtocols.HTTP.HTTP_NOT_EXTENDED- Description
RFC 2774 section 7: 510 Not Extended (obsolete)
- Constant
HTTP_NOT_FOUND
constantProtocols.HTTP.HTTP_NOT_FOUND- Description
RFC 2616 section 10.4.5: 404 Not Found
- Constant
HTTP_NOT_IMPL
constantProtocols.HTTP.HTTP_NOT_IMPL- Description
RFC 2616 section 10.5.2: 501 Not Implemented
- Constant
HTTP_NOT_MODIFIED
constantProtocols.HTTP.HTTP_NOT_MODIFIED- Description
RFC 2616 section 10.3.5: 304 Not Modified
- Constant
HTTP_NO_CONTENT
constantProtocols.HTTP.HTTP_NO_CONTENT- Description
RFC 2616 section 10.2.5: 204 No Content
- Constant
HTTP_OK
constantProtocols.HTTP.HTTP_OK- Description
RFC 2616 section 10.2.1: 200 OK
- Constant
HTTP_PARTIAL_CONTENT
constantProtocols.HTTP.HTTP_PARTIAL_CONTENT- Description
RFC 2616 section 10.2.7: 206 Partial Content
- Constant
HTTP_PAY
constantProtocols.HTTP.HTTP_PAY- Description
RFC 2616 section 10.4.3: 402 Payment Required
- Constant
HTTP_PERM_REDIRECT
constantProtocols.HTTP.HTTP_PERM_REDIRECT- Description
RFC 7538 section 3: 308 Permanent Redirect
- Constant
HTTP_PRECOND_FAILED
constantProtocols.HTTP.HTTP_PRECOND_FAILED- Description
RFC 2616 section 10.4.13: 412 Precondition Failed
- Constant
HTTP_PRECOND_REQUIRED
constantProtocols.HTTP.HTTP_PRECOND_REQUIRED- Description
RFC 6585 section 3: 428 Precondition required
- Constant
HTTP_PROXY_AUTH_REQ
constantProtocols.HTTP.HTTP_PROXY_AUTH_REQ- Description
RFC 2616 section 10.4.8: 407 Proxy Authentication Required
- Constant
HTTP_REQ_TOO_LARGE
constantProtocols.HTTP.HTTP_REQ_TOO_LARGE- Description
RFC 2616 section 10.4.14: 413 Request Entity Too Large
- Constant
HTTP_RESET_CONTENT
constantProtocols.HTTP.HTTP_RESET_CONTENT- Description
RFC 2616 section 10.2.6: 205 Reset Content
- Constant
HTTP_SEE_OTHER
constantProtocols.HTTP.HTTP_SEE_OTHER- Description
RFC 2616 section 10.3.4: 303 See Other
- Constant
HTTP_SWITCH_PROT
constantProtocols.HTTP.HTTP_SWITCH_PROT- Description
RFC 2616 section 10.1.2: 101 Switching protocols
- Constant
HTTP_TEMP_REDIRECT
constantProtocols.HTTP.HTTP_TEMP_REDIRECT- Description
RFC 2616 section 10.3.8: 307 Temporary Redirect
- Constant
HTTP_TIMEOUT
constantProtocols.HTTP.HTTP_TIMEOUT- Description
RFC 2616 section 10.4.9: 408 Request Timeout
- Constant
HTTP_TOO_MANY_REQUESTS
constantProtocols.HTTP.HTTP_TOO_MANY_REQUESTS- Description
RFC 6585 section 4: 429 Too Many Requests
- Constant
HTTP_UNAUTH
constantProtocols.HTTP.HTTP_UNAUTH- Description
RFC 2616 section 10.4.2: 401 Unauthorized
- Constant
HTTP_UNAVAIL
constantProtocols.HTTP.HTTP_UNAVAIL- Description
RFC 2616 section 10.5.4: 503 Service Unavailable
- Constant
HTTP_UNSUPP_MEDIA
constantProtocols.HTTP.HTTP_UNSUPP_MEDIA- Description
RFC 2616 section 10.4.16: 415 Unsupported Media Type
- Constant
HTTP_UNSUPP_VERSION
constantProtocols.HTTP.HTTP_UNSUPP_VERSION- Description
RFC 2616 section 10.5.6: 505 HTTP Version Not Supported
- Constant
HTTP_URI_TOO_LONG
constantProtocols.HTTP.HTTP_URI_TOO_LONG- Description
RFC 2616 section 10.4.15: 414 Request-URI Too Long
- Constant
HTTP_USE_PROXY
constantProtocols.HTTP.HTTP_USE_PROXY- Description
RFC 2616 section 10.3.6: 305 Use Proxy
- Constant
TCN_VARIANT_NEGOTIATES
constantProtocols.HTTP.TCN_VARIANT_NEGOTIATES- Description
RFC 2295 section 8.1: 506 Variant Also Negotiates
- Constant
TLS_TOO_EARLY
constantProtocols.HTTP.TLS_TOO_EARLY- Description
RFC 8470 section 5.2: 425 Too Early
- Constant
TLS_UPGRADE_REQUIRED
constantProtocols.HTTP.TLS_UPGRADE_REQUIRED- Description
RFC 2817 section 4.2: 426 Upgrade Required
Class Protocols.HTTP.Query
classProtocols.HTTP.Query- Description
Open and execute an HTTP query.
- Example
HTTP.Query o=HTTP.Query();
void ok() { write("ok...\n"); write("%O\n", o->headers); exit(0); }
void fail() { write("fail\n"); exit(0); }
int main() { o->set_callbacks(ok, fail); o->async_request("pike.lysator.liu.se", 80, "HEAD / HTTP/1.0"); return -1; }
- Variable
buf
Variable headerbuf stringProtocols.HTTP.Query.bufstringProtocols.HTTP.Query.headerbuf- Description
Input buffers.
- Variable
con
Stdio.File|SSL.File|Stdio.UDPProtocols.HTTP.Query.con- Description
Connection to HTTP(s) server.
- Variable
errno
intProtocols.HTTP.Query.errno- Description
Errno copied from the connection or simulated for async operations.
- Note
In Pike 7.8 and earlier hardcoded Linux values were used in async operations, 110 instead of
System.ETIMEDOUTand 113 instead ofSystem.EHOSTUNREACH.
- Variable
request_ok
Variable request_fail
Variable extra_args localfunction(:void)|zeroProtocols.HTTP.Query.request_oklocalfunction(:void)|zeroProtocols.HTTP.Query.request_failarrayProtocols.HTTP.Query.extra_args- Description
Callbacks and arguments set by
set_callbacks().
- Variable
headers
mappingProtocols.HTTP.Query.headers- Description
Headers as a mapping. All header names are in lower case, for convinience.
- Variable
host
Variable real_host
Variable port stringProtocols.HTTP.Query.hoststringProtocols.HTTP.Query.real_hostintProtocols.HTTP.Query.port- Description
Connected host and port.
Used to detect whether keep-alive can be used.
- Variable
hostname_cache
mapping(string:array(string)) Protocols.HTTP.Query.hostname_cache- Description
Set this to a global mapping if you want to use a cache, prior of calling *request().
- Variable
timeout
Variable maxtime intProtocols.HTTP.Query.timeoutintProtocols.HTTP.Query.maxtime- Description
timeoutis the time to wait in seconds on connection and/or data. If data is fetched asynchronously the watchdog will be reset every time data is received. Defaults to 120 seconds.maxtimeis the time the entire operation is allowed to take, no matter if the connection and data fetching is successful. This is by default indefinitely.- Note
These values only have effect in asynchroneous calls
- Variable
status
Variable status_desc intProtocols.HTTP.Query.statusstringProtocols.HTTP.Query.status_desc- Description
Status number and description (eg
200and"ok").
- Method
`()
intres =Protocols.HTTP.Query()()- Description
Wait for connection to complete.
- Returns
Returns
1on successfull connection,0on failure.
- Method
async_fetch
voidasync_fetch(function(:void)callback,mixed...extra)- Description
Fetch all data in background.
- See also
timed_async_fetch(),async_request(),set_callbacks()
- Method
set_callbacks
Method async_request Protocols.HTTP.Queryset_callbacks(function(:void)|zerorequest_ok,function(:void)|zerorequest_fail,mixed...extra)Protocols.HTTP.Queryasync_request(stringserver,intport,stringquery)Protocols.HTTP.Queryasync_request(stringserver,intport,stringquery,mappingheaders,string|voiddata)- Description
Setup and run an asynchronous request, otherwise similar to
thread_request().request_ok(Protocols.HTTP.Query httpquery,...extra args) will be called when connection is complete, and headers are parsed.request_fail(Protocols.HTTP.Query httpquery,...extra args) is called if the connection fails.- Returns
Returns the called object
- Method
cast
(array)Protocols.HTTP.Query()- Returns
Array mapping0Headers
string1Data
string2Protocol
int3Status
string4Status description
- Method
cast
(mapping)Protocols.HTTP.Query()- Returns
The header mapping ORed with the following mapping.
"protocol":stringThe protocol.
"status":intThe status code.
"status_desc":stringThe status description.
"data":stringThe returned data.
- Method
datafile
Protocols.HTTP.Query.PseudoFiledatafile()- Description
Gives back a pseudo-file object, with the methods
read()andclose(). This could be used to copy the file to disc at a proper tempo.datafile()doesn't give the complete request, just the data.- See also
file()
- Method
file
Protocols.HTTP.Query.PseudoFilefile()Protocols.HTTP.Query.PseudoFilefile(mappingnewheaders,void|mappingremoveheaders)- Description
Gives back a pseudo-file object, with the methods
read()andclose(). This could be used to copy the file to disc at a proper tempo.newheaders,removeheadersis applied as:(oldheaders|newheaders))-removeheadersMake sure all new and remove-header indices are lower case.- See also
datafile()
- Method
ponder_answer
protectedintponder_answer(int|voidstart_position)- Description
Attempt to read the result header block from
bufandcon.- Returns
0Returns
0if the header block has not yet been received.1Sets
headerbufto the raw header block andheadersto the parsed header block, calls therequest_okcallback (if any) and returns1on successful read of the header block.- Note
The data part of the result may still be pending on
1return.
- Method
thread_request
Protocols.HTTP.Querythread_request(stringserver,intport,stringquery)Protocols.HTTP.Querythread_request(stringserver,intport,stringquery,mappingheaders,void|stringdata)- Description
Create a new query object and begin the query.
The query is executed in a background thread; call
`()in the object to wait for the request to complete.queryis the first line sent to the HTTP server; for instance"GET /index.html HTTP/1.1".headerswill be encoded and sent after the first line, anddatawill be sent after the headers.- Returns
Returns the called object.
- Method
timed_async_fetch
voidtimed_async_fetch(function(this_program,__unknown__... :void)ok_callback,function(this_program,__unknown__... :void)fail_callback,mixed...extra)- Description
Like
async_fetch(), except with a timeout and a corresponding fail callback function.- See also
async_fetch(),async_request(),set_callbacks()
- Method
total_bytes
inttotal_bytes()- Description
Gives back the size of a file if a content-length header is present and parsed at the time of evaluation. Otherwise returns -1.
- Method
unicode_data
stringunicode_data()- Description
Gives back data, but decoded according to the content-type character set.
- See also
data
Class Protocols.HTTP.Query.PseudoFile
classProtocols.HTTP.Query.PseudoFile- Description
Minimal simulation of a
Stdio.Fileobject.Objects of this class are returned by
file()anddatafile().- Note
Do not attempt further queries using this
Queryobject before having read all data.
Class Protocols.HTTP.Session
classProtocols.HTTP.Session
- Typedef
URL
typedefstring|Standards.URI|SessionURLProtocols.HTTP.Session.URL- Description
A URL which is either a string a
Standards.URIor aSessionURL.
- Variable
default_headers
mappingProtocols.HTTP.Session.default_headers- Description
Default HTTP headers.
- Variable
follow_redirects
intProtocols.HTTP.Session.follow_redirects- Description
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.
- See also
Request.follow_redirects
- Variable
hostname_cache
mappingProtocols.HTTP.Session.hostname_cache- Description
Cache of hostname to IP lookups. Given to and used by the
Queryobjects.
- Variable
maximum_connection_reuse
intProtocols.HTTP.Session.maximum_connection_reuse- Description
Maximum times a connection is reused. Defaults to 1000000. <2 means no reuse at all.
- Variable
maximum_connections_per_server
intProtocols.HTTP.Session.maximum_connections_per_server- Description
Maximum number of connections to the same server. Used only by async requests. Defaults to 10 connections.
- Variable
maximum_total_connections
intProtocols.HTTP.Session.maximum_total_connections- Description
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.
- Variable
time_to_keep_unused_connections
int|floatProtocols.HTTP.Session.time_to_keep_unused_connections- Description
The time to keep unused connections in seconds. Set to zero to never save any kept-alive connections. (Might be good in a for instance totaly synchroneous script that keeps the backend thread busy and never will get call_outs.) Defaults to 10 seconds.
- Method
async_get_url
Method async_put_url
Method async_delete_url
Method async_post_url Requestasync_get_url(URLurl,void|mappingquery_variables,function(:void)|zerocallback_headers_ok,function(:void)|zerocallback_data_ok,function(:void)|zerocallback_fail,mixed...callback_arguments)Requestasync_put_url(URLurl,void|stringfile,void|mappingquery_variables,function(:void)|zerocallback_headers_ok,function(:void)|zerocallback_data_ok,function(:void)|zerocallback_fail,mixed...callback_arguments)Requestasync_delete_url(URLurl,void|mappingquery_variables,function(:void)|zerocallback_headers_ok,function(:void)|zerocallback_data_ok,function(:void)|zerocallback_fail,mixed...callback_arguments)Requestasync_post_url(URLurl,mappingquery_variables,function(:void)|zerocallback_headers_ok,function(:void)|zerocallback_data_ok,function(:void)|zerocallback_fail,mixed...callback_arguments)- Description
Sends a HTTP GET, POST, PUT or DELETE request to the server in the URL asynchroneously, and call the corresponding callbacks when result arrives (or not). The callbacks will receive the created Request object as first argument, then the given
callback_arguments, if any.callback_headers_okis called when the HTTP request has received headers.callback_data_okis called when the HTTP request has been received completely, data and all.callback_failis called when the HTTP request has failed, on a TCP/IP or DNS level, or has received a forced timeout.The created Request object is returned.
- Method
encode_cookies
Method decode_cookies stringencode_cookies()voiddecode_cookies(stringdata,voidno_clear)- Description
Dump all cookies to a string and read them back. This is useful to store cookies in between sessions (on disk, for instance).
decode_cookieswill throw an error upon parse failures. Also note,decode_cookieswill clear out any previously learned cookies from theSessionobject, unless no_clear is given and true.
- Method
get_url
Method post_url
Method put_url
Method delete_url Requestget_url(URLurl,void|mappingquery_variables)Requestpost_url(URLurl,mapping|stringquery_variables)Requestput_url(URLurl,stringfile,void|mappingquery_variables)Requestdelete_url(URLurl,void|mappingquery_variables)- Description
Sends a HTTP GET, POST, PUT or DELETE request to the server in the URL and returns the created and initialized
Requestobject. 0 is returned upon failure.
- Method
get_cookies
array(string) get_cookies(Standards.URI|SessionURLfor_url,void|boolno_delete)- Description
Get the cookies that we should send to this server, for this url. They are presented in the form suitable for HTTP headers (as an array). This will also take in count expiration of cookies, and delete expired cookies from the
Sessionunlessno_deleteis true.
- Method
get_url_nice
Method get_url_data
Method post_url_nice
Method post_url_data array(string) get_url_nice(URLurl,mappingquery_variables)stringget_url_data(URLurl,mappingquery_variables)array(string) post_url_nice(URLurl,mapping|stringquery_variables)stringpost_url_data(URLurl,mapping|stringquery_variables)- Description
Returns an array of
({content_type,data})and just the data string respective, after calling the requested server for the information.0is returned upon failure.post* is similar to the
get_url()class of functions, except that the query variables is sent as a POST request instead of as a GET.
- Constant
response_codes