SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::HTTPServer Class Reference

HTTP server class wrapping the esp-idf http server. More...

#include <sensesp/net/http_server.h>

Inheritance diagram for sensesp::HTTPServer:
[legend]

Public Member Functions

 HTTPServer (int port=HTTP_DEFAULT_PORT, const String &config_path="/system/httpserver")
 
void stop ()
 
void set_auth_credentials (const String &username, const String &password, bool auth_required=true)
 
void set_captive_portal (bool captive_portal, IPAddress ap_ip=IPAddress())
 Enable or disable the captive-portal redirect path.
 
virtual bool to_json (JsonObject &config) override
 
virtual bool from_json (const JsonObject &config) override
 
void add_handler (std::shared_ptr< HTTPRequestHandler > &handler)
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 

Protected Member Functions

bool authenticate_request (HTTPAuthenticator *auth, std::function< esp_err_t(httpd_req_t *)> handler, httpd_req_t *req)
 
esp_err_t dispatch_request (httpd_req_t *req)
 Dispatcher method that captures all requests and forwards them to the appropriate handlers.
 
bool handle_captive_portal (httpd_req_t *req)
 Check if the request is for the captive portal and handle it if it.
 

Protected Attributes

bool captive_portal_ = false
 
IPAddress captive_portal_ap_ip_
 
httpd_handle_t server_ = nullptr
 
httpd_config_t config_
 
String username_
 
String ha1_
 Pre-computed MD5(username:realm:password)
 
bool auth_required_ = false
 
std::unique_ptr< HTTPAuthenticatorauthenticator_
 
std::list< std::shared_ptr< HTTPRequestHandler > > handlers_
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 

Friends

esp_err_t call_request_dispatcher (httpd_req_t *req)
 

Detailed Description

HTTP server class wrapping the esp-idf http server.

Definition at line 83 of file http_server.h.

Constructor & Destructor Documentation

◆ HTTPServer()

sensesp::HTTPServer::HTTPServer ( int  port = HTTP_DEFAULT_PORT,
const String &  config_path = "/system/httpserver" 
)
inline

Definition at line 85 of file http_server.h.

Here is the call graph for this function:

Member Function Documentation

◆ add_handler()

void sensesp::HTTPServer::add_handler ( std::shared_ptr< HTTPRequestHandler > &  handler)
inline

Definition at line 194 of file http_server.h.

◆ authenticate_request()

bool sensesp::HTTPServer::authenticate_request ( HTTPAuthenticator auth,
std::function< esp_err_t(httpd_req_t *)>  handler,
httpd_req_t *  req 
)
protected

Definition at line 174 of file http_server.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_request()

esp_err_t sensesp::HTTPServer::dispatch_request ( httpd_req_t *  req)
protected

Dispatcher method that captures all requests and forwards them to the appropriate handlers.

Parameters
req
Returns
esp_err_t

Definition at line 41 of file http_server.cpp.

Here is the call graph for this function:

◆ from_json()

virtual bool sensesp::HTTPServer::from_json ( const JsonObject &  root)
inlineoverridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 175 of file http_server.h.

Here is the call graph for this function:

◆ handle_captive_portal()

bool sensesp::HTTPServer::handle_captive_portal ( httpd_req_t *  req)
protected

Check if the request is for the captive portal and handle it if it.

Parameters
req
Returns
true Request was handled
false Request was not handled

Definition at line 131 of file http_server.cpp.

Here is the caller graph for this function:

◆ set_auth_credentials()

void sensesp::HTTPServer::set_auth_credentials ( const String &  username,
const String &  password,
bool  auth_required = true 
)
inline

Definition at line 145 of file http_server.h.

Here is the call graph for this function:

◆ set_captive_portal()

void sensesp::HTTPServer::set_captive_portal ( bool  captive_portal,
IPAddress  ap_ip = IPAddress() 
)
inline

Enable or disable the captive-portal redirect path.

The captive-portal path is only meaningful when the underlying network provisioner is serving a soft-AP (currently WiFi only). SensESPApp passes the soft-AP IPv4 address here so this class does not need to depend on the WiFi library directly.

Definition at line 161 of file http_server.h.

◆ stop()

void sensesp::HTTPServer::stop ( )
inline

Definition at line 143 of file http_server.h.

◆ to_json()

virtual bool sensesp::HTTPServer::to_json ( JsonObject &  root)
inlineoverridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 167 of file http_server.h.

Friends And Related Symbol Documentation

◆ call_request_dispatcher

esp_err_t call_request_dispatcher ( httpd_req_t *  req)
friend

Definition at line 187 of file http_server.cpp.

Member Data Documentation

◆ auth_required_

bool sensesp::HTTPServer::auth_required_ = false
protected

Definition at line 205 of file http_server.h.

◆ authenticator_

std::unique_ptr<HTTPAuthenticator> sensesp::HTTPServer::authenticator_
protected

Definition at line 206 of file http_server.h.

◆ captive_portal_

bool sensesp::HTTPServer::captive_portal_ = false
protected

Definition at line 199 of file http_server.h.

◆ captive_portal_ap_ip_

IPAddress sensesp::HTTPServer::captive_portal_ap_ip_
protected

Definition at line 200 of file http_server.h.

◆ config_

httpd_config_t sensesp::HTTPServer::config_
protected

Definition at line 202 of file http_server.h.

◆ ha1_

String sensesp::HTTPServer::ha1_
protected

Pre-computed MD5(username:realm:password)

Definition at line 204 of file http_server.h.

◆ handlers_

std::list<std::shared_ptr<HTTPRequestHandler> > sensesp::HTTPServer::handlers_
protected

Definition at line 230 of file http_server.h.

◆ server_

httpd_handle_t sensesp::HTTPServer::server_ = nullptr
protected

Definition at line 201 of file http_server.h.

◆ username_

String sensesp::HTTPServer::username_
protected

Definition at line 203 of file http_server.h.


The documentation for this class was generated from the following files: