forked from benkuper/juce_simpleweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleWebSocketServer.cpp
More file actions
714 lines (602 loc) · 20.1 KB
/
SimpleWebSocketServer.cpp
File metadata and controls
714 lines (602 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/*
==============================================================================
juce_SimpleWebSocketServer.cpp
Created: 17 Jun 2020 11:22:54pm
Author: bkupe
==============================================================================
*/
#include "JuceHeader.h"
using namespace juce;
SimpleWebSocketServerBase::SimpleWebSocketServerBase() : Thread("Web socket"), port(0), allowAddressReuse(false), isConnected(false) {}
SimpleWebSocketServerBase::~SimpleWebSocketServerBase()
{
stopThread(2000);
}
void SimpleWebSocketServerBase::start(int _port, const String& _wsSuffix, const String& _localAddress, bool allowAddrReuse)
{
stopThread(1000);
localAddress = _localAddress;
port = _port;
wsSuffix = _wsSuffix;
allowAddressReuse = allowAddrReuse;
isConnecting = true;
startThread();
}
void SimpleWebSocketServerBase::send(const MemoryBlock& data)
{
send((const char*) data.getData(), (int) data.getSize());
}
void SimpleWebSocketServerBase::stop()
{
// #if !JUCE_DEBUG
// if (Thread::getCurrentThreadId() != this->getThreadId()) stopThread(500);
// #endif
stopInternal();
isConnecting = false;
isConnected = false;
// #if JUCE_DEBUG //don't know why the order is not the same for debug and release...
// if (Thread::getCurrentThreadId() != this->getThreadId()) stopThread(500);
// #endif
}
void SimpleWebSocketServerBase::closeConnection(const String& id, int code, const String& reason)
{
closeConnectionInternal(id, code, reason);
}
void SimpleWebSocketServerBase::run()
{
// HTTP init
isConnected = false;
isConnecting = true;
initServer();
}
void SimpleWebSocketServerBase::addHTTPRequestHandler(RequestHandler* newHandler)
{
handlers.add(newHandler);
}
void SimpleWebSocketServerBase::removeHTTPRequestHandler(RequestHandler* handlerToRemove)
{
handlers.removeAllInstancesOf(handlerToRemove);
}
// SIMPLE
SimpleWebSocketServer::SimpleWebSocketServer() {}
SimpleWebSocketServer::~SimpleWebSocketServer()
{
stop();
}
void SimpleWebSocketServer::send(const String& message)
{
HashMap<String, std::shared_ptr<WsServer::Connection>, DefaultHashFunctions, CriticalSection>::Iterator it(connectionMap);
while (it.next())
{
it.getValue()->send(message.toStdString());
}
}
void SimpleWebSocketServer::send(const char* data, int numData)
{
std::shared_ptr<WsServer::OutMessage> out_message = std::make_shared<WsServer::OutMessage>();
out_message->write(data, numData);
HashMap<String, std::shared_ptr<WsServer::Connection>, DefaultHashFunctions, CriticalSection>::Iterator it(connectionMap);
while (it.next())
{
it.getValue()->send(out_message, nullptr, 130); // 130 = binary
}
}
void SimpleWebSocketServer::sendTo(const String& message, const String& id)
{
if (connectionMap.contains(id))
{
connectionMap[id]->send(message.toStdString());
}
else
{
DBG("Websocket connection not found : " << id);
}
}
void SimpleWebSocketServer::sendTo(const MemoryBlock& data, const String& id)
{
std::shared_ptr<WsServer::OutMessage> out_message = std::make_shared<WsServer::OutMessage>();
out_message->write((const char*) data.getData(), data.getSize());
if (connectionMap.contains(id))
{
connectionMap[id]->send(out_message, nullptr, 130); // 130 = binary
}
else
{
DBG("Websocket connection not found : " << id);
}
}
void SimpleWebSocketServer::sendExclude(const String& message, const StringArray excludeIds)
{
HashMap<String, std::shared_ptr<WsServer::Connection>, DefaultHashFunctions, CriticalSection>::Iterator it(connectionMap);
while (it.next())
{
if (excludeIds.contains(it.getKey()))
{
continue;
}
it.getValue()->send(message.toStdString());
}
}
void SimpleWebSocketServer::sendExclude(const MemoryBlock& data, const StringArray excludeIds)
{
std::shared_ptr<WsServer::OutMessage> out_message = std::make_shared<WsServer::OutMessage>();
out_message->write((const char*) data.getData(), data.getSize());
HashMap<String, std::shared_ptr<WsServer::Connection>, DefaultHashFunctions, CriticalSection>::Iterator it(connectionMap);
while (it.next())
{
if (excludeIds.contains(it.getKey()))
{
continue;
}
it.getValue()->send(out_message, nullptr, 130); // 130 = binary
}
}
void SimpleWebSocketServer::stopInternal()
{
if (ioService != nullptr)
{
ioService->stop();
}
ScopedLock lock(serverLock);
if (ws != nullptr)
{
std::unordered_set<std::shared_ptr<WsServer::Connection>> connections = ws->get_connections();
for (auto& c : connections)
{
c->send_close(1000, "Server destroyed");
}
connectionMap.clear();
ws->stop();
}
if (http != nullptr)
{
http->stop();
}
ws.reset();
http.reset();
ioService.reset();
stopThread(1000);
}
void SimpleWebSocketServer::closeConnectionInternal(const String& id, int code, const String& reason)
{
if (!connectionMap.contains(id))
{
return;
}
connectionMap[id]->send_close(code, reason.toStdString());
}
void SimpleWebSocketServer::initServer()
{
ScopedLock lock(serverLock);
try
{
ioService = std::make_shared<asio::io_service>();
DBG("HTTP create");
http.reset(new HttpServer());
if (localAddress.isNotEmpty())
{
http->config.address = localAddress.toStdString();
}
http->config.port = port;
http->io_service = ioService;
std::function<void(std::shared_ptr<HttpServer::Response>, std::shared_ptr<HttpServer::Request>)> httpCallbackFunc = std::bind(&SimpleWebSocketServer::httpDefaultCallback, this, std::placeholders::_1, std::placeholders::_2);
http->default_resource["GET"] = httpCallbackFunc;
http->default_resource["POST"] = httpCallbackFunc;
http->default_resource["PUT"] = httpCallbackFunc;
http->default_resource["DELETE"] = httpCallbackFunc;
http->default_resource["PATCH"] = httpCallbackFunc;
http->on_upgrade = std::bind(&SimpleWebSocketServer::onHTTPUpgrade, this, std::placeholders::_1, std::placeholders::_2);
// WebSocket init
DBG("WS create");
ws.reset(new WsServer());
auto& wsEndpoint = ws->endpoint[("^" + wsSuffix + "/?$").toStdString()];
wsEndpoint.on_message = std::bind(&SimpleWebSocketServer::onMessageCallback, this, std::placeholders::_1, std::placeholders::_2);
wsEndpoint.on_error = std::bind(&SimpleWebSocketServer::onErrorCallback, this, std::placeholders::_1, std::placeholders::_2);
wsEndpoint.on_open = std::bind(&SimpleWebSocketServer::onNewConnectionCallback, this, std::placeholders::_1);
wsEndpoint.on_close = std::bind(&SimpleWebSocketServer::onConnectionCloseCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
http->config.timeout_request = 1;
http->config.timeout_content = 300;
http->config.max_request_streambuf_size = 1000000;
http->config.thread_pool_size = 4;
http->config.reuse_address = allowAddressReuse;
DBG("Http start");
http->start(std::bind(&SimpleWebSocketServer::httpStartCallback, this, std::placeholders::_1));
DBG("Service run");
isConnected = true;
isConnecting = false;
webSocketListeners.call(&Listener::serverInitSuccess);
if (ioService != nullptr)
{
ioService->run();
}
}
catch (std::exception e)
{
DBG("Error init server " << e.what());
webSocketListeners.call(&Listener::serverInitError, e.what());
}
}
int SimpleWebSocketServer::getNumActiveConnections() const
{
return connectionMap.size();
}
String SimpleWebSocketServer::getConnectionString(std::shared_ptr<WsServer::Connection> connection) const
{
return String(connection->remote_endpoint().address().to_string()) + ":" + String(connection->remote_endpoint().port());
}
void SimpleWebSocketServerBase::serveFile(const File& file, std::shared_ptr<HttpServer::Response> response)
{
String contentType = MIMETypes::getMIMEType(file.getFileExtension());
bool fileIsText = contentType.contains("text") || contentType.contains("json") || contentType.contains("script") || contentType.contains("css");
SimpleWeb::CaseInsensitiveMultimap header;
header.emplace("Content-Length", String(file.getSize()).toStdString());
header.emplace("Content-Type", contentType.toStdString());
header.emplace("Accept-range", "bytes");
header.emplace("Access-Control-Allow-Origin", "*");
response->write(SimpleWeb::StatusCode::success_ok, header);
if (fileIsText)
{
*response << file.loadFileAsString().toStdString();
}
else
{
MemoryBlock b;
std::unique_ptr<FileInputStream> fs = file.createInputStream();
fs->readIntoMemoryBlock(b);
response->write((const char*) b.getData(), b.getSize());
}
}
void SimpleWebSocketServerBase::serveFile(const File& file, std::shared_ptr<HttpsServer::Response> response)
{
String contentType = MIMETypes::getMIMEType(file.getFileExtension());
bool fileIsText = contentType.contains("text") || contentType.contains("json") || contentType.contains("script") || contentType.contains("css");
SimpleWeb::CaseInsensitiveMultimap header;
header.emplace("Content-Length", String(file.getSize()).toStdString());
header.emplace("Content-Type", contentType.toStdString());
header.emplace("Accept-range", "bytes");
header.emplace("Access-Control-Allow-Origin", "*");
response->write(SimpleWeb::StatusCode::success_ok, header);
if (fileIsText)
{
*response << file.loadFileAsString().toStdString();
}
else
{
MemoryBlock b;
std::unique_ptr<FileInputStream> fs = file.createInputStream();
fs->readIntoMemoryBlock(b);
response->write((const char*) b.getData(), b.getSize());
}
}
void SimpleWebSocketServer::onMessageCallback(std::shared_ptr<WsServer::Connection> connection, std::shared_ptr<WsServer::InMessage> in_message)
{
String id = getConnectionString(connection);
if (in_message->fin_rsv_opcode == 129)
{
webSocketListeners.call(&Listener::messageReceived, id, String(in_message->string()));
}
else if (in_message->fin_rsv_opcode == 130)
{
MemoryBlock b(in_message->string().c_str(), in_message->size());
webSocketListeners.call(&Listener::dataReceived, id, b);
}
else if (in_message->fin_rsv_opcode == 136)
{
DBG("Connection ended for " << id);
}
}
void SimpleWebSocketServer::onNewConnectionCallback(std::shared_ptr<WsServer::Connection> connection)
{
String id = getConnectionString(connection);
connectionMap.set(id, connection);
webSocketListeners.call(&Listener::connectionOpened, id);
}
void SimpleWebSocketServer::onConnectionCloseCallback(std::shared_ptr<WsServer::Connection> connection, int status, const std::string& reason)
{
String id = getConnectionString(connection);
connectionMap.remove(id);
webSocketListeners.call(&Listener::connectionClosed, id, status, reason);
}
void SimpleWebSocketServer::onErrorCallback(std::shared_ptr<WsServer::Connection> connection, const SimpleWeb::error_code& ec)
{
String id = getConnectionString(connection);
connectionMap.remove(id);
webSocketListeners.call(&Listener::connectionError, id, ec.message());
}
void SimpleWebSocketServer::httpStartCallback(unsigned short _port)
{
isConnected = port == _port;
}
void SimpleWebSocketServer::onHTTPUpgrade(std::unique_ptr<SimpleWeb::HTTP>& socket, std::shared_ptr<HttpServer::Request> request)
{
jassert(ws != nullptr);
auto connection = std::make_shared<WsServer::Connection>(std::move(socket));
connection->method = std::move(request->method);
connection->path = std::move(request->path);
connection->http_version = std::move(request->http_version);
connection->header = std::move(request->header);
ws->upgrade(connection);
}
void SimpleWebSocketServer::httpDefaultCallback(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request)
{
for (auto& secondaryHandler : handlers)
{
if (secondaryHandler->handleHTTPRequest(response, request))
{
return;
}
}
if (rootPath.exists() && rootPath.isDirectory())
{
// String content = "";
String contentType = "text/html";
File f;
String path = request->path.substr(1);
if (path.isEmpty())
{
path = "index.html";
}
f = rootPath.getChildFile(path); // substr to remove the first "/"
if (f.exists() && f.isDirectory())
{
f = f.getChildFile("index.html");
}
if (f.existsAsFile())
{
// check that file is not outside rootPath
if (!f.isAChildOf(rootPath))
{
*response << "HTTP/1.1 403 Forbidden";
serveFile(rootPath.getChildFile("403.html"), response);
return;
}
serveFile(f, response);
return;
}
else
{
DBG("WebServer requested file not found : " << f.getFullPathName());
}
}
*response << "HTTP/1.1 404 Not Found";
}
// SECURE
#if SIMPLEWEB_SECURE_SUPPORTED
SecureWebSocketServer::SecureWebSocketServer(const String& certFile, const String& privateKeyFile, const String& verifyFile) : certFile(certFile), keyFile(privateKeyFile), verifyFile(verifyFile) {}
SecureWebSocketServer::~SecureWebSocketServer()
{
stop();
}
void SecureWebSocketServer::send(const String& message)
{
HashMap<String, std::shared_ptr<WssServer::Connection>>::Iterator it(connectionMap);
while (it.next())
{
it.getValue()->send(message.toStdString());
}
}
void SecureWebSocketServer::send(const char* data, int numData)
{
std::shared_ptr<WssServer::OutMessage> out_message = std::make_shared<WssServer::OutMessage>();
out_message->write(data, numData);
HashMap<String, std::shared_ptr<WssServer::Connection>>::Iterator it(connectionMap);
while (it.next())
{
it.getValue()->send(out_message, nullptr, 130); // 130 = binary
}
}
void SecureWebSocketServer::sendTo(const String& message, const String& id)
{
if (connectionMap.contains(id))
{
connectionMap[id]->send(message.toStdString());
}
else
{
DBG("[Dashboard] Websocket connection not found : " << id);
}
}
void SecureWebSocketServer::sendTo(const MemoryBlock& data, const String& id)
{
std::shared_ptr<WssServer::OutMessage> out_message = std::make_shared<WssServer::OutMessage>();
out_message->write((const char*) data.getData(), data.getSize());
if (connectionMap.contains(id))
{
connectionMap[id]->send(out_message, nullptr, 130); // 130 = binary
}
else
{
DBG("[Dashboard] Websocket connection not found : " << id);
}
}
void SecureWebSocketServer::sendExclude(const String& message, const StringArray excludeIds)
{
HashMap<String, std::shared_ptr<WssServer::Connection>>::Iterator it(connectionMap);
while (it.next())
{
if (excludeIds.contains(it.getKey()))
{
continue;
}
it.getValue()->send(message.toStdString());
}
}
void SecureWebSocketServer::sendExclude(const MemoryBlock& data, const StringArray excludeIds)
{
std::shared_ptr<WssServer::OutMessage> out_message = std::make_shared<WssServer::OutMessage>();
out_message->write((const char*) data.getData(), data.getSize());
HashMap<String, std::shared_ptr<WssServer::Connection>>::Iterator it(connectionMap);
while (it.next())
{
if (excludeIds.contains(it.getKey()))
{
continue;
}
it.getValue()->send(out_message, nullptr, 130); // 130 = binary
}
}
void SecureWebSocketServer::stopInternal()
{
if (ioService != nullptr)
{
ioService->stop();
}
ScopedLock lock(serverLock);
if (ws != nullptr)
{
std::unordered_set<std::shared_ptr<WssServer::Connection>> connections = ws->get_connections();
for (auto& c : connections)
{
c->send_close(1000, "Server destroyed");
}
connectionMap.clear();
ws->stop();
}
if (http != nullptr)
{
http->stop();
}
ws.reset();
http.reset();
ioService.reset();
}
void SecureWebSocketServer::closeConnectionInternal(const String& id, int code, const String& reason)
{
if (!connectionMap.contains(id))
{
return;
}
connectionMap[id]->send_close(code, reason.toStdString());
}
void SecureWebSocketServer::initServer()
{
ScopedLock lock(serverLock);
try
{
ioService = std::make_shared<asio::io_service>();
http.reset(new HttpsServer(certFile.toStdString(), keyFile.toStdString(), verifyFile.toStdString()));
http->config.port = port;
http->io_service = ioService;
http->default_resource["GET"] = std::bind(&SecureWebSocketServer::httpDefaultCallback, this, std::placeholders::_1, std::placeholders::_2);
http->on_upgrade = std::bind(&SecureWebSocketServer::onHTTPUpgrade, this, std::placeholders::_1, std::placeholders::_2);
// WebSocket init
ws.reset(new WssServer(certFile.toStdString(), keyFile.toStdString(), verifyFile.toStdString()));
// ws->config.timeout_idle = 1;
ws->config.timeout_request = 2;
auto& wsEndpoint = ws->endpoint[("^" + wsSuffix + "/?$").toStdString()];
wsEndpoint.on_message = std::bind(&SecureWebSocketServer::onMessageCallback, this, std::placeholders::_1, std::placeholders::_2);
wsEndpoint.on_error = std::bind(&SecureWebSocketServer::onErrorCallback, this, std::placeholders::_1, std::placeholders::_2);
wsEndpoint.on_open = std::bind(&SecureWebSocketServer::onNewConnectionCallback, this, std::placeholders::_1);
wsEndpoint.on_close = std::bind(&SecureWebSocketServer::onConnectionCloseCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
http->config.timeout_request = 1;
http->config.timeout_content = 2;
http->config.max_request_streambuf_size = 1000000;
http->config.thread_pool_size = 2;
http->config.reuse_address = allowAddressReuse;
http->start(std::bind(&SecureWebSocketServer::httpStartCallback, this, std::placeholders::_1));
isConnected = true;
isConnecting = false;
webSocketListeners.call(&Listener::serverInitSuccess);
if (ioService != nullptr)
{
ioService->run();
}
}
catch (std::exception e)
{
DBG("Error init server " << e.what());
webSocketListeners.call(&Listener::serverInitError, e.what());
}
}
int SecureWebSocketServer::getNumActiveConnections() const
{
return connectionMap.size();
}
String SecureWebSocketServer::getConnectionString(std::shared_ptr<WssServer::Connection> connection) const
{
return String(connection->remote_endpoint().address().to_string()) + ":" + String(connection->remote_endpoint().port());
}
void SecureWebSocketServer::onMessageCallback(std::shared_ptr<WssServer::Connection> connection, std::shared_ptr<WssServer::InMessage> in_message)
{
String id = getConnectionString(connection);
if (in_message->fin_rsv_opcode == 129)
{
webSocketListeners.call(&Listener::messageReceived, id, String(in_message->string()));
}
else if (in_message->fin_rsv_opcode == 130)
{
webSocketListeners.call(&Listener::dataReceived, id, in_message->binary);
}
else if (in_message->fin_rsv_opcode == 136)
{
DBG("Connection ended for " << id);
}
}
void SecureWebSocketServer::onNewConnectionCallback(std::shared_ptr<WssServer::Connection> connection)
{
String id = getConnectionString(connection);
connectionMap.set(id, connection);
webSocketListeners.call(&Listener::connectionOpened, id);
}
void SecureWebSocketServer::onConnectionCloseCallback(std::shared_ptr<WssServer::Connection> connection, int status, const std::string& reason)
{
String id = getConnectionString(connection);
connectionMap.remove(id);
webSocketListeners.call(&Listener::connectionClosed, id, status, reason);
}
void SecureWebSocketServer::onErrorCallback(std::shared_ptr<WssServer::Connection> connection, const SimpleWeb::error_code& ec)
{
String id = getConnectionString(connection);
connectionMap.remove(id);
webSocketListeners.call(&Listener::connectionError, id, ec.message());
}
void SecureWebSocketServer::httpStartCallback(unsigned short _port)
{
isConnected = port == _port;
}
void SecureWebSocketServer::onHTTPUpgrade(std::unique_ptr<SimpleWeb::HTTPS>& socket, std::shared_ptr<HttpsServer::Request> request)
{
jassert(ws != nullptr);
auto connection = std::make_shared<WssServer::Connection>(std::move(socket));
connection->method = std::move(request->method);
connection->path = std::move(request->path);
connection->http_version = std::move(request->http_version);
connection->header = std::move(request->header);
ws->upgrade(connection);
}
void SecureWebSocketServer::httpDefaultCallback(std::shared_ptr<HttpsServer::Response> response, std::shared_ptr<HttpsServer::Request> request)
{
for (auto& handler : handlers)
{
if (handler->handleHTTPSRequest(response, request))
{
return;
}
}
if (rootPath.exists() && rootPath.isDirectory())
{
// String content = "";
File f;
String path = request->path.substr(1);
if (path.isEmpty())
{
path = "index.html";
}
f = rootPath.getChildFile(path); // substr to remove the first "/"
if (f.exists() && f.isDirectory())
{
f = f.getChildFile("index.html");
}
if (f.existsAsFile())
{
serveFile(f, response);
return;
}
else
{
DBG("WebServer requested file not found : " << f.getFullPathName());
}
}
*response << "HTTP/1.1 404 Not Found";
}
#endif