SensESP 3.0.1
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)
 
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
 
- Public Member Functions inherited from sensesp::Serializable

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
 
httpd_handle_t server_ = nullptr
 
httpd_config_t config_
 
String username_
 
String 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 61 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 63 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 142 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 165 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 40 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 129 of file http_server.h.

◆ 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 122 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 110 of file http_server.h.

◆ set_captive_portal()

void sensesp::HTTPServer::set_captive_portal ( bool captive_portal)
inline

Definition at line 117 of file http_server.h.

◆ stop()

void sensesp::HTTPServer::stop ( )
inline

Definition at line 108 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 121 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 178 of file http_server.cpp.

Member Data Documentation

◆ auth_required_

bool sensesp::HTTPServer::auth_required_ = false
protected

Definition at line 152 of file http_server.h.

◆ authenticator_

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

Definition at line 153 of file http_server.h.

◆ captive_portal_

bool sensesp::HTTPServer::captive_portal_ = false
protected

Definition at line 147 of file http_server.h.

◆ config_

httpd_config_t sensesp::HTTPServer::config_
protected

Definition at line 149 of file http_server.h.

◆ handlers_

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

Definition at line 177 of file http_server.h.

◆ password_

String sensesp::HTTPServer::password_
protected

Definition at line 151 of file http_server.h.

◆ server_

httpd_handle_t sensesp::HTTPServer::server_ = nullptr
protected

Definition at line 148 of file http_server.h.

◆ username_

String sensesp::HTTPServer::username_
protected

Definition at line 150 of file http_server.h.


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