Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::HttpServer< ClientType, ServerType > Class Template Reference

Header-only HTTP server wrapper that registers callback handlers. More...

#include <HttpServer.h>

Inheritance diagram for tiny_dlna::HttpServer< ClientType, ServerType >:
Inheritance graph
[legend]

Public Member Functions

 HttpServer (ServerType &server, int bufferSize=1024)
 
 ~HttpServer () override
 
IPAddress & localIP () override
 Provides the local ip address.
 
bool begin () override
 Starts the server.
 
void end () override
 stops the server_ptr
 
void rewrite (const char *from, const char *to) override
 adds a rewrite rule
 
void on (const char *url, TinyMethodID method, web_callback_fn fn, void *ctx[]=nullptr, int ctxCount=0) override
 register a generic handler
 
void on (const char *url, TinyMethodID method, const char *mime, web_callback_fn fn) override
 register a handler with mime
 
void on (const char *url, TinyMethodID method, const char *mime, const char *result) override
 register a handler which provides the indicated string
 
void on (const char *url, TinyMethodID method, const char *mime, const uint8_t *data, int len) override
 register a handler which provides the indicated string
 
void on (const char *url, TinyMethodID method, Url &redirect) override
 register a redirection
 
bool onRequest (const char *path) override
 
void replyChunked (const char *contentType, Stream &inputStream, int status=200, const char *msg=SUCCESS) override
 chunked reply with data from an input stream
 
void replyChunked (const char *contentType, int status=200, const char *msg=SUCCESS) override
 start of chunked reply: use HttpChunkWriter to provde the data
 
void reply (const char *contentType, Stream &inputStream, int size, int status=200, const char *msg=SUCCESS) override
 write reply - copies data from input stream with header size
 
void reply (const char *contentType, size_t(*callback)(Print &out, void *ref), int status=200, const char *msg=SUCCESS, void *ref=nullptr) override
 write reply - using callback that writes to stream
 
void reply (const char *contentType, const char *str, int status=200, const char *msg=SUCCESS) override
 write reply - string with header size
 
void reply (const char *contentType, const uint8_t *str, int len, int status=200, const char *msg=SUCCESS) override
 Send binary data response.
 
void replyOK () override
 write OK reply with 200 SUCCESS
 
void replyNotFound () override
 write 404 reply
 
void replyError (int err, const char *msg="Internal Server Error") override
 Send error response with status code.
 
HttpRequestHeaderrequestHeader () override
 provides the request header
 
HttpReplyHeaderreplyHeader () override
 provides the reply header
 
void endClient () override
 closes the connection to the current client_ptr
 
void crlf () override
 print a CR LF
 
void addHandler (HttpRequestHandlerLine *handlerLinePtr) override
 adds a new handler
 
bool doLoop () override
 Legacy method: same as copy();.
 
bool copy () override
 Call this method from your loop!
 
ClientType & client () override
 Provides the current client.
 
 operator bool () override
 Provides true if the server has been started.
 
bool isActive () override
 Check if server is active.
 
const char * localHost () override
 Determines the local ip address.
 
void setNoConnectDelay (int delay) override
 Set no-connect delay.
 
Str contentStr () override
 converts the client content to a string
 
void setReference (void *reference) override
 Definesa reference/context object.
 
void * getReference () override
 Provides access to a reference/context object.
 

Protected Member Functions

void removeClosedClients ()
 
void reply (int status, const char *msg)
 Writes the status and message to the reply.
 
const char * nullstr (const char *in)
 Converts null to an empty string.
 
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
 
List< ClientType > open_clients
 
List< ClientType >::Iterator current_client_iterator
 
ClientType * client_ptr = nullptr
 
ServerType * server_ptr = nullptr
 
bool is_active
 
Vector< char > buffer {0}
 
const char * local_host = nullptr
 
int no_connect_delay = 5
 
void * ref = nullptr
 

Detailed Description

template<typename ClientType, typename ServerType>
class tiny_dlna::HttpServer< ClientType, ServerType >

Header-only HTTP server wrapper that registers callback handlers.

This server is templated so you can provide the concrete Arduino networking classes that back the transport. ClientType is the socket implementation accepted from the server (for example WiFiClient or EthernetClient) and ServerType is the listener type (for example WiFiServer). Default template arguments keep the legacy WiFi behaviour intact, while custom transports can swap in their own client/server types.

Template Parameters
ClientTypeArduino client class accepted from the listener (e.g. WiFiClient, EthernetClient).
ServerTypeArduino server/listener class that produces ClientType instances (e.g. WiFiServer, EthernetServer).

Constructor & Destructor Documentation

◆ HttpServer()

template<typename ClientType , typename ServerType >
tiny_dlna::HttpServer< ClientType, ServerType >::HttpServer ( ServerType &  server,
int  bufferSize = 1024 
)
inline

◆ ~HttpServer()

template<typename ClientType , typename ServerType >
tiny_dlna::HttpServer< ClientType, ServerType >::~HttpServer ( )
inlineoverride

Member Function Documentation

◆ addHandler()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::addHandler ( HttpRequestHandlerLine handlerLinePtr)
inlineoverridevirtual

adds a new handler

Implements tiny_dlna::IHttpServer.

◆ begin()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::begin ( )
inlineoverridevirtual

Starts the server.

Implements tiny_dlna::IHttpServer.

◆ client()

template<typename ClientType , typename ServerType >
ClientType & tiny_dlna::HttpServer< ClientType, ServerType >::client ( )
inlineoverridevirtual

Provides the current client.

Implements tiny_dlna::IHttpServer.

◆ contentStr()

template<typename ClientType , typename ServerType >
Str tiny_dlna::HttpServer< ClientType, ServerType >::contentStr ( )
inlineoverridevirtual

converts the client content to a string

Implements tiny_dlna::IHttpServer.

◆ copy()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::copy ( )
inlineoverridevirtual

Call this method from your loop!

Implements tiny_dlna::IHttpServer.

◆ crlf()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::crlf ( )
inlineoverridevirtual

print a CR LF

Implements tiny_dlna::IHttpServer.

◆ doLoop()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::doLoop ( )
inlineoverridevirtual

Legacy method: same as copy();.

Implements tiny_dlna::IHttpServer.

◆ end()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::end ( )
inlineoverridevirtual

stops the server_ptr

Implements tiny_dlna::IHttpServer.

◆ endClient()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::endClient ( )
inlineoverridevirtual

closes the connection to the current client_ptr

Implements tiny_dlna::IHttpServer.

◆ getReference()

template<typename ClientType , typename ServerType >
void * tiny_dlna::HttpServer< ClientType, ServerType >::getReference ( )
inlineoverridevirtual

Provides access to a reference/context object.

Implements tiny_dlna::IHttpServer.

◆ isActive()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::isActive ( )
inlineoverridevirtual

Check if server is active.

Implements tiny_dlna::IHttpServer.

◆ localHost()

template<typename ClientType , typename ServerType >
const char * tiny_dlna::HttpServer< ClientType, ServerType >::localHost ( )
inlineoverridevirtual

Determines the local ip address.

Implements tiny_dlna::IHttpServer.

◆ localIP()

template<typename ClientType , typename ServerType >
IPAddress & tiny_dlna::HttpServer< ClientType, ServerType >::localIP ( )
inlineoverridevirtual

Provides the local ip address.

Implements tiny_dlna::IHttpServer.

◆ matchesMime()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::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()

template<typename ClientType , typename ServerType >
const char * tiny_dlna::HttpServer< ClientType, ServerType >::nullstr ( const char *  in)
inlineprotected

Converts null to an empty string.

◆ on() [1/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
const char *  result 
)
inlineoverridevirtual

register a handler which provides the indicated string

Implements tiny_dlna::IHttpServer.

◆ on() [2/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
const uint8_t *  data,
int  len 
)
inlineoverridevirtual

register a handler which provides the indicated string

Implements tiny_dlna::IHttpServer.

◆ on() [3/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::on ( const char *  url,
TinyMethodID  method,
const char *  mime,
web_callback_fn  fn 
)
inlineoverridevirtual

register a handler with mime

Implements tiny_dlna::IHttpServer.

◆ on() [4/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::on ( const char *  url,
TinyMethodID  method,
Url redirect 
)
inlineoverridevirtual

register a redirection

Implements tiny_dlna::IHttpServer.

◆ on() [5/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::on ( const char *  url,
TinyMethodID  method,
web_callback_fn  fn,
void *  ctx[] = nullptr,
int  ctxCount = 0 
)
inlineoverridevirtual

register a generic handler

Implements tiny_dlna::IHttpServer.

◆ onRequest()

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::onRequest ( const char *  path)
inlineoverridevirtual

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

Implements tiny_dlna::IHttpServer.

◆ operator bool()

template<typename ClientType , typename ServerType >
tiny_dlna::HttpServer< ClientType, ServerType >::operator bool ( )
inlineoverridevirtual

Provides true if the server has been started.

Implements tiny_dlna::IHttpServer.

◆ processRequest()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::processRequest ( )
inlineprotected

◆ removeClosedClients()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::removeClosedClients ( )
inlineprotected

◆ reply() [1/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::reply ( const char *  contentType,
const char *  str,
int  status = 200,
const char *  msg = SUCCESS 
)
inlineoverridevirtual

write reply - string with header size

Implements tiny_dlna::IHttpServer.

◆ reply() [2/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::reply ( const char *  contentType,
const uint8_t *  str,
int  len,
int  status = 200,
const char *  msg = SUCCESS 
)
inlineoverridevirtual

Send binary data response.

Implements tiny_dlna::IHttpServer.

◆ reply() [3/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::reply ( const char *  contentType,
size_t(*)(Print &out, void *ref callback,
int  status = 200,
const char *  msg = SUCCESS,
void *  ref = nullptr 
)
inlineoverridevirtual

write reply - using callback that writes to stream

Implements tiny_dlna::IHttpServer.

◆ reply() [4/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::reply ( const char *  contentType,
Stream &  inputStream,
int  size,
int  status = 200,
const char *  msg = SUCCESS 
)
inlineoverridevirtual

write reply - copies data from input stream with header size

Implements tiny_dlna::IHttpServer.

◆ reply() [5/5]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::reply ( int  status,
const char *  msg 
)
inlineprotected

Writes the status and message to the reply.

◆ replyChunked() [1/2]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::replyChunked ( const char *  contentType,
int  status = 200,
const char *  msg = SUCCESS 
)
inlineoverridevirtual

start of chunked reply: use HttpChunkWriter to provde the data

Implements tiny_dlna::IHttpServer.

◆ replyChunked() [2/2]

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::replyChunked ( const char *  contentType,
Stream &  inputStream,
int  status = 200,
const char *  msg = SUCCESS 
)
inlineoverridevirtual

chunked reply with data from an input stream

Implements tiny_dlna::IHttpServer.

◆ replyError()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::replyError ( int  err,
const char *  msg = "Internal Server Error" 
)
inlineoverridevirtual

Send error response with status code.

Implements tiny_dlna::IHttpServer.

◆ replyHeader()

template<typename ClientType , typename ServerType >
HttpReplyHeader & tiny_dlna::HttpServer< ClientType, ServerType >::replyHeader ( )
inlineoverridevirtual

provides the reply header

Implements tiny_dlna::IHttpServer.

◆ replyNotFound()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::replyNotFound ( )
inlineoverridevirtual

write 404 reply

Implements tiny_dlna::IHttpServer.

◆ replyOK()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::replyOK ( )
inlineoverridevirtual

write OK reply with 200 SUCCESS

Implements tiny_dlna::IHttpServer.

◆ requestHeader()

template<typename ClientType , typename ServerType >
HttpRequestHeader & tiny_dlna::HttpServer< ClientType, ServerType >::requestHeader ( )
inlineoverridevirtual

provides the request header

Implements tiny_dlna::IHttpServer.

◆ resolveRewrite()

template<typename ClientType , typename ServerType >
const char * tiny_dlna::HttpServer< ClientType, ServerType >::resolveRewrite ( const char *  from)
inlineprotected

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

◆ rewrite()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::rewrite ( const char *  from,
const char *  to 
)
inlineoverridevirtual

adds a rewrite rule

Implements tiny_dlna::IHttpServer.

◆ setNoConnectDelay()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::setNoConnectDelay ( int  delay)
inlineoverridevirtual

Set no-connect delay.

Implements tiny_dlna::IHttpServer.

◆ setReference()

template<typename ClientType , typename ServerType >
void tiny_dlna::HttpServer< ClientType, ServerType >::setReference ( void *  reference)
inlineoverridevirtual

Definesa reference/context object.

Implements tiny_dlna::IHttpServer.

Member Data Documentation

◆ buffer

template<typename ClientType , typename ServerType >
Vector<char> tiny_dlna::HttpServer< ClientType, ServerType >::buffer {0}
protected

◆ client_ptr

template<typename ClientType , typename ServerType >
ClientType* tiny_dlna::HttpServer< ClientType, ServerType >::client_ptr = nullptr
protected

◆ current_client_iterator

template<typename ClientType , typename ServerType >
List<ClientType>::Iterator tiny_dlna::HttpServer< ClientType, ServerType >::current_client_iterator
protected
Initial value:
=
List< ClientType > open_clients
Definition: HttpServer.h:456
Iterator begin()
Definition: List.h:309

◆ handler_collection

template<typename ClientType , typename ServerType >
List<HttpRequestHandlerLine*> tiny_dlna::HttpServer< ClientType, ServerType >::handler_collection
protected

◆ is_active

template<typename ClientType , typename ServerType >
bool tiny_dlna::HttpServer< ClientType, ServerType >::is_active
protected

◆ local_host

template<typename ClientType , typename ServerType >
const char* tiny_dlna::HttpServer< ClientType, ServerType >::local_host = nullptr
protected

◆ no_connect_delay

template<typename ClientType , typename ServerType >
int tiny_dlna::HttpServer< ClientType, ServerType >::no_connect_delay = 5
protected

◆ open_clients

template<typename ClientType , typename ServerType >
List<ClientType> tiny_dlna::HttpServer< ClientType, ServerType >::open_clients
protected

◆ ref

template<typename ClientType , typename ServerType >
void* tiny_dlna::HttpServer< ClientType, ServerType >::ref = nullptr
protected

◆ reply_header

template<typename ClientType , typename ServerType >
HttpReplyHeader tiny_dlna::HttpServer< ClientType, ServerType >::reply_header
protected

◆ request_header

template<typename ClientType , typename ServerType >
HttpRequestHeader tiny_dlna::HttpServer< ClientType, ServerType >::request_header
protected

◆ rewrite_collection

template<typename ClientType , typename ServerType >
List<HttpRequestRewrite*> tiny_dlna::HttpServer< ClientType, ServerType >::rewrite_collection
protected

◆ server_ptr

template<typename ClientType , typename ServerType >
ServerType* tiny_dlna::HttpServer< ClientType, ServerType >::server_ptr = nullptr
protected

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