HSL 2.0 framework
Description of the framework
|
All methods of the HTTP server More
..Public Member Functions | |
def | __init__ (self, framework, context_map) |
Constructor. More... | |
def | set_authentication (self, user=None, pw=None, digest=False) |
Sets the HTTP authentication: More... | |
def | set_address (self, ip, port) |
Sets the IP address and IP port. More... | |
def | set_error_callback (self, callback) |
Sets a callback method in case of an error. More... | |
def | set_max_post_size (self, size) |
Sets the allowed size of the body for POST/PUT calls. More... | |
def | set_logger (self, logger) |
Assigns an hsl20_4.hsl20_4.Logger instance to the server. More... | |
def | start_server (self) |
Starts the server. More... | |
def | register_uri (self, method, path, callback) |
Registers a URI on the server. More... | |
def | set_server_name (self, name) |
Sets the server name. More... | |
All methods of the HTTP server
Provides a server service for communication via HTTP.
If the HTTP server was generated by the framework and bound to an IP and port, it can be started
If calls are now made by a client, there are two possibilities:
After processing the respective callback method, the server sends the generated response to the remote terminal. If no status code is set in the response object, the server answers with status code 501
When registering a URI, one or more HTTP methods (by logical OR, e.g. hsl20_4_http_server.GET|hsl20_4_http_server.PUT) can be defined directly, alternatively you can also assign hsl20_4_http_server.ALL, then the callback method will be called for each method. The HTTP server provides direct support for the following methods:
With the methods POST and PUT a body element is supported in the request. For this purpose the field "Content-length" must be set in the header. If the client exceeds the maximum allowed size, the server will disconnect the connection
See also hsl20_4_http_server.Server::set_max_post_size
Please note the following timeouts, when they occur, the connection will be disconnected:
It is possible to secure access to the server with user/password. Authentication can be enabled and disabled using the method hsl20_4_http_server.Server.set_authentication. The following two methods are available for transmitting user data:
RESULT = BASE64(user name + ":" + password)
HA1 = MD5(USERNAME + ":" + REALM + ":" + PASSWORD) HA2 = MD5(UPPERCASE(HTTP_METHOD) + ":" + URI) RESULT = MD5(HA1 + ":" + NONCE_SERVER + ":" + NONCE_COUNTER + ":" + NONCE_CLIENT + ":auth:" + HA2)
The use of this class by means of a short source code excerpt
def hsl20_4_http_server.hsl20_4_http_server.Server.__init__ | ( | self, | |
framework, | |||
context_map | |||
) |
Constructor
def hsl20_4_http_server.hsl20_4_http_server.Server.register_uri | ( | self, | |
method, | |||
path, | |||
callback | |||
) |
Registers a URI on the server
If this URI is called by a client, the transferred callback is executed
method | int HTTP retrieval methods. OR multiple options per URI are supported. The following constants are available:
|
path | string Path (e.g.: /index) |
callback | function Callback. The method passed here requires the following parameters |
def hsl20_4_http_server.hsl20_4_http_server.Server.set_address | ( | self, | |
ip, | |||
port | |||
) |
def hsl20_4_http_server.hsl20_4_http_server.Server.set_authentication | ( | self, | |
user = None , |
|||
pw = None , |
|||
digest = False |
|||
) |
Sets the HTTP authentication
Authentication counts for all registered URIs
user | string User |
pw | string Password |
digest | bool Optional. If TRUE, "Digest Access Authentication" is used as the authentication mechanism, otherwise "Basic Authentication" is used |
def hsl20_4_http_server.hsl20_4_http_server.Server.set_error_callback | ( | self, | |
callback | |||
) |
Sets a callback method in case of an error
Called when the client calls a URL not registered with register_uri. Evaluated by the HTTP server after this method is completed.
callback | function The callback method requires the following parameters:
|
def hsl20_4_http_server.hsl20_4_http_server.Server.set_logger | ( | self, | |
logger | |||
) |
Assigns a hsl20_4.hsl20_4.Logger instance to the server
logger | hsl20_4.logger Logger object |
def hsl20_4_http_server.hsl20_4_http_server.Server.set_max_post_size | ( | self, | |
size | |||
) |
Sets the allowed size of the body for POST/PUT calls
If the value is exceeded, the call is aborted.
Default value: 1,000,000 bytes
Maximum permissible value (MAX VALUE): 10,000,000 bytes
size | int Size in bytes. If size > MAXVALUE, size = MAXVALUE is set! |
def hsl20_4_http_server.hsl20_4_http_server.Server.set_server_name | ( | self, | |
name | |||
) |
Sets the server name
If set, this value is used as the default value for the 'Server' field in an HTTP request. The value set here can be overwritten with response.set_header. If no value is specified by set_server_name and no value is specified by response.set_header, the context is transmitted as server name
name | string New server name |
def hsl20_4_http_server.hsl20_4_http_server.server.start_server | ( | self | ) |
Starts the server
AttributeError | Is triggered if no valid address is specified |