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
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 usingPL::HttpClient::WriteRequestHeaders()
,PL::HttpClient::WriteRequestBody()
,PL::HttpClient::ReadResponseHeaders()
andPL::HttpClient::ReadResponseBody()
.PL::HttpClient::SetRequestAuthScheme()
andPL::HttpClient::SetRequestAuthCredentials()
configure the HTTP authentication.PL::HttpClient::SetRequestHeader()
andPL::HttpClient::DeleteRequestHeader()
configure the request headers.PL::HttpServer
- aPL::NetworkServer
implementation for HTTP/HTTPS connections. The descendant class should overridePL::HttpServer::HandleRequest()
to handle the client request.PL::HttpServerTransaction
- an HTTP/HTTPS server transaction class.PL::HttpServerTransaction::GetRequestMethod()
,PL::HttpServerTransaction::GetRequestUri()
,PL::HttpServerTransaction::GetRequestHeader()
,PL::HttpServerTransaction::GetRequestBodySize()
andPL::HttpServerTransaction::ReadRequestBody()
should be used to analyze the request.PL::HttpServerTransaction::SetResponseHeader()
andPL::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
- Types
- PL::HttpClient class
HttpClient
HttpClient::HttpClient()
HttpClient::HttpClient()
HttpClient::HttpClient()
HttpClient::HttpClient()
HttpClient::HttpClient()
HttpClient::HttpClient()
HttpClient::Lock()
HttpClient::Unlock()
HttpClient::Initialize()
HttpClient::WriteRequestHeaders()
HttpClient::WriteRequestBody()
HttpClient::WriteRequest()
HttpClient::WriteRequest()
HttpClient::ReadResponseHeaders()
HttpClient::ReadResponseBody()
HttpClient::Disconnect()
HttpClient::GetPort()
HttpClient::SetPort()
HttpClient::GetReadTimeout()
HttpClient::SetReadTimeout()
HttpClient::SetAuthScheme()
HttpClient::SetAuthCredentials()
HttpClient::SetRequestHeader()
HttpClient::DeleteRequestHeader()
HttpClient::GetResponseHeader()
HttpClient::defaultHttpPort
HttpClient::defaultHttpsPort
HttpClient::defaultReadTimeout
HttpClient::defaultHeaderBufferSize
- PL::HttpServer class
HttpServer
HttpServer::HttpServer()
HttpServer::HttpServer()
HttpServer::HttpServer()
HttpServer::HttpServer()
HttpServer::Lock()
HttpServer::Unlock()
HttpServer::Enable()
HttpServer::Disable()
HttpServer::IsEnabled()
HttpServer::GetPort()
HttpServer::SetPort()
HttpServer::GetMaxNumberOfClients()
HttpServer::SetMaxNumberOfClients()
HttpServer::GetReadTimeout()
HttpServer::SetReadTimeout()
HttpServer::SetTaskParameters()
HttpServer::GetName()
HttpServer::SetName()
HttpServer::enabledEvent
HttpServer::disabledEvent
HttpServer::defaultHttpName
HttpServer::defaultHttpsName
HttpServer::defaultHttpPort
HttpServer::defaultHttpsPort
HttpServer::defaultMaxNumberOfClients
HttpServer::defaultReadTimeout
HttpServer::defaultTaskParameters
HttpServer::defaultUriBufferSize
HttpServer::defaultHeaderBufferSize
HttpServer::HandleRequest()
- PL::HttpServerTransaction class
HttpServerTransaction
HttpServerTransaction::GetNetworkStream()
HttpServerTransaction::ReadRequestBody()
HttpServerTransaction::WriteResponse()
HttpServerTransaction::WriteResponse()
HttpServerTransaction::WriteResponse()
HttpServerTransaction::WriteResponse()
HttpServerTransaction::WriteResponse()
HttpServerTransaction::GetRequestMethod()
HttpServerTransaction::GetRequestUri()
HttpServerTransaction::GetRequestHeader()
HttpServerTransaction::GetRequestBodySize()
HttpServerTransaction::SetResponseHeader()