ESP_IOT v2.5
IOT ESP Coding
WebServer Class Reference

#include <WebServer.h>

Collaboration diagram for WebServer:
Collaboration graph

Classes

struct  RequestArgument
 

Public Types

typedef std::function< void(void)> THandlerFunction
 

Public Member Functions

 WebServer (IPAddress addr, int port=80)
 
 WebServer (int port=80)
 
 ~WebServer ()
 
void begin ()
 
void handleClient ()
 
void close ()
 
void stop ()
 
bool authenticate (const char *username, const char *password)
 
void requestAuthentication ()
 
void on (const String &uri, THandlerFunction handler)
 
void on (const String &uri, HTTPMethod method, THandlerFunction fn)
 
void on (const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn)
 
void addHandler (RequestHandler *handler)
 
void serveStatic (const char *uri, fs::FS &fs, const char *path, const char *cache_header=NULL)
 
void onNotFound (THandlerFunction fn)
 
void onFileUpload (THandlerFunction fn)
 
String uri ()
 
HTTPMethod method ()
 
WiFiClient client ()
 
HTTPUploadupload ()
 
String arg (String name)
 
String arg (int i)
 
String argName (int i)
 
int args ()
 
bool hasArg (String name)
 
void collectHeaders (const char *headerKeys[], const size_t headerKeysCount)
 
String header (String name)
 
String header (int i)
 
String headerName (int i)
 
int headers ()
 
bool hasHeader (String name)
 
String hostHeader ()
 
void send (int code, const char *content_type=NULL, const String &content=String(""))
 
void send (int code, char *content_type, const String &content)
 
void send (int code, const String &content_type, const String &content)
 
void send_P (int code, PGM_P content_type, PGM_P content)
 
void send_P (int code, PGM_P content_type, PGM_P content, size_t contentLength)
 
void setContentLength (size_t contentLength)
 
void sendHeader (const String &name, const String &value, bool first=false)
 
void sendContent (const String &content)
 
void sendContent_P (PGM_P content)
 
void sendContent_P (PGM_P content, size_t size)
 
template<typename T >
size_t streamFile (T &file, const String &contentType)
 

Static Public Member Functions

static String urlDecode (const String &text)
 

Protected Member Functions

void _addRequestHandler (RequestHandler *handler)
 
void _handleRequest ()
 
bool _parseRequest (WiFiClient &client)
 
void _parseArguments (String data)
 
bool _parseForm (WiFiClient &client, String boundary, uint32_t len)
 
bool _parseFormUploadAborted ()
 
void _uploadWriteByte (uint8_t b)
 
uint8_t _uploadReadByte (WiFiClient &client)
 
void _prepareHeader (String &response, int code, const char *content_type, size_t contentLength)
 
bool _collectHeader (const char *headerName, const char *headerValue)
 

Static Protected Member Functions

static String _responseCodeToString (int code)
 

Protected Attributes

WiFiServer _server
 
WiFiClient _currentClient
 
HTTPMethod _currentMethod
 
String _currentUri
 
uint8_t _currentVersion
 
HTTPClientStatus _currentStatus
 
unsigned long _statusChange
 
RequestHandler_currentHandler
 
RequestHandler_firstHandler
 
RequestHandler_lastHandler
 
THandlerFunction _notFoundHandler
 
THandlerFunction _fileUploadHandler
 
int _currentArgCount
 
RequestArgument_currentArgs
 
HTTPUpload _currentUpload
 
int _headerKeysCount
 
RequestArgument_currentHeaders
 
size_t _contentLength
 
String _responseHeaders
 
String _hostHeader
 
bool _chunked
 

Detailed Description

Definition at line 66 of file WebServer.h.

Member Typedef Documentation

◆ THandlerFunction

typedef std::function<void(void)> WebServer::THandlerFunction

Definition at line 82 of file WebServer.h.

Constructor & Destructor Documentation

◆ WebServer() [1/2]

WebServer::WebServer ( IPAddress  addr,
int  port = 80 
)

Definition at line 44 of file WebServer.cpp.

◆ WebServer() [2/2]

WebServer::WebServer ( int  port = 80)

Definition at line 62 of file WebServer.cpp.

◆ ~WebServer()

WebServer::~WebServer ( )

Definition at line 80 of file WebServer.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ _addRequestHandler()

void WebServer::_addRequestHandler ( RequestHandler handler)
protected

Definition at line 154 of file WebServer.cpp.

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

◆ _collectHeader()

bool WebServer::_collectHeader ( const char *  headerName,
const char *  headerValue 
)
protected

Definition at line 259 of file Parsing.cpp.

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

◆ _handleRequest()

void WebServer::_handleRequest ( )
protected

Definition at line 456 of file WebServer.cpp.

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

◆ _parseArguments()

void WebServer::_parseArguments ( String  data)
protected

Definition at line 269 of file Parsing.cpp.

Here is the call graph for this function:

◆ _parseForm()

bool WebServer::_parseForm ( WiFiClient &  client,
String  boundary,
uint32_t  len 
)
protected

Definition at line 364 of file Parsing.cpp.

Here is the call graph for this function:

◆ _parseFormUploadAborted()

bool WebServer::_parseFormUploadAborted ( )
protected

Definition at line 603 of file Parsing.cpp.

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

◆ _parseRequest()

bool WebServer::_parseRequest ( WiFiClient &  client)
protected

Definition at line 67 of file Parsing.cpp.

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

◆ _prepareHeader()

void WebServer::_prepareHeader ( String &  response,
int  code,
const char *  content_type,
size_t  contentLength 
)
protected

Definition at line 259 of file WebServer.cpp.

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

◆ _responseCodeToString()

String WebServer::_responseCodeToString ( int  code)
staticprotected

Definition at line 484 of file WebServer.cpp.

Here is the caller graph for this function:

◆ _uploadReadByte()

uint8_t WebServer::_uploadReadByte ( WiFiClient &  client)
protected

Definition at line 354 of file Parsing.cpp.

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

◆ _uploadWriteByte()

void WebServer::_uploadWriteByte ( uint8_t  b)
protected

Definition at line 344 of file Parsing.cpp.

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

◆ addHandler()

void WebServer::addHandler ( RequestHandler handler)

Definition at line 150 of file WebServer.cpp.

Here is the call graph for this function:

◆ arg() [1/2]

String WebServer::arg ( int  i)

Definition at line 376 of file WebServer.cpp.

◆ arg() [2/2]

String WebServer::arg ( String  name)

Definition at line 368 of file WebServer.cpp.

Here is the caller graph for this function:

◆ argName()

String WebServer::argName ( int  i)

Definition at line 382 of file WebServer.cpp.

Here is the caller graph for this function:

◆ args()

int WebServer::args ( )

Definition at line 388 of file WebServer.cpp.

◆ authenticate()

bool WebServer::authenticate ( const char *  username,
const char *  password 
)

Definition at line 100 of file WebServer.cpp.

Here is the call graph for this function:

◆ begin()

void WebServer::begin ( )

Definition at line 93 of file WebServer.cpp.

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

◆ client()

WiFiClient WebServer::client ( )
inline

Definition at line 93 of file WebServer.h.

Here is the caller graph for this function:

◆ close()

void WebServer::close ( )

Definition at line 233 of file WebServer.cpp.

Here is the caller graph for this function:

◆ collectHeaders()

void WebServer::collectHeaders ( const char *  headerKeys[],
const size_t  headerKeysCount 
)

Definition at line 409 of file WebServer.cpp.

Here is the caller graph for this function:

◆ handleClient()

void WebServer::handleClient ( )

Definition at line 169 of file WebServer.cpp.

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

◆ hasArg()

bool WebServer::hasArg ( String  name)

Definition at line 392 of file WebServer.cpp.

Here is the caller graph for this function:

◆ hasHeader()

bool WebServer::hasHeader ( String  name)

Definition at line 436 of file WebServer.cpp.

Here is the caller graph for this function:

◆ header() [1/2]

String WebServer::header ( int  i)

Definition at line 420 of file WebServer.cpp.

◆ header() [2/2]

String WebServer::header ( String  name)

Definition at line 401 of file WebServer.cpp.

Here is the caller graph for this function:

◆ headerName()

String WebServer::headerName ( int  i)

Definition at line 426 of file WebServer.cpp.

Here is the caller graph for this function:

◆ headers()

int WebServer::headers ( )

Definition at line 432 of file WebServer.cpp.

◆ hostHeader()

String WebServer::hostHeader ( )

Definition at line 444 of file WebServer.cpp.

◆ method()

HTTPMethod WebServer::method ( )
inline

Definition at line 92 of file WebServer.h.

Here is the caller graph for this function:

◆ on() [1/3]

void WebServer::on ( const String &  uri,
HTTPMethod  method,
WebServer::THandlerFunction  fn 
)

Definition at line 142 of file WebServer.cpp.

Here is the call graph for this function:

◆ on() [2/3]

void WebServer::on ( const String &  uri,
HTTPMethod  method,
WebServer::THandlerFunction  fn,
WebServer::THandlerFunction  ufn 
)

Definition at line 146 of file WebServer.cpp.

Here is the call graph for this function:

◆ on() [3/3]

void WebServer::on ( const String &  uri,
WebServer::THandlerFunction  handler 
)

Definition at line 138 of file WebServer.cpp.

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

◆ onFileUpload()

void WebServer::onFileUpload ( THandlerFunction  fn)

Definition at line 448 of file WebServer.cpp.

◆ onNotFound()

void WebServer::onNotFound ( THandlerFunction  fn)

Definition at line 452 of file WebServer.cpp.

Here is the caller graph for this function:

◆ requestAuthentication()

void WebServer::requestAuthentication ( )

Definition at line 133 of file WebServer.cpp.

Here is the call graph for this function:

◆ send() [1/3]

void WebServer::send ( int  code,
char *  content_type,
const String &  content 
)

Definition at line 322 of file WebServer.cpp.

Here is the call graph for this function:

◆ send() [2/3]

void WebServer::send ( int  code,
const char *  content_type = NULL,
const String &  content = String("") 
)

Definition at line 287 of file WebServer.cpp.

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

◆ send() [3/3]

void WebServer::send ( int  code,
const String &  content_type,
const String &  content 
)

Definition at line 326 of file WebServer.cpp.

Here is the call graph for this function:

◆ send_P() [1/2]

void WebServer::send_P ( int  code,
PGM_P  content_type,
PGM_P  content 
)

Definition at line 298 of file WebServer.cpp.

Here is the call graph for this function:

◆ send_P() [2/2]

void WebServer::send_P ( int  code,
PGM_P  content_type,
PGM_P  content,
size_t  contentLength 
)

Definition at line 313 of file WebServer.cpp.

Here is the call graph for this function:

◆ sendContent()

void WebServer::sendContent ( const String &  content)

Definition at line 330 of file WebServer.cpp.

Here is the caller graph for this function:

◆ sendContent_P() [1/2]

void WebServer::sendContent_P ( PGM_P  content)

Definition at line 347 of file WebServer.cpp.

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

◆ sendContent_P() [2/2]

void WebServer::sendContent_P ( PGM_P  content,
size_t  size 
)

Definition at line 351 of file WebServer.cpp.

◆ sendHeader()

void WebServer::sendHeader ( const String &  name,
const String &  value,
bool  first = false 
)

Definition at line 241 of file WebServer.cpp.

Here is the caller graph for this function:

◆ serveStatic()

void WebServer::serveStatic ( const char *  uri,
fs::FS &  fs,
const char *  path,
const char *  cache_header = NULL 
)

Definition at line 165 of file WebServer.cpp.

Here is the call graph for this function:

◆ setContentLength()

void WebServer::setContentLength ( size_t  contentLength)

Definition at line 255 of file WebServer.cpp.

Here is the caller graph for this function:

◆ stop()

void WebServer::stop ( )

Definition at line 237 of file WebServer.cpp.

Here is the call graph for this function:

◆ streamFile()

template<typename T >
size_t WebServer::streamFile ( T &  file,
const String &  contentType 
)
inline

Definition at line 128 of file WebServer.h.

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

◆ upload()

HTTPUpload & WebServer::upload ( )
inline

Definition at line 94 of file WebServer.h.

◆ uri()

String WebServer::uri ( )
inline

Definition at line 91 of file WebServer.h.

Here is the caller graph for this function:

◆ urlDecode()

String WebServer::urlDecode ( const String &  text)
static

Definition at line 572 of file Parsing.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ _chunked

bool WebServer::_chunked
protected

Definition at line 182 of file WebServer.h.

◆ _contentLength

size_t WebServer::_contentLength
protected

Definition at line 178 of file WebServer.h.

◆ _currentArgCount

int WebServer::_currentArgCount
protected

Definition at line 172 of file WebServer.h.

◆ _currentArgs

RequestArgument* WebServer::_currentArgs
protected

Definition at line 173 of file WebServer.h.

◆ _currentClient

WiFiClient WebServer::_currentClient
protected

Definition at line 159 of file WebServer.h.

◆ _currentHandler

RequestHandler* WebServer::_currentHandler
protected

Definition at line 166 of file WebServer.h.

◆ _currentHeaders

RequestArgument* WebServer::_currentHeaders
protected

Definition at line 177 of file WebServer.h.

◆ _currentMethod

HTTPMethod WebServer::_currentMethod
protected

Definition at line 160 of file WebServer.h.

◆ _currentStatus

HTTPClientStatus WebServer::_currentStatus
protected

Definition at line 163 of file WebServer.h.

◆ _currentUpload

HTTPUpload WebServer::_currentUpload
protected

Definition at line 174 of file WebServer.h.

◆ _currentUri

String WebServer::_currentUri
protected

Definition at line 161 of file WebServer.h.

◆ _currentVersion

uint8_t WebServer::_currentVersion
protected

Definition at line 162 of file WebServer.h.

◆ _fileUploadHandler

THandlerFunction WebServer::_fileUploadHandler
protected

Definition at line 170 of file WebServer.h.

◆ _firstHandler

RequestHandler* WebServer::_firstHandler
protected

Definition at line 167 of file WebServer.h.

◆ _headerKeysCount

int WebServer::_headerKeysCount
protected

Definition at line 176 of file WebServer.h.

◆ _hostHeader

String WebServer::_hostHeader
protected

Definition at line 181 of file WebServer.h.

◆ _lastHandler

RequestHandler* WebServer::_lastHandler
protected

Definition at line 168 of file WebServer.h.

◆ _notFoundHandler

THandlerFunction WebServer::_notFoundHandler
protected

Definition at line 169 of file WebServer.h.

◆ _responseHeaders

String WebServer::_responseHeaders
protected

Definition at line 179 of file WebServer.h.

◆ _server

WiFiServer WebServer::_server
protected

Definition at line 157 of file WebServer.h.

◆ _statusChange

unsigned long WebServer::_statusChange
protected

Definition at line 164 of file WebServer.h.


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