A Simple Header only implementation of Http Server that allows the registration of callback functions. This is based on the Arduino Server class. More...
#include <HttpServer.h>
Public Member Functions | |
HttpServer (WiFiServer &server_ptr, int bufferSize=1024) | |
void | addExtension (Extension &out) |
registers an extension | |
void | addHandler (HttpRequestHandlerLine *handlerLinePtr) |
adds a new handler | |
bool | begin (int port) |
Starts the server on the indicated port. | |
bool | begin (int port, const char *ssid, const char *password) |
Starts the server on the indicated port - calls WiFi.begin(ssid, password);. | |
WiFiClient & | client () |
Provides the current client. | |
void | copy () |
Call this method from your loop! | |
void | crlf () |
print a CR LF | |
void | doLoop () |
Legacy method: same as copy();. | |
void | endClient () |
closes the connection to the current client_ptr | |
const char * | localHost () |
Determines the local ip address. | |
IPAddress & | localIP () |
Provides the local ip address. | |
void | on (const char *url, TinyMethodID method, const char *mime, const char *result) |
register a handler which provides the indicated string | |
void | on (const char *url, TinyMethodID method, const char *mime, web_callback_fn fn) |
register a handler with mime | |
void | on (const char *url, TinyMethodID method, HttpTunnel &tunnel) |
register a redirection | |
void | on (const char *url, TinyMethodID method, Url &redirect) |
register a redirection | |
void | on (const char *url, TinyMethodID method, web_callback_fn fn, void *ctx[]=nullptr, int ctxCount=0) |
register a generic handler | |
bool | onRequest (const char *path) |
generic handler - you can overwrite this method to provide your specifc processing logic | |
operator bool () | |
Provides true if the server has been started. | |
void | reply (const char *contentType, const char *str, int status=200, const char *msg=SUCCESS) |
write reply - string with header size | |
void | reply (const char *contentType, Stream &inputStream, int size, int status=200, const char *msg=SUCCESS) |
write reply - copies data from input stream with header size | |
void | reply (const char *contentType, void(*callback)(Stream &out), int status=200, const char *msg=SUCCESS) |
write reply - using callback that writes to stream | |
void | reply (int status, const char *msg) |
Writes the status and message to the reply. | |
void | replyChunked (const char *contentType, int status=200, const char *msg=SUCCESS) |
start of chunked reply: use HttpChunkWriter to provde the data | |
void | replyChunked (const char *contentType, Stream &inputStream, int status=200, const char *msg=SUCCESS) |
chunked reply with data from an input stream | |
HttpReplyHeader & | replyHeader () |
provides the reply header | |
void | replyNotFound () |
write 404 reply | |
void | replyOK () |
write OK reply with 200 SUCCESS | |
HttpRequestHeader & | requestHeader () |
provides the request header | |
void | rewrite (const char *from, const char *to) |
adds a rewrite rule | |
void | stop () |
stops the server_ptr | |
Protected Member Functions | |
bool | matchesMime (const char *handler_mime, const char *request_mime) |
compares mime of handler with mime of request: provides true if they match of one is null (=any value) | |
const char * | nullstr (const char *in) |
Converts null to an empty string. | |
void | processExtensions () |
executes the doLoop of all extension_collection | |
void | processRequest () |
const char * | resolveRewrite (const char *from) |
determiens the potentially rewritten url which should be used for the further processing | |
Protected Attributes | |
char * | buffer |
int | buffer_size |
WiFiClient * | client_ptr |
List< Extension * > | extension_collection |
List< HttpRequestHandlerLine * > | handler_collection |
bool | is_active |
const char * | local_host =nullptr |
HttpReplyHeader | reply_header |
HttpRequestHeader | request_header |
List< HttpRequestRewrite * > | rewrite_collection |
WiFiServer * | server_ptr |
A Simple Header only implementation of Http Server that allows the registration of callback functions. This is based on the Arduino Server class.