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

Protected Member Functions

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
 
Client * client_ptr = nullptr
 
WiFiServer * server_ptr = nullptr
 
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.

◆ contentStr()

Str tiny_dlna::HttpServer::contentStr ( )
inline

converts the client content to a string

◆ 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 = nullptr
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 = nullptr
protected

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