To contents

14.25.1 Protocols.HTTP.Query

CLASS
Protocols.HTTP.Query

DESCRIPTION
Open and execute a HTTP query.

METHOD
Protocols.HTTP.Query.set_callbacks,
Protocols.HTTP.Query.async_request

SYNTAX
object set_callbacks(function request_ok, function request_fail, mixed ...extra)
object async_request(string server, int port, string query);
object async_request(string server, int port, string query, mapping headers, void|string data);

DESCRIPTION
Setup and run an asynchronous request, otherwise similar to thread_request.

request_ok(object httpquery,...extra args) will be called when connection is complete, and headers are parsed.

request_fail(object httpquery,...extra args) is called if the connection fails.

variable int ok Tells if the connection is successfull. variable int errno Errno copied from the connection.

variable mapping headers Headers as a mapping. All header names are in lower case, for convinience.

variable string protocol Protocol string, ie "HTTP/1.0".

variable int status variable string status_desc Status number and description (ie, 200 and "ok").

variable mapping hostname_cache Set this to a global mapping if you want to use a cache, prior of calling *request().

variable mapping async_dns Set this to an array of Protocols.DNS.async_clients, if you wish to limit the number of outstanding DNS requests. Example: async_dns=allocate(20,Protocols.DNS.async_client)();

RETURNS
the called object

METHOD
Protocols.HTTP.Query.cast

SYNTAX
array cast("array")

DESCRIPTION
Gives back ({mapping headers,string data, string protocol,int status,string status_desc});

METHOD
Protocols.HTTP.Query.cast

SYNTAX
mapping cast("mapping")

DESCRIPTION
Gives back headers | (["protocol":protocol, "status":status number, "status_desc":status description, "data":data]);

METHOD
Protocols.HTTP.Query.cast

SYNTAX
string cast("string")

DESCRIPTION
Gives back the answer as a string.

METHOD
Protocols.HTTP.Query.data

SYNTAX
string data()

DESCRIPTION
Gives back the data as a string.

METHOD
Protocols.HTTP.Query.downloaded_bytes

SYNTAX
int downloaded_bytes()

DESCRIPTION
Gives back the number of downloaded bytes.

METHOD
Protocols.HTTP.Query.thread_request

SYNTAX
object thread_request(string server, int port, string query);
object thread_request(string server, int port, string query, mapping headers, void|string data);

DESCRIPTION
Create a new query object and begin the query.

The query is executed in a background thread; call '() in this object to wait for the request to complete.

'query' is the first line sent to the HTTP server; for instance "GET /index.html HTTP/1.1".

headers will be encoded and sent after the first line, and data will be sent after the headers.

RETURNS
the called object

METHOD
Protocols.HTTP.Query.total_bytes

SYNTAX
int total_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.

object(pseudofile) file() object(pseudofile) file(mapping newheaders,void|mapping removeheaders) object(pseudofile) datafile(); Gives back a pseudo-file object, with the method read() and close(). This could be used to copy the file to disc at a proper tempo.

datafile() doesn't give the complete request, just the data.

newheaders, removeheaders is applied as: (oldheaders|newheaders))-removeheaders Make sure all new and remove-header indices are lower case.

void async_fetch(function done_callback); Fetch all data in background.

METHOD
Protocols.HTTP.Query.`

SYNTAX
int `()()

DESCRIPTION
Wait for connection to complete.

RETURNS
1 on successfull connection, 0 if failed

To contents