Scol standard library package
0.3.1
Common and usefull functions for all Scol applications
|
Functions | |
std_httpsrvClose (o) | |
Close a server and its opened conections. All active connections will be closed too. More... | |
std_httpsrvCloseRequest (o, oreq) | |
Close an opened connection request. More... | |
std_httpsrvGetActives (o) | |
Get the current number of active (opened) connections. More... | |
std_httpsrvGetCallback (o) | |
Return the current called function when a request is received. More... | |
std_httpsrvGetCallbackAccept (o) | |
Return the current called function when a connection is accepted. More... | |
std_httpsrvGetHeader (o) | |
Return the current default header for the answers. More... | |
std_httpsrvGetId (o) | |
Get the internal id of a server. More... | |
std_httpsrvGetLogged (o) | |
Return if the operations are (or not) currently logged in the application log file (depending on the Scol settings). More... | |
std_httpsrvGetMaxSizePost (o) | |
Return the current max size for a POST request. More... | |
std_httpsrvGetPort (o) | |
Return the listened port. More... | |
std_httpsrvGetRequest (oreq) | |
Get the full received request. More... | |
std_httpsrvGetRequestClose (oreq) | |
Return the defined callback when a connection is closed. More... | |
std_httpsrvGetRequestHeader (oreq) | |
Get the current defined header for a request object. More... | |
std_httpsrvGetRequestId (oreq) | |
Return the id of a connection. More... | |
std_httpsrvGetRequestIP (oreq) | |
Return the IP address of the client (or its proxy, ...). More... | |
std_httpsrvGetRequestSize (oreq) | |
Return the size of the buffer request. More... | |
std_httpsrvGetStats (o) | |
Returns few stats about this server. More... | |
std_httpsrvGetType (o) | |
Return if the server is synchronous or asynchronous. More... | |
std_httpsrvKeyValue (str, verb) | |
Function to convert a string parameters like a=b&c=d ... to a list key,value. More... | |
std_httpsrvNewAsync (chn, port, cbfun) | |
Create a new asynchronous Simple HTTP server. More... | |
std_httpsrvNewSync (chn, port, cbfun) | |
Create a new synchronous Simple HTTP server. More... | |
std_httpsrvParseRequest (oreq) | |
Parse a received request. More... | |
std_httpsrvRequestBody (oreq) | |
Return the body of a received request object. More... | |
std_httpsrvRequestHeader (oreq) | |
Return the header of a received request object. More... | |
std_httpsrvSend (o, oreq) | |
Send an anwser to a client by an opened connection request. You should set std_httpsrvSetResponseS or std_httpsrvSetResponseP before use this function. More... | |
std_httpsrvSetCallback (o, cbfun) | |
Set the reflex function which is called when a request is received. This callback can be changed as you want. More... | |
std_httpsrvSetCallbackAccept (o, cbfun) | |
Set the reflex function which is called when a connection is accepted. The request object given by the callback doesn't contain the string request yet. This string will be present in the request object in the received callback only. This callback can be changed as you want. More... | |
std_httpsrvSetHeader (o, szDefaultHeader) | |
Set the default header for the answers. More... | |
std_httpsrvSetLogged (o, state) | |
Set if the operations are (or not) currently logged in the application log file (depending on the Scol settings). More... | |
std_httpsrvSetMaxSizePost (o, size) | |
Set the max size for a POST request. More... | |
std_httpsrvSetRequestClose (oreq, cbfun) | |
Set the callback when a connection is closed. More... | |
std_httpsrvSetRequestHeader (oreq, szHeader) | |
Set the header answer of a specific received request. By default, it is the default server header. More... | |
std_httpsrvSetResponseP (oreq, pFile) | |
Set the file to send to a specific received request. The header will be automatically added when the answser is sent. The content file won't loaded in Scol memory. More... | |
std_httpsrvSetResponseS (oreq, szResponse) | |
Set the answer of a specific received request. The header will be automatically added when the answser is sent. More... | |
Package to load : lib/std/httpsrv.pkg
Dependancies :
std_httpsrvNewSync | ( | chn | , |
port | , | ||
cbfun | |||
) |
Create a new synchronous Simple HTTP server.
Prototype : fun [Chn I fun [STD_HTTP_SERVER_REQUEST] S] STD_HTTP_SERVER
Chn | : the channel where the server will be created. Generally, it is the current channel ( _channel ). |
I | : the TCP-IP listen port. By default, it is on 80. |
fun | [STD_HTTP_SERVER_REQUEST] S : each time that a request is received, this function is called. Its argument is a request object. Its API is in this same package. The function must return a string. This string is the response to the client. Don't forget to include a comprehensive header in the answer. |
std_httpsrvNewAsync | ( | chn | , |
port | , | ||
cbfun | |||
) |
Create a new asynchronous Simple HTTP server.
Prototype : fun [Chn I fun [STD_HTTP_SERVER_REQUEST] S] STD_HTTP_SERVER
Chn | : the channel where the server will be created. Generally, it is the current channel ( _channel ). |
I | : the TCP-IP listen port. By default, it is on 80. |
fun | [STD_HTTP_SERVER_REQUEST] S : each time that a request is received, this function is called. Its argument is a request object. Its API is in this same package. The function should return nil. To answser, see in this same API. As the server will be asynchronous, the application send the response and manage the connection manually. |
std_httpsrvClose | ( | o | ) |
Close a server and its opened conections. All active connections will be closed too.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a server object |
std_httpsrvGetType | ( | o | ) |
Return if the server is synchronous or asynchronous.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetPort | ( | o | ) |
Return the listened port.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetLogged | ( | o | ) |
Return if the operations are (or not) currently logged in the application log file (depending on the Scol settings).
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetCallback | ( | o | ) |
Return the current called function when a request is received.
Prototype :fun [STD_HTTP_SERVER] fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetCallbackAccept | ( | o | ) |
Return the current called function when a connection is accepted.
Prototype :fun [STD_HTTP_SERVER] fun [STD_HTTP_SERVER_REQUEST] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetHeader | ( | o | ) |
Return the current default header for the answers.
Prototype :fun [STD_HTTP_SERVER] S
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetMaxSizePost | ( | o | ) |
Return the current max size for a POST request.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetActives | ( | o | ) |
Get the current number of active (opened) connections.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetStats | ( | o | ) |
Returns few stats about this server.
Prototype :fun [STD_HTTP_SERVER] [I I I I]
STD_HTTP_SERVER | : a valid server object |
std_httpsrvGetId | ( | o | ) |
Get the internal id of a server.
Prototype :fun [STD_HTTP_SERVER] I
STD_HTTP_SERVER | : a valid server object |
std_httpsrvSetLogged | ( | o | , |
state | |||
) |
Set if the operations are (or not) currently logged in the application log file (depending on the Scol settings).
Prototype :fun [STD_HTTP_SERVER I] STD_HTTP_SERVER
STD_HTTP_SERVER | : a valid server object |
I | : the new state : 0 (default) or 1. Another value is ignored. |
std_httpsrvSetCallback | ( | o | , |
cbfun | |||
) |
Set the reflex function which is called when a request is received. This callback can be changed as you want.
Prototype :fun [STD_HTTP_SERVER fun [STD_HTTP_SERVER_REQUEST] S] STD_HTTP_SERVER
STD_HTTP_SERVER | : a valid server object |
fun | [STD_HTTP_SERVER_REQUEST] S : the new callback. |
std_httpsrvSetCallbackAccept | ( | o | , |
cbfun | |||
) |
Set the reflex function which is called when a connection is accepted. The request object given by the callback doesn't contain the string request yet. This string will be present in the request object in the received callback only. This callback can be changed as you want.
Prototype :fun [STD_HTTP_SERVER fun [STD_HTTP_SERVER_REQUEST] I] STD_HTTP_SERVER
STD_HTTP_SERVER | : a valid server object |
fun | [STD_HTTP_SERVER_REQUEST] I : the new callback. |
std_httpsrvSetHeader | ( | o | , |
szDefaultHeader | |||
) |
Set the default header for the answers.
Prototype :fun [STD_HTTP_SERVER S] STD_HTTP_SERVER
STD_HTTP_SERVER | : a valid server object |
S | : the new default header. |
std_httpsrvSetMaxSizePost | ( | o | , |
size | |||
) |
Set the max size for a POST request.
Prototype :fun [STD_HTTP_SERVER I] STD_HTTP_SERVER
STD_HTTP_SERVER | : a valid server object |
I | : the new positive size (a negative value will be ignored) |
std_httpsrvGetRequest | ( | oreq | ) |
Get the full received request.
Prototype :fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvGetRequestHeader | ( | oreq | ) |
Get the current defined header for a request object.
Prototype :fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvGetRequestIP | ( | oreq | ) |
Return the IP address of the client (or its proxy, ...).
Prototype :fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvGetRequestSize | ( | oreq | ) |
Return the size of the buffer request.
Prototype :fun [STD_HTTP_SERVER_REQUEST] I
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvGetRequestId | ( | oreq | ) |
Return the id of a connection.
Prototype :fun [STD_HTTP_SERVER_REQUEST] I
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvGetRequestClose | ( | oreq | ) |
Return the defined callback when a connection is closed.
Prototype :fun [STD_HTTP_SERVER_REQUEST] fun [I] I
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvSetRequestClose | ( | oreq | , |
cbfun | |||
) |
Set the callback when a connection is closed.
Prototype :fun [STD_HTTP_SERVER_REQUEST fun [I] I] STD_HTTP_SERVER_REQUEST
STD_HTTP_SERVER_REQUEST | : a valid request object |
fun | [I] I : function to call. Its argument is the id of the connection. |
std_httpsrvSetRequestHeader | ( | oreq | , |
szHeader | |||
) |
Set the header answer of a specific received request. By default, it is the default server header.
Prototype :fun [STD_HTTP_SERVER_REQUEST S] STD_HTTP_SERVER_REQUEST
STD_HTTP_SERVER_REQUEST | : a valid request object |
S | : an header |
std_httpsrvSetResponseS | ( | oreq | , |
szResponse | |||
) |
Set the answer of a specific received request. The header will be automatically added when the answser is sent.
Prototype :fun [STD_HTTP_SERVER_REQUEST S] STD_HTTP_SERVER_REQUEST
STD_HTTP_SERVER_REQUEST | : a valid request object |
S | : an answer |
std_httpsrvSetResponseP | ( | oreq | , |
pFile | |||
) |
Set the file to send to a specific received request. The header will be automatically added when the answser is sent. The content file won't loaded in Scol memory.
Prototype :fun [STD_HTTP_SERVER_REQUEST P] STD_HTTP_SERVER_REQUEST
STD_HTTP_SERVER_REQUEST | : a valid request object |
P | : a read reference file |
std_httpsrvSend | ( | o | , |
oreq | |||
) |
Send an anwser to a client by an opened connection request. You should set std_httpsrvSetResponseS or std_httpsrvSetResponseP before use this function.
Prototype :fun [STD_HTTP_SERVER STD_HTTP_SERVER_REQUEST] I
STD_HTTP_SERVER | : a server to send the asynchronous answer |
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvCloseRequest | ( | o | , |
oreq | |||
) |
Close an opened connection request.
Prototype :fun [STD_HTTP_SERVER STD_HTTP_SERVER_REQUEST] I
STD_HTTP_SERVER | : server |
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvParseRequest | ( | oreq | ) |
Parse a received request.
Prototype :fun [STD_HTTP_SERVER_REQUEST] [S S S S S S S S S S [[S S] r1]]
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvRequestHeader | ( | oreq | ) |
Return the header of a received request object.
Prototype :fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvRequestBody | ( | oreq | ) |
Return the body of a received request object.
Prototype :fun [STD_HTTP_SERVER_REQUEST] S
STD_HTTP_SERVER_REQUEST | : a valid request object |
std_httpsrvKeyValue | ( | str | , |
verb | |||
) |
Function to convert a string parameters like a=b&c=d ... to a list key,value.
Prototype :fun [STD_HTTP_SERVER_REQUEST S] [[S S] r1]
STD_HTTP_SERVER_REQUEST | : a valid request object |
S | : the verb ("GET", "POST", ...) |