Skip to content

Class WebServer

ClassList > WebServer

Public Types

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

Public Functions

Type Name
WebServer (IPAddress addr, int port=80)
WebServer (int port=80)
void addHandler (RequestHandler * handler)
String arg (String name)
String arg (int i)
String argName (int i)
int args ()
bool authenticate (const char * username, const char * password)
virtual void begin ()
virtual void begin (uint16_t port)
virtual WiFiClient client ()
virtual void close ()
void collectHeaders (const char * headerKeys, const size_t headerKeysCount)
void enableCORS (boolean value=true)
void enableCrossOrigin (boolean value=true)
void enableDelay (boolean value)
virtual void handleClient ()
bool hasArg (String name)
bool hasHeader (String name)
String header (String name)
String header (int i)
String headerName (int i)
int headers ()
String hostHeader ()
HTTPMethod method ()
void on (const Uri & uri, THandlerFunction fn)
void on (const Uri & uri, HTTPMethod method, THandlerFunction fn)
void on (const Uri & uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn)
void onFileUpload (THandlerFunction ufn)
void onNotFound (THandlerFunction fn)
String pathArg (unsigned int i)
void requestAuthentication (HTTPAuthMethod mode=BASIC_AUTH, const char * realm=NULL, const String & authFailMsg=String(""))
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 sendContent (const String & content)
void sendContent (const char * content, size_t contentLength)
void sendContent_P (PGM_P content)
void sendContent_P (PGM_P content, size_t size)
void sendHeader (const String & name, const String & value, bool first=false)
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 serveStatic (const char * uri, fs::FS & fs, const char * path, const char * cache_header=NULL)
void setContentLength (const size_t contentLength)
void stop ()
size_t streamFile (T & file, const String & contentType)
HTTPUpload & upload ()
String uri ()
virtual ~WebServer ()

Public Static Functions

Type Name
String urlDecode (const String & text)

Protected Attributes

Type Name
bool _chunked
size_t _contentLength
boolean _corsEnabled
int _currentArgCount
RequestArgument * _currentArgs
WiFiClient _currentClient
RequestHandler * _currentHandler
RequestArgument * _currentHeaders
HTTPMethod _currentMethod
HTTPClientStatus _currentStatus
std::unique_ptr< HTTPUpload > _currentUpload
String _currentUri
uint8_t _currentVersion
THandlerFunction _fileUploadHandler
RequestHandler * _firstHandler
int _headerKeysCount
String _hostHeader
RequestHandler * _lastHandler
THandlerFunction _notFoundHandler
boolean _nullDelay
RequestArgument * _postArgs
int _postArgsLen
String _responseHeaders
WiFiServer _server
String _snonce
String _sopaque
String _srealm
unsigned long _statusChange

Protected Functions

Type Name
void _addRequestHandler (RequestHandler * handler)
bool _collectHeader (const char * headerName, const char * headerValue)
virtual size_t _currentClientWrite (const char * b, size_t l)
virtual size_t _currentClientWrite_P (PGM_P b, size_t l)
String _extractParam (String & authReq, const String & param, const char delimit='"')
void _finalizeResponse ()
String _getRandomHexString ()
void _handleRequest ()
void _parseArguments (String data)
bool _parseForm (WiFiClient & client, String boundary, uint32_t len)
bool _parseFormUploadAborted ()
bool _parseRequest (WiFiClient & client)
void _prepareHeader (String & response, int code, const char * content_type, size_t contentLength)
void _streamFileCore (const size_t fileSize, const String & fileName, const String & contentType)
int _uploadReadByte (WiFiClient & client)
void _uploadWriteByte (uint8_t b)

Protected Static Functions

Type Name
String _responseCodeToString (int code)

Public Types Documentation

typedef THandlerFunction

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

Public Functions Documentation

function WebServer [1/2]

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

function WebServer [2/2]

WebServer::WebServer (
    int port=80
) 

function addHandler

void WebServer::addHandler (
    RequestHandler * handler
) 

function arg [1/2]

String WebServer::arg (
    String name
) 

function arg [2/2]

String WebServer::arg (
    int i
) 

function argName

String WebServer::argName (
    int i
) 

function args

int WebServer::args () 

function authenticate

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

function begin [1/2]

virtual void WebServer::begin () 

function begin [2/2]

virtual void WebServer::begin (
    uint16_t port
) 

function client

inline virtual WiFiClient WebServer::client () 

function close

virtual void WebServer::close () 

function collectHeaders

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

function enableCORS

void WebServer::enableCORS (
    boolean value=true
) 

function enableCrossOrigin

void WebServer::enableCrossOrigin (
    boolean value=true
) 

function enableDelay

void WebServer::enableDelay (
    boolean value
) 

function handleClient

virtual void WebServer::handleClient () 

function hasArg

bool WebServer::hasArg (
    String name
) 

function hasHeader

bool WebServer::hasHeader (
    String name
) 

function header [1/2]

String WebServer::header (
    String name
) 

function header [2/2]

String WebServer::header (
    int i
) 

function headerName

String WebServer::headerName (
    int i
) 

function headers

int WebServer::headers () 

function hostHeader

String WebServer::hostHeader () 

function method

inline HTTPMethod WebServer::method () 

function on [1/3]

void WebServer::on (
    const Uri & uri,
    THandlerFunction fn
) 

function on [2/3]

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

function on [3/3]

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

function onFileUpload

void WebServer::onFileUpload (
    THandlerFunction ufn
) 

function onNotFound

void WebServer::onNotFound (
    THandlerFunction fn
) 

function pathArg

String WebServer::pathArg (
    unsigned int i
) 

function requestAuthentication

void WebServer::requestAuthentication (
    HTTPAuthMethod mode=BASIC_AUTH,
    const char * realm=NULL,
    const String & authFailMsg=String("")
) 

function send [1/3]

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

function send [2/3]

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

function send [3/3]

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

function sendContent [1/2]

void WebServer::sendContent (
    const String & content
) 

function sendContent [2/2]

void WebServer::sendContent (
    const char * content,
    size_t contentLength
) 

function sendContent_P [1/2]

void WebServer::sendContent_P (
    PGM_P content
) 

function sendContent_P [2/2]

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

function sendHeader

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

function send_P [1/2]

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

function send_P [2/2]

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

function serveStatic

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

function setContentLength

void WebServer::setContentLength (
    const size_t contentLength
) 

function stop

void WebServer::stop () 

function streamFile

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

function upload

inline HTTPUpload & WebServer::upload () 

function uri

inline String WebServer::uri () 

function ~WebServer

virtual WebServer::~WebServer () 

Public Static Functions Documentation

function urlDecode

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

Protected Attributes Documentation

variable _chunked

bool WebServer::_chunked;

variable _contentLength

size_t WebServer::_contentLength;

variable _corsEnabled

boolean WebServer::_corsEnabled;

variable _currentArgCount

int WebServer::_currentArgCount;

variable _currentArgs

RequestArgument* WebServer::_currentArgs;

variable _currentClient

WiFiClient WebServer::_currentClient;

variable _currentHandler

RequestHandler* WebServer::_currentHandler;

variable _currentHeaders

RequestArgument* WebServer::_currentHeaders;

variable _currentMethod

HTTPMethod WebServer::_currentMethod;

variable _currentStatus

HTTPClientStatus WebServer::_currentStatus;

variable _currentUpload

std::unique_ptr<HTTPUpload> WebServer::_currentUpload;

variable _currentUri

String WebServer::_currentUri;

variable _currentVersion

uint8_t WebServer::_currentVersion;

variable _fileUploadHandler

THandlerFunction WebServer::_fileUploadHandler;

variable _firstHandler

RequestHandler* WebServer::_firstHandler;

variable _headerKeysCount

int WebServer::_headerKeysCount;

variable _hostHeader

String WebServer::_hostHeader;

variable _lastHandler

RequestHandler* WebServer::_lastHandler;

variable _notFoundHandler

THandlerFunction WebServer::_notFoundHandler;

variable _nullDelay

boolean WebServer::_nullDelay;

variable _postArgs

RequestArgument* WebServer::_postArgs;

variable _postArgsLen

int WebServer::_postArgsLen;

variable _responseHeaders

String WebServer::_responseHeaders;

variable _server

WiFiServer WebServer::_server;

variable _snonce

String WebServer::_snonce;

variable _sopaque

String WebServer::_sopaque;

variable _srealm

String WebServer::_srealm;

variable _statusChange

unsigned long WebServer::_statusChange;

Protected Functions Documentation

function _addRequestHandler

void WebServer::_addRequestHandler (
    RequestHandler * handler
) 

function _collectHeader

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

function _currentClientWrite

inline virtual size_t WebServer::_currentClientWrite (
    const char * b,
    size_t l
) 

function _currentClientWrite_P

inline virtual size_t WebServer::_currentClientWrite_P (
    PGM_P b,
    size_t l
) 

function _extractParam

String WebServer::_extractParam (
    String & authReq,
    const String & param,
    const char delimit='"'
) 

function _finalizeResponse

void WebServer::_finalizeResponse () 

function _getRandomHexString

String WebServer::_getRandomHexString () 

function _handleRequest

void WebServer::_handleRequest () 

function _parseArguments

void WebServer::_parseArguments (
    String data
) 

function _parseForm

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

function _parseFormUploadAborted

bool WebServer::_parseFormUploadAborted () 

function _parseRequest

bool WebServer::_parseRequest (
    WiFiClient & client
) 

function _prepareHeader

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

function _streamFileCore

void WebServer::_streamFileCore (
    const size_t fileSize,
    const String & fileName,
    const String & contentType
) 

function _uploadReadByte

int WebServer::_uploadReadByte (
    WiFiClient & client
) 

function _uploadWriteByte

void WebServer::_uploadWriteByte (
    uint8_t b
) 

Protected Static Functions Documentation

function _responseCodeToString

static String WebServer::_responseCodeToString (
    int code
) 

The documentation for this class was generated from the following file cores/common/arduino/libraries/ext/WebServer/WebServer.h