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
PL::HttpClient
HttpClient()
HttpClient()
HttpClient()
HttpClient()
HttpClient()
HttpClient()
Lock()
Unlock()
Initialize()
WriteRequestHeaders()
WriteRequestBody()
WriteRequest()
WriteRequest()
ReadResponseHeaders()
ReadResponseBody()
Disconnect()
GetPort()
SetPort()
GetReadTimeout()
SetReadTimeout()
SetAuthScheme()
SetAuthCredentials()
SetRequestHeader()
DeleteRequestHeader()
GetResponseHeader()
defaultHttpPort
defaultHttpsPort
defaultReadTimeout
defaultHeaderBufferSize
- PL::HttpServer class
PL::HttpServer
HttpServer()
HttpServer()
HttpServer()
HttpServer()
Lock()
Unlock()
Enable()
Disable()
IsEnabled()
GetPort()
SetPort()
GetMaxNumberOfClients()
SetMaxNumberOfClients()
GetReadTimeout()
SetReadTimeout()
SetTaskParameters()
GetName()
SetName()
enabledEvent
disabledEvent
defaultHttpName
defaultHttpsName
defaultHttpPort
defaultHttpsPort
defaultMaxNumberOfClients
defaultReadTimeout
defaultTaskParameters
defaultUriBufferSize
defaultHeaderBufferSize
HandleRequest()
- PL::HttpServerTransaction class