demo_utils.curl_client module

A client for executing HTTP requests via cURL. It does not use any external libraries. The only requirement is that you have the curl executable in your PATH or bin.

Used to make arbitrary http(s) requests.

class demo_utils.curl_client.CurlClient(username='', password='', proto='http', server='127.0.0.1', port=8080)

The CurlClient object. Houses the parameters used when making requests

Parameters:
  • username (str, optional) – Username for basic authentication. Default empty string
  • password (str, optional) – Password for basic authentication. Default empty string
  • proto (str, optional) – protocol used in requests. Must be one of http or https
  • server (str, optional) – The server or hostname to which we will make the request. Defaults 127.0.0.1
  • port (int, optional) – The integer number of the port that the server runs on. Defaults 8080
cmd = <demo_utils.shell.Shell instance>
make_request(verb, request, options='', query='')

Make the actual request using cURL and the demo_utils.shell module.

Parameters:
  • verb (str) – the HTTP verb to use. Currently only supporting GET/PUT/POST/DELETE
  • request (str) – The request path. Simply appended to the end of PROTO://HOST:PORT. Should begin with a leading ‘/’.
  • options (str, optional) – cURL command line argument that you which to be included. This might include headers or more.
  • query (str, optional) – The query string to be appended to the end of the request URL.
Returns:

A two item list. The [0] element is the output to stdout. The [1] element is the curl output to stderr

Return type:

list

Raises:

ValueError – When the HTTP verb is not one of GET/PUT/POST/DELETE

password = ''

Password for basic authentication

port = ''

Port to connect to

proto = ''

Protocol to use when connecting via cURL

server = ''

Server or hostname to connect to

set_password(password)

Set the basic authentication password

Parameters:password (str) –
Returns:N/A
set_port(port)

Set the port to connect to

Parameters:port (int, str) –
Returns:N/A
Raises:ValueError – When the port argument can’t be converted to an int. Or when the port is less than 0 or greater than 65535
set_proto(proto)

Set the protocol. Must be http or https

Parameters:proto (str) –
Returns:N/A
Raises:ValueError – When proto argument is not one of http or https
set_server(server)

Set the server to connect to

Parameters:server (str) –
Returns:N/A
set_username(username)

Set the basic authentication username

Parameters:username (str) –
Returns:N/A
username = ''

Username for basic authentication