Arduino DLNA Server
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::HttpServer Class Reference

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>

Collaboration diagram for tiny_dlna::HttpServer:
Collaboration graph
[legend]

Public Member Functions

 HttpServer (WiFiServer &server, int bufferSize=1024)
 
 ~HttpServer ()
 
IPAddress & localIP ()
 Provides the local ip address. More...
 
bool begin (int port, const char *ssid, const char *password)
 
bool begin (int port)
 Starts the server on the indicated port. More...
 
void end ()
 stops the server_ptr More...
 
void rewrite (const char *from, const char *to)
 adds a rewrite rule More...
 
void on (const char *url, TinyMethodID method, web_callback_fn fn, void *ctx[]=nullptr, int ctxCount=0)
 register a generic handler More...
 
void on (const char *url, TinyMethodID method, const char *mime, web_callback_fn fn)
 register a handler with mime More...
 
void on (const char *url, TinyMethodID method, const char *mime, const char *result)
 register a handler which provides the indicated string More...
 
void on (const char *url, TinyMethodID method, const char *mime, const uint8_t *data, int len)
 register a handler which provides the indicated string More...
 
void on (const char *url, TinyMethodID method, Url &redirect)
 register a redirection More...
 
void on (const char *url, TinyMethodID method, HttpTunnel &tunnel)
 register a redirection More...
 
bool onRequest (const char *path)
 
void replyChunked (const char *contentType, Stream &inputStream, int status=200, const char *msg=SUCCESS)
 chunked reply with data from an input stream More...
 
void replyChunked (const char *contentType, int status=200, const char *msg=SUCCESS)
 start of chunked reply: use HttpChunkWriter to provde the data More...
 
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 More...
 
void reply (const char *contentType, void(*callback)(Stream &out), int status=200, const char *msg=SUCCESS)
 write reply - using callback that writes to stream More...
 
void reply (const char *contentType, void(*callback)(Print &out), int status=200, const char *msg=SUCCESS)
 write reply - using callback that writes to stream More...
 
void reply (const char *contentType, const char *str, int status=200, const char *msg=SUCCESS)
 write reply - string with header size More...
 
void reply (const char *contentType, const uint8_t *str, int len, int status=200, const char *msg=SUCCESS)
 
void replyOK ()
 write OK reply with 200 SUCCESS More...
 
void replyNotFound ()
 write 404 reply More...
 
void reply (int status, const char *msg)
 Writes the status and message to the reply. More...
 
HttpRequestHeaderrequestHeader ()
 provides the request header More...
 
HttpReplyHeaderreplyHeader ()
 provides the reply header More...
 
void endClient ()
 closes the connection to the current client_ptr More...
 
void crlf ()
 print a CR LF More...
 
void addHandler (HttpRequestHandlerLine *handlerLinePtr)
 adds a new handler More...
 
bool doLoop ()
 Legacy method: same as copy();. More...
 
bool copy ()
 Call this method from your loop! More...
 
Client & client ()
 Provides the current client. More...
 
 operator bool ()
 Provides true if the server has been started. More...
 
const char * localHost ()
 Determines the local ip address. More...
 
void setNoConnectDelay (int delay)
 

Protected Member Functions

const char * nullstr (const char *in)
 Converts null to an empty string. More...
 
void processRequest ()
 
const char * resolveRewrite (const char *from)
 
bool matchesMime (const char *handler_mime, const char *request_mime)
 

Protected Attributes

HttpRequestHeader request_header
 
HttpReplyHeader reply_header
 
List< HttpRequestHandlerLine * > handler_collection
 
List< HttpRequestRewrite * > rewrite_collection
 
Client * client_ptr
 
WiFiServer * server_ptr
 
bool is_active
 
Vector< char > buffer {0}
 
const char * local_host = nullptr
 
int no_connect_delay = 5
 

Detailed Description

A Simple Header only implementation of Http Server that allows the registration of callback functions. This is based on the Arduino Server class.

Constructor & Destructor Documentation

◆ HttpServer()

tiny_dlna::HttpServer::HttpServer ( WiFiServer &  server,
int  bufferSize = 1024 
)
inline

◆ ~HttpServer()

tiny_dlna::HttpServer::~HttpServer ( )
inline

Member Function Documentation

◆ addHandler()

void tiny_dlna::HttpServer::addHandler ( HttpRequestHandlerLine handlerLinePtr)
inline

adds a new handler

◆ begin() [1/2]

bool tiny_dlna::HttpServer::begin ( int  port)
inline

Starts the server on the indicated port.

◆ begin() [2/2]

bool tiny_dlna::HttpServer::begin ( int  port,
const char *  ssid,
const char *  password 
)
inline

Starts the server on the indicated port - calls WiFi.begin(ssid, password);

◆ client()

Client& tiny_dlna::HttpServer::client ( )
inline

Provides the current client.

◆ copy()

bool tiny_dlna::HttpServer::copy ( )
inline

Call this method from your loop!

◆ crlf()

void tiny_dlna::HttpServer::crlf ( )
inline

print a CR LF

◆ doLoop()

bool tiny_dlna::HttpServer::doLoop ( )
inline

Legacy method: same as copy();.

◆ end()

void tiny_dlna::HttpServer::end ( )
inline

stops the server_ptr

◆ endClient()

void tiny_dlna::HttpServer::endClient ( )
inline

closes the connection to the current client_ptr

◆ localHost()

const char* tiny_dlna::HttpServer::localHost ( )
inline

Determines the local ip address.

◆ localIP()

IPAddress& tiny_dlna::HttpServer::localIP ( )
inline

Provides the local ip address.

◆ matchesMime()

bool tiny_dlna::HttpServer::matchesMime ( const char *  handler_mime,
const char *  request_mime 
)
inlineprotected

compares mime of handler with mime of request: provides true if they match of one is null (=any value)

◆ nullstr()

const char* tiny_dlna::HttpServer::nullstr ( const char *  in)
inlineprotected

Converts null to an empty string.

◆ on() [1/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
const char *  result 
)
inline

register a handler which provides the indicated string

◆ on() [2/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
const uint8_t *  data,
int  len 
)
inline

register a handler which provides the indicated string

◆ on() [3/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
web_callback_fn  fn 
)
inline

register a handler with mime

◆ on() [4/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
HttpTunnel tunnel 
)
inline

register a redirection

◆ on() [5/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
Url redirect 
)
inline

register a redirection

◆ on() [6/6]

void tiny_dlna::HttpServer::on ( const char *  url,
TinyMethodID  method,
web_callback_fn  fn,
void *  ctx[] = nullptr,
int  ctxCount = 0 
)
inline

register a generic handler

◆ onRequest()

bool tiny_dlna::HttpServer::onRequest ( const char *  path)
inline

generic handler - you can overwrite this method to provide your specifc processing logic

◆ operator bool()

tiny_dlna::HttpServer::operator bool ( )
inline

Provides true if the server has been started.

◆ processRequest()

void tiny_dlna::HttpServer::processRequest ( )
inlineprotected

◆ reply() [1/6]

void tiny_dlna::HttpServer::reply ( const char *  contentType,
const char *  str,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

write reply - string with header size

◆ reply() [2/6]

void tiny_dlna::HttpServer::reply ( const char *  contentType,
const uint8_t *  str,
int  len,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

◆ reply() [3/6]

void tiny_dlna::HttpServer::reply ( const char *  contentType,
Stream &  inputStream,
int  size,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

write reply - copies data from input stream with header size

◆ reply() [4/6]

void tiny_dlna::HttpServer::reply ( const char *  contentType,
void(*)(Print &out)  callback,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

write reply - using callback that writes to stream

◆ reply() [5/6]

void tiny_dlna::HttpServer::reply ( const char *  contentType,
void(*)(Stream &out)  callback,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

write reply - using callback that writes to stream

◆ reply() [6/6]

void tiny_dlna::HttpServer::reply ( int  status,
const char *  msg 
)
inline

Writes the status and message to the reply.

◆ replyChunked() [1/2]

void tiny_dlna::HttpServer::replyChunked ( const char *  contentType,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

start of chunked reply: use HttpChunkWriter to provde the data

◆ replyChunked() [2/2]

void tiny_dlna::HttpServer::replyChunked ( const char *  contentType,
Stream &  inputStream,
int  status = 200,
const char *  msg = SUCCESS 
)
inline

chunked reply with data from an input stream

◆ replyHeader()

HttpReplyHeader& tiny_dlna::HttpServer::replyHeader ( )
inline

provides the reply header

◆ replyNotFound()

void tiny_dlna::HttpServer::replyNotFound ( )
inline

write 404 reply

◆ replyOK()

void tiny_dlna::HttpServer::replyOK ( )
inline

write OK reply with 200 SUCCESS

◆ requestHeader()

HttpRequestHeader& tiny_dlna::HttpServer::requestHeader ( )
inline

provides the request header

◆ resolveRewrite()

const char* tiny_dlna::HttpServer::resolveRewrite ( const char *  from)
inlineprotected

determiens the potentially rewritten url which should be used for the further processing

◆ rewrite()

void tiny_dlna::HttpServer::rewrite ( const char *  from,
const char *  to 
)
inline

adds a rewrite rule

◆ setNoConnectDelay()

void tiny_dlna::HttpServer::setNoConnectDelay ( int  delay)
inline

Member Data Documentation

◆ buffer

Vector<char> tiny_dlna::HttpServer::buffer {0}
protected

◆ client_ptr

Client* tiny_dlna::HttpServer::client_ptr
protected

◆ handler_collection

List<HttpRequestHandlerLine*> tiny_dlna::HttpServer::handler_collection
protected

◆ is_active

bool tiny_dlna::HttpServer::is_active
protected

◆ local_host

const char* tiny_dlna::HttpServer::local_host = nullptr
protected

◆ no_connect_delay

int tiny_dlna::HttpServer::no_connect_delay = 5
protected

◆ reply_header

HttpReplyHeader tiny_dlna::HttpServer::reply_header
protected

◆ request_header

HttpRequestHeader tiny_dlna::HttpServer::request_header
protected

◆ rewrite_collection

List<HttpRequestRewrite*> tiny_dlna::HttpServer::rewrite_collection
protected

◆ server_ptr

WiFiServer* tiny_dlna::HttpServer::server_ptr
protected

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