HSL 2.0 framework Description of the framework

Public Member Functions |List of all members
hsl20_4_http_client.hsl20_4_http_client.Client Class Reference

All methods of the HTTP client More..

## Public Member Functions
def | __init__ (self, framework, context_map)
| Constructor. More...
def | set_url (self, method, url, http_version=1)
| Sets the URL to be called. More...
def | set_header (self, key, value)
| Sets a header. More...
def | set_body (self, data, content_type=None)
| Set the body. More...
def | set_on_data (self, callback)
| Specifies a callback method for the response. More...
def | set_on_error (self, callback)
| Specifies a callback method for errors. More...
def | start_request (self)
| Starts HTTP polling. More...

## Detailed Description

All methods of the HTTP client

Deprecated:
  This class should no longer be used. The example https_client WebRequest shows how it can be replaced by standard Python modules

Used for communication with a remote terminal via HTTP.

## Timeouts

The following timeouts, which will disconnect the connection when they occur, must be observed:

- The time between two received packets is greater than 15 seconds
- More than 30 seconds have passed since the connection was established and the header has not yet been sent correctly

class my_demo_module(hsl20_4.BaseModule):
...
def get_demo_page(self):
client = self.FRAMEWORK.create_http_client()
client.set_url("GET" , "http://www.example.net/" )
client.set_on_data(self.on_example_data)
client.start_request()
def on_example_data(self, http_response):
if http_response.get_status_code()==200:
# Evaluate response

Note
  The class works asynchronously. None of the methods offered are blocked

## Constructor & Destructor Documentation

## ◆ __init__()

def hsl20_4_http_client.hsl20_4_http_client.Client.__init__ | ( |  | self,
|  |  | framework,
|  |  | context_map
| ) |  |

Constructor

Warning
  This class should not be instantiated directly

## Member Function Documentation

## ◆ set_body()

def hsl20_4_http_client.hsl20_4_http_client.client.set_body | ( |  | self,
|  |  | data,
|  |  | content_type = `None`
| ) |  |

Set the body

Only needed for e.g. POST and GET. The method also sets the HTTP header "Content-length" based on the data passed under data

Parameters

  data | string Data
  content_type | string Optional, sets in the header the content-type of the data to be transmitted (default: None) Note added to the default value of parameter content_type

## ◆ set_header()

def hsl20_4_http_client.hsl20_4_http_client.Client.set_header | ( |  | self,
|  |  | key,
|  |  | value
| ) |  |

Sets a header

For example: `set_header("Content-type", "text/html")`
Several headers can be defined

Parameters

  key | string Key of the header
  value | string Value

## ◆ set_on_data()

def hsl20_4_http_client.hsl20_4_http_client.client.set_on_data | ( |  | self,
|  |  | callback
| ) |  |

Specifies a callback method for the response

The method is called when the remote party has completely answered the request or when an error has occurred.

The callback method requires the following parameters:

- response hsl20_4_http_client.hsl20_4_http_client.Response
  Response object. Contains the response data of the remote party.

Parameters

  callback | function Callback method

## ◆ set_on_error()

def hsl20_4_http_client.hsl20_4_http_client.Client.set_on_error | ( |  | self,
|  |  | callback
| ) |  |

Specifies a callback method for errors

The callback method is called when an error or timeout occurs during communication.

The callback method requires the following parameters:

- exception exception
  The exception that occurred. Returns None if an unknown error has occurred.

Parameters

  callback | function Callback method

## ◆ set_url()

def hsl20_4_http_client.hsl20_4_http_client.client.set_url | ( |  | self,
|  |  | method,
|  |  | ancient,
|  |  | http_version = `1`
| ) |  |

Sets the URL to be called

Parameters

  method | string Retrieval method to be used for the URL (e.g. GET)
  url | string URL (e.g. http://www.example.net/)
  http_version | int Optional. HTTP version. 1 => HTTP/1.0 (default) 2 => HTTP/1.1

Note
  The transferring URL must be correctly encoded

Exceptions

  ValueError | Dispatched when an invalid URL is supplied
  ValueError | Dispatched when an invalid HTTP version is submitted

## ◆ start_request()

def hsl20_4_http_client.hsl20_4_http_client.client.start_request | ( |  | self | ) |

Starts HTTP polling

Triggers an exception if not all attributes required for the request are set

Exceptions

  AttributeError | Triggers an exception if not all attributes required for the retrieval are set
  RuntimeError | Triggers an exception if the host name could not be resolved
  RuntimeError | Triggers an exception if the method has already been called

The documentation for this class was generated from the following file:

- hsl20_4_http_client.py