HTTP/HTTPS Component

Installation

The component requires ESP-IDF 5.3 and higher and is installed using IDF Component Manager.

Add this to the idf_component.yml in the project main directory or in the component directory:

dependencies:
  plasmapper/pl_http: "^1.1.0"

Add this to the source code:

#include "pl_http.h"

Add extern "C" to the app_main function:

extern "C" void app_main(void) {...}

Add this to the sdkconfig.defaults in the project directory or configure the values using Project Configuration:

CONFIG_COMPILER_CXX_RTTI=y
CONFIG_LWIP_SO_RCVBUF=y
CONFIG_ESP_HTTPS_SERVER_ENABLE=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y

Features

  1. PL::HttpClient - an HTTP/HTTPS client class. It is initialized with a hostname and (for an HTTPS client) server certificate or certificate bundle. PL::HttpClient::Initialize() initializes the client. A request is performed using PL::HttpClient::WriteRequestHeaders(), PL::HttpClient::WriteRequestBody(), PL::HttpClient::ReadResponseHeaders() and PL::HttpClient::ReadResponseBody(). PL::HttpClient::SetRequestAuthScheme() and PL::HttpClient::SetRequestAuthCredentials() configure the HTTP authentication. PL::HttpClient::SetRequestHeader() and PL::HttpClient::DeleteRequestHeader() configure the request headers.

  2. PL::HttpServer - a PL::NetworkServer implementation for HTTP/HTTPS connections. The descendant class should override PL::HttpServer::HandleRequest() to handle the client request.

  3. PL::HttpServerTransaction - an HTTP/HTTPS server transaction class. PL::HttpServerTransaction::GetRequestMethod(), PL::HttpServerTransaction::GetRequestUri(), PL::HttpServerTransaction::GetRequestHeader(), PL::HttpServerTransaction::GetRequestBodySize() and PL::HttpServerTransaction::ReadRequestBody() should be used to analyze the request. PL::HttpServerTransaction::SetResponseHeader() and PL::HttpServerTransaction::WriteResponse() should be used to send the response.

Thread safety

Class method thread safety is implemented by having the PL::Lockable as a base class and creating the class object lock guard at the beginning of the methods.

PL::HttpClient::ReadResponseHeaders() locks both the PL::HttpClient and the header buffer objects for the duration of the transaction.

PL::HttpServer request handler locks the PL::HttpServer, the URI buffer and the header buffer objects for the duration of the transaction.

Examples

API reference