Client API

using RequestQueue = ObjectQueue<HttpRequest, HTTP_REQUEST_POOL_SIZE>

Provides http client connection.

class HttpClient
#include <HttpClient.h>

Subclassed by Ota::Network::HttpUpgrader

Public Functions

inline virtual ~HttpClient()

HttpClient destructor.

Note

DON’T call cleanup. If you want to free all resources from HttpClients the correct sequence will be to

  1. Delete all instances of HttpClient

  2. Call the static method HttpClient::cleanup();

inline bool downloadString(const Url &url, RequestCompletedDelegate requestComplete, size_t maxLength = NETWORK_SEND_BUFFER_SIZE)

Queue request to download content as string (in memory)

Parameters
  • url – URL from which the content will be fetched

  • requestComplete – Completion callback

  • maxLength – maximum bytes to store in memory. If the response is bigger than maxLength then the rest bytes will be discarded. Use this parameter wisely as setting the value too high may consume all available RAM resulting in device restart and Denial-Of-Service

bool downloadFile(const Url &url, const String &saveFileName, RequestCompletedDelegate requestComplete = nullptr)

Queue request to download a file.

Parameters
  • url – Source of file data

  • saveFileName – Path to save file to. Optional: specify nullptr to use name from url

  • requestComplete – Completion callback

inline HttpRequest *createRequest(const Url &url)

Helper function to create a new request on a URL.

Parameters

url

Returns

HttpRequest*

Public Static Functions

static inline void cleanup()

Use this method to clean all object pools.