6#include "HardwareSerial.h"
36template <
typename ClientType,
typename ServerType>
55 static IPAddress address;
56 address = WiFi.localIP();
75 void rewrite(
const char* from,
const char* to)
override {
83 void* ctx[] =
nullptr,
int ctxCount = 0)
override {
90 memmove(hl->
context, ctx, ctxCount *
sizeof(
void*));
109 const char* result)
override {
115 if (hl->contextCount < 2) {
119 const char* mime = (
const char*)hl->context[0];
120 const char* msg = (
const char*)hl->context[1];
121 handler.
reply(mime, msg, 200);
125 hl->
context[1] = (
void*)result;
134 const uint8_t* data,
int len)
override {
140 if (hl->contextCount < 3) {
144 const char* mime =
static_cast<char*
>(hl->context[0]);
145 const uint8_t* data =
static_cast<uint8_t*
>(hl->context[1]);
146 int* p_len = (
int*)hl->context[2];
149 handler.
reply(mime, data, len, 200);
166 if (hl->contextCount < 1) {
172 Url* url =
static_cast<Url*
>(hl->context[0]);
175 reply_header.
put(
"X-Forwarded-Host", (
const char*)hl->context[1]);
202 nullstr(handler_line_ptr->path.c_str()),
203 methods[handler_line_ptr->method],
204 nullstr(handler_line_ptr->mime));
206 if (pathStr.
matches(handler_line_ptr->path.c_str()) &&
212 nullstr(handler_line_ptr->path.c_str()));
213 handler_line_ptr->fn(
client_handler,
this, path, handler_line_ptr);
243 if (client.connected()) {
247 client.setNoDelay(
true);
266 ClientType* p_client = &(*current_client_iterator);
267 if (!p_client->connected()) {
274 if (p_client->available() == 0) {
276 "copy: no data available from client");
352 if ((!(*it).connected())) {
369 const char*
nullstr(
const char* in) {
return in ==
nullptr ?
"" : in; }
389 if (
rewrite->from.matches(from)) {
398 bool matchesMime(
const char* handler_mime,
const char* request_mime) {
401 if (
StrView(handler_mime).isEmpty() ||
StrView(request_mime).isEmpty()) {
Handles HTTP client connections and responses for the DLNA HTTP server.
Definition: HttpClientHandler.h:30
HttpRequestHeader & requestHeader()
Definition: HttpClientHandler.h:192
void readHttpHeader()
Reads the http header info from the client.
Definition: HttpClientHandler.h:42
HttpReplyHeader & replyHeader()
Definition: HttpClientHandler.h:194
void setClient(ClientT *client)
Definition: HttpClientHandler.h:39
void replyNotFound() override
Definition: HttpClientHandler.h:170
void resize(size_t newSize)
Definition: HttpClientHandler.h:197
Used to register and process callbacks.
Definition: HttpRequestHandlerLine.h:12
web_callback_fn fn
Definition: HttpRequestHandlerLine.h:36
Str path
Definition: HttpRequestHandlerLine.h:34
TinyMethodID method
Definition: HttpRequestHandlerLine.h:33
void ** context
Definition: HttpRequestHandlerLine.h:37
const char * mime
Definition: HttpRequestHandlerLine.h:35
int contextCount
Definition: HttpRequestHandlerLine.h:38
Object which information about the rewrite rule.
Definition: HttpRequestRewrite.h:11
Header-only HTTP server wrapper that registers callback handlers.
Definition: HttpServer.h:37
ListLockFree< ClientType >::Iterator current_client_iterator
Definition: HttpServer.h:337
void setReference(void *reference) override
Definesa reference/context object.
Definition: HttpServer.h:326
void processRequest(ClientType *p_client)
Definition: HttpServer.h:372
ListLockFree< ClientType > open_clients
Definition: HttpServer.h:335
bool copy() override
Call this method from your loop!
Definition: HttpServer.h:235
void on(const char *url, TinyMethodID method, web_callback_fn fn, void *ctx[]=nullptr, int ctxCount=0) override
register a generic handler
Definition: HttpServer.h:82
void on(const char *url, TinyMethodID method, Url &redirect) override
register a redirection
Definition: HttpServer.h:162
bool isActive() override
Definition: HttpServer.h:299
void setNoConnectDelay(int delay) override
Definition: HttpServer.h:309
void removeClosedClients()
Definition: HttpServer.h:349
bool onRequest(const char *path) override
Definition: HttpServer.h:192
bool matchesMime(const char *handler_mime, const char *request_mime)
Definition: HttpServer.h:398
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
Definition: HttpServer.h:133
void on(const char *url, TinyMethodID method, const char *mime, const char *result) override
register a handler which provides the indicated string
Definition: HttpServer.h:108
HttpServer(ServerType &server, int bufferSize=1024)
Definition: HttpServer.h:39
int no_connect_delay
Definition: HttpServer.h:342
void rewrite(const char *from, const char *to) override
adds a rewrite rule
Definition: HttpServer.h:75
ServerType * server_ptr
Definition: HttpServer.h:339
bool doLoop() override
Legacy method: same as copy();.
Definition: HttpServer.h:232
bool is_active
Definition: HttpServer.h:340
~HttpServer() override
Definition: HttpServer.h:45
List< HttpRequestRewrite * > rewrite_collection
Definition: HttpServer.h:334
const char * nullstr(const char *in)
Definition: HttpServer.h:369
IPAddress & localIP() override
Provides the local ip address.
Definition: HttpServer.h:54
HttpClientHandler< ClientType > client_handler
Definition: HttpServer.h:336
void end() override
stops the server_ptr
Definition: HttpServer.h:69
const char * local_host
Definition: HttpServer.h:341
void addHandler(HttpRequestHandlerLine *handlerLinePtr)
adds a new handler
Definition: HttpServer.h:227
bool begin() override
Starts the server.
Definition: HttpServer.h:61
List< HttpRequestHandlerLine * > handler_collection
Definition: HttpServer.h:333
const char * resolveRewrite(const char *from)
Definition: HttpServer.h:385
void * ref
Definition: HttpServer.h:343
void * getReference() override
Provides access to a reference/context object.
Definition: HttpServer.h:329
void on(const char *url, TinyMethodID method, const char *mime, web_callback_fn fn) override
register a handler with mime
Definition: HttpServer.h:96
const char * localHost() override
Determines the local ip address.
Definition: HttpServer.h:302
Definition: IHttpServer.h:19
virtual void reply(const char *contentType, Stream &inputStream, int size, int status=200, const char *msg=SUCCESS)=0
virtual Client * client()=0
virtual void endClient()=0
Abstract interface for HTTP server functionality.
Definition: IHttpServer.h:50
Bidirectional iterator for ListLockFree.
Definition: ListLockFree.h:44
Lock-free double linked list using atomic operations.
Definition: ListLockFree.h:28
Iterator end()
Definition: ListLockFree.h:395
bool empty()
Definition: ListLockFree.h:415
Iterator begin()
Definition: ListLockFree.h:388
bool erase(Iterator it)
Definition: ListLockFree.h:357
bool push_back(const T &data)
Definition: ListLockFree.h:195
Double linked list.
Definition: List.h:19
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: StrView.h:18
virtual bool matches(const char *pattern)
Definition: StrView.h:207
virtual bool replace(const char *toReplace, const int replaced)
Replaces the first instance of toReplace with replaced.
Definition: StrView.h:395
virtual bool contains(const char *str)
checks if the string contains a substring
Definition: StrView.h:284
URL parser which breaks a full url string up into its individual parts.
Definition: Url.h:18
const char * url()
Definition: Url.h:39
#define DLNA_HTTP_READ_TIMEOUT_MS
Define the default http request timeout.
Definition: dlna_config.h:20
Definition: Allocator.h:13
const char * methods[]
Definition: HttpHeader.h:50
TinyMethodID
Definition: HttpHeader.h:35
void(* web_callback_fn)(IClientHandler &client, IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *handlerLine)
Definition: IHttpServer.h:40
const char * LOCATION
Definition: HttpHeader.h:32