Commit Graph

198 Commits

Author SHA1 Message Date
Greg Lincoln 46eebddd76 Allow "default" headers to be defined for all responses. (#230)
* Add DefaultHeaders singleton.

* Add documentation for DefaultHeaders.
2017-09-18 13:15:49 +08:00
me-no-dev b681dbc3cd Add cache for the editor
Idea from:
http://tinkerman.cat/embed-your-website-in-your-esp8266-firmware-image/
2017-09-12 23:30:11 +03:00
me-no-dev 3e6690396a Some small adjustments for ESP32
- bump version
- remove compilation warnings
- do not require SPIFFS
2017-09-09 09:04:50 +03:00
me-no-dev 75fb9573e8 Make SPIFFSEditor work with other file systems (ESP32) 2017-09-08 13:36:24 +03:00
arantius fe080dc07e Address compilation warning. (#209)
Specifically: "warning: comparison between signed and unsigned integer
expressions".  Make `i` the same type as `len`, which it is frequently
compared to.
2017-09-07 22:02:46 +03:00
me-no-dev d37bd16c22 Initial ESP32 compatibility 2017-09-07 22:01:58 +03:00
Alexandr Zarubkin 30f9dab08d Fixed chunked file response length. (#219)
Signed-off-by: Alexandr Zarubkin <me21@yandex.ru>
2017-09-05 20:13:16 +03:00
Alexandr Zarubkin e6c432e563 Something got lost during pull request #189. Fixes #211, updates documentation. (#213)
* Removed unnecessary memmove from chunked response generation.

* Added simple template processor to AsyncFileResponse.

Unzipped files in SPIFFS, Streams, PROGMEM strings, callback/chunked responses may have template placeholders like %TEMPLATE_VAR% inside. If callback is specified in Async...Response constructor call, it will be used to replace these with actual strings.
The prototype of callback is String(const String&), i.e. it gets variable name and returns its value.
Template variables' delimiter is currently percent sign ('%').
Maximal placeholder length is 32 chars (chosen somewhat arbitrarily, it may be stored on stack during processing). It is not guaranteed that placeholders longer than that will be processed.

Signed-off-by: Alexandr Zarubkin <me21@yandex.ru>
2017-08-31 19:44:23 +03:00
Me No Dev 2540507664 The following changes and enhancements are included: (#208)
- Added "SAVE-Button
- Upgraded to ACE 1.2.6
- Added additional field, which shows name of the current edited File
- Reset upload path after uploading or creating a File (avoid confusion about which file is shown in editor)
- added the possibility, to run the editor completly from flash. When ace.js.gz or ace.js and the corresponding files are found on SPIFFS, the editor can be used in AP mode also.  Otherwise the files are searched on cloudflare like before.
- added all gzipped js-files in data directory
- added an exclude list, containing wildcards, telling which files should not be listed in the editor (to prevent deletion of needed files)
- minified the embedded HTML/Javascript with https://kangax.github.io/html-minifier/ before gzipping.  With all additions the resulting hex-code is now 700 bytes smaller
- embedded the plain html as documentation
2017-08-18 20:14:12 +03:00
Alexandr Zarubkin 0179c17cf9 Added simple template processor to AsyncFileResponse. (#189)
Unzipped files in SPIFFS, Streams, PROGMEM strings, callback/chunked responses may have template placeholders like %TEMPLATE_VAR% inside. If callback is specified in Async...Response constructor call, it will be used to replace these with actual strings.
The prototype of callback is String(const String&), i.e. it gets variable name and returns its value.
Template variables' delimiter is currently percent sign ('%').
Maximal placeholder length is 32 chars (chosen somewhat arbitrarily, it may be stored on stack during processing). It is not guaranteed that placeholders longer than that will be processed.

Signed-off-by: Alexandr Zarubkin <me21@yandex.ru>

# Conflicts:
#	src/WebResponses.cpp
2017-08-18 17:59:06 +03:00
Me No Dev 77a520ba24 This commit solves issues 172 and 198 (#207)
* This commit solves issues 172 and 198

* This commit solves issues 172 and 198
2017-08-18 17:52:21 +03:00
Me No Dev 05ed854d7b Update SPIFFSEditor.cpp
Fix URL Encode logic
2017-08-18 17:41:31 +03:00
Alexandr Zarubkin 4dcd458d13 Removed unnecessary memmove from chunked response generation. (#188) 2017-08-18 11:54:52 +03:00
Mariusz Kryński 3d0cf89d58 Fix url decoding in POST / GET requests (#185) 2017-08-18 11:53:57 +03:00
probonopd 2e6dff35bd Allow for double quotes in boundary, closes #191 (#192)
https://tools.ietf.org/html/rfc2046#section-5.1.1
2017-08-17 20:17:21 +03:00
omersiar e56e1a6370 Bug Fix for #175 and #167 (#182)
Prevent double MD5 hashing
2017-06-21 12:37:19 +02:00
Trygve Laugstøl be12e0c171 Fixing compiler warnings exposed with -Wall and -Wextra: (#159)
AsyncWebHandler::setAuthentication: return is required.
AsyncWebSocketMultiMessage::~AsyncWebSocketMultiMessage: error: enumeral and non-enumeral type in conditional expression.
2017-04-20 11:14:00 +03:00
Trygve Laugstøl 2c4128c7cd Minor cleanup of AsyncWebServer, removing unneeded casts. (#156) 2017-04-10 17:10:02 +03:00
Alexandr Zarubkin ab61227a8a The previous event need not be ACKed to send the next one (it will be queued). (#149)
Signed-off-by: Alexandr Zarubkin <me21@yandex.ru>
2017-04-06 10:11:48 +02:00
Charles 120984e6d2 Added getSize() to know JSON buffer size (#151)
* Added doc for ws.enable and ws.enabled

* added getSize()
2017-04-06 10:10:59 +02:00
probonopd 09dde693ba Solve error "previous definition of 'class fs::File'" (#147)
As per https://github.com/me-no-dev/ESPAsyncWebServer/issues/111#issuecomment-288265916 by @boblemaire
2017-03-22 10:23:37 +01:00
sticilface 1b35f15ec2 Web Sockets memory improvements : shared message buffer, direct buffer access (#144)
* Add support for a MultiMessage where the buffer is shared between WS messages to multiple clients.
Add ability to create a WS buffer directly and write to it, saving duplication of message in RAM, then send it.  example below is an arduinoJson message.

```cpp
void sendDataWs(AsyncWebSocketClient * client)
{
    DynamicJsonBuffer jsonBuffer;
    JsonObject& root = jsonBuffer.createObject();
    root["a"] = "abc";
    root["b"] = "abcd";
    root["c"] = "abcde";
    root["d"] = "abcdef";
    root["e"] = "abcdefg";
    size_t len = root.measureLength();
    AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); //  creates a buffer (len + 1) for you.
    if (buffer) {
        root.printTo((char *)buffer->get(), len + 1);
        if (client) {
            client->text(buffer);
        } else {
            ws.textAll(buffer);
        }
    }
}
```

* Add example to readme.
2017-03-14 14:55:39 +01:00
sticilface b9641902bf Events Source Message Queue (#129)
* Events Source Message Queue
 - Fixes problem where events sent close together are silently dropped.

* Update AsyncEventSource.cpp

error
2017-03-11 09:57:37 +01:00
Zhenyu Wu fce6aad2c3 Remove Rx timeout constraint in the request response stage, fix premature connection termination (#121) 2017-03-05 20:15:25 +02:00
sticilface edf6c75f8c Fix memory leak in __flashString Web sockets implementation. (#136) 2017-03-05 20:07:17 +02:00
sticilface 3afc669f10 Flash String support (#137)
* Flash String support

* use strlen_P and strcpy_p
2017-03-05 20:06:57 +02:00
Tuan PM 9b66da2c92 Add basic auth for server static (#143)
* Add basic auth for server static

* Also effect to Websocket

* Add http basic auth for event source & document to README.md
2017-03-05 20:02:33 +02:00
Me No Dev bab5457584 Fix case where space is not enough for a chunk 2017-01-25 21:25:21 +02:00
Zhenyu Wu 213387b88f Convert resursive call to iterations, reduce stack usage (#120) 2017-01-22 12:47:21 +02:00
Luc 5159d8b845 Fix #76 Problem uploading multiple files (#104) 2016-11-29 23:12:52 +02:00
Sakari Kapanen ea7b76b0ee Fix const correctness of _sourceValid (#100) 2016-11-28 22:00:33 +02:00
Max Lunin a7c4dfb04f Template container instead of direct pointer manipulation. (#95)
* using Container instead ofdirect pointers list manipulation

* fixed different type of virtual methods.

* Fixed typo in conditional

* Renamed ListArray to LinkedList

* Const reference to String as method parameters to prevent additional copy and memory allocation when String passed by value

* fix 'min' redefinition

* removed #include <iterator>
begin/end methods it's enough for 'for( : )' loop
count() renamed to length()
spacing fixing

* Const reference to String as method parameters to prevent additional copy and memory allocation when String passed by value

* Fixed unused params warnings
2016-11-27 17:42:09 +02:00
me-no-dev 41c57bcdd1 add size to returned file data 2016-11-17 01:33:50 +02:00
Max Lunin 3eb639b027 Reset all handlers. This allowing to use same server few times (#93)
* Reset all handlers. This allowing to use same server few times during app life.
E.g. for WiFi manager when hardware sepups WiFi connection and as HTTP server during hardware life cycle
2016-11-17 01:16:58 +02:00
Me No Dev 49d5a24815 fix Digest authentication for IE 2016-10-18 16:30:14 +03:00
me-no-dev 0adc36b1f6 fix mistake 2016-09-23 21:56:28 +03:00
me-no-dev 1fd73a9262 disable timeout for web sockets and event source 2016-09-23 21:44:52 +03:00
me-no-dev a39051a2d5 Add SPIFFSEditor to the library 2016-09-23 15:11:50 +03:00
me-no-dev d935b1d740 close the file if left open and add timeout to clients 2016-09-23 13:48:35 +03:00
me-no-dev c2de999f03 fix broken uploads 2016-09-03 23:30:14 +03:00
Me No Dev b6c9ebd9e6 make headers work with ignoreCase
Connected to: https://github.com/me-no-dev/ESPAsyncWebServer/issues/64
Eliminates: https://github.com/me-no-dev/ESPAsyncWebServer/pull/70
2016-09-02 13:52:32 +03:00
Me No Dev 18478e6520 do not compile SSL if disabled 2016-08-26 02:44:20 +03:00
Me No Dev 9ae9976b05 return 304 if file uses cache and size has not changed 2016-08-25 22:29:27 +03:00
Me No Dev 1163808495 add some mime types and a commented implementation of etag for cache 2016-08-25 22:15:17 +03:00
Me No Dev a14e93dd84 Initial SSL Implementation 2016-08-24 22:32:27 +03:00
Me No Dev dab3077f2b pointless 2016-08-23 08:02:04 +03:00
Me No Dev 7110758b5a optimizations 2016-08-23 03:10:45 +03:00
Me No Dev 7f9bdec0f9 use uint8_t to store WebRequestMethod (#68)
so we can have server.on("/foo", HTTP_GET | HTTP_POST,
[](AsyncWebServerRequest *request) {}) to handle multiple methods.

this also saves a bit memory, enums are stored in int, which is 32bit on
xtensa. since we only have 7 methods (plus HTTP_ANY for everything) we
only want 7 bit, so uint8_t is pretty sufficient.
2016-08-19 22:21:08 +03:00
Me No Dev 46d41ddcd4 Update for ESP32 RTOS SDK 3.0.0 2016-08-02 14:28:21 +03:00
Sergey Anisimov b3db252acb Passing String parameters by const ref. (#57) 2016-07-25 20:07:02 +03:00
Me No Dev cc38b8d57c fix some methods and add setCode to all responses 2016-07-22 00:03:12 +03:00
Me No Dev d61cc2d130 Implement sending content from progmem
make the example editor run from progmem
2016-07-21 12:25:25 +03:00
Me No Dev 933ac023cb Optimizations 2016-07-14 00:01:34 +03:00
Me No Dev b8ba1c885b Add EventSource::count() 2016-06-30 11:26:20 +03:00
Me No Dev 330027a8de close event gracefully so pending messages get sent as well 2016-06-29 21:44:33 +03:00
Me No Dev acd03d5071 syntax error 2016-06-29 21:26:41 +03:00
Me No Dev 8399f0bcb9 add collection of LastEventId header 2016-06-29 21:21:10 +03:00
Me No Dev a5674fab69 fix onConnect not being called if there are no clients 2016-06-29 20:50:00 +03:00
Me No Dev 0d02922e52 Add onConnect callback to EventSources
usage:
  AsyncEventSource events("/events");
  events.onConnect([](AsyncEventSourceClient *client){
    client->send("Hello!",NULL,0,1000);
  });
  server.addHandler(&events);
  ...
  events.send("boot finished","system");//send "system" event
2016-06-29 19:29:39 +03:00
Me No Dev 49b6046125 Add Digest Web Authentication and make it default
accept htdigest formatted hashes as well
2016-06-29 16:20:03 +03:00
Me No Dev cdd1ced67a Add EventSource plugin 2016-06-28 21:51:48 +03:00
Me No Dev dce6d35ad4 close the web socket instead of aborting it
latest ESPAsyncTCP commits are needed for this to properly work
fixing: https://github.com/me-no-dev/ESPAsyncWebServer/issues/48
2016-06-28 13:35:32 +03:00
Me No Dev 082e6e7039 disable some functions on ESP31B 2016-06-28 01:45:43 +03:00
Me No Dev b02d4a03a7 allow last modified to be also set to time_t or current time
to start sntp:
```cpp
void startSNTP(){
  time_t rawtime;
  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
  while(time(&rawtime) == 0) delay(10);
}
```
2016-06-28 01:39:35 +03:00
Me No Dev e3e7a5e91e add option to set last modified from struct tm 2016-06-27 20:08:09 +03:00
Me No Dev f8141fcd0e fix warning about setting String to NULL 2016-06-26 16:21:44 +03:00
Me No Dev e5a6999582 add request->redirect(url) 2016-06-26 16:20:21 +03:00
Hagai Shatz afb7dd688a New - rewrite, filters and last-modified (#47)
* New - server.rewirte() to rewrite the request url with optional get parameters injection.
New - rewrite.setFilter() and handler.setFilter() to specify a filter callback for more control on when to include them.
New - static file handler can be set with Last-Modified header value to support Not-Modified (304) response instead of serving the actual file.

* Remove clearRewrites & clearHandlers from server.mplement server distractor to delete internal members. Fixed and improved gzip stats calculation.
2016-06-25 22:04:06 +03:00
Hagai Shatz 11b7bd1d3a Fix bug in AsyncStaticWebHandler (#37)
* HTTP 302 and 304 Support

Add support for http redirection (302) and http not modified (304) to
reduce the load the server.
server.redirect(“url”, “location”, exclude-ip) will respond with 302 to
redirect the browser to a different url, this is useful for backward
compatibility and to redirect call to CDN when not no AP mode.
server.serveStatic has a new optional parameter to get the
Last-Modified date for all files serve for this location, when the
browser request have the same If-Modified-Since header value, the
server respond with 304 code instead of serving the file.

* Fix path problems in static handler and improve performance.

* Revert "Merge remote-tracking branch 'me-no-dev/master'"

This reverts commit 1621206357843b5de0272fe4579387af3011e656, reversing
changes made to a01972c9e569967dd3d761c364066518b4901e46.

* Revert "HTTP 302 and 304 Support"

This reverts commit a01972c9e569967dd3d761c364066518b4901e46.

* Sync with me-no-dev/master

* Fix AsyncStaticWebHandler

Fix ambiguity of serving file or directory.
The following options will all have the same outcome, the last two will
server the default file ‘index.htm’ faster:
server.serveStatic("/fs", SPIFFS, "/web");
server.serveStatic("/fs/", SPIFFS, "/web");
server.serveStatic("/fs", SPIFFS, "/web/");
server.serveStatic("/fs/", SPIFFS, "/web/");
2016-06-18 19:43:52 +03:00
Me No Dev e46d4d7418 fix broken send of gzipped files 2016-06-18 01:28:36 +03:00
Hagai Shatz 89b19e8cde Bug fix (#45)
* HTTP 302 and 304 Support

Add support for http redirection (302) and http not modified (304) to
reduce the load the server.
server.redirect(“url”, “location”, exclude-ip) will respond with 302 to
redirect the browser to a different url, this is useful for backward
compatibility and to redirect call to CDN when not no AP mode.
server.serveStatic has a new optional parameter to get the
Last-Modified date for all files serve for this location, when the
browser request have the same If-Modified-Since header value, the
server respond with 304 code instead of serving the file.

* First round of performance improvements.

* Merge remote-tracking branch 'me-no-dev/master' into performance

# Conflicts:
#	src/WebHandlerImpl.h
#	src/WebHandlers.cpp

* use of sprintf

* Remove sections not related.

* Fix a bug to serve a file in directory (e.g. serverStatic("/", SPIFFS, "/index.html");
2016-06-18 00:32:09 +03:00
Hagai Shatz b63a86eba8 Performance (#44)
* HTTP 302 and 304 Support

Add support for http redirection (302) and http not modified (304) to
reduce the load the server.
server.redirect(“url”, “location”, exclude-ip) will respond with 302 to
redirect the browser to a different url, this is useful for backward
compatibility and to redirect call to CDN when not no AP mode.
server.serveStatic has a new optional parameter to get the
Last-Modified date for all files serve for this location, when the
browser request have the same If-Modified-Since header value, the
server respond with 304 code instead of serving the file.

* First round of performance improvements.

* Merge remote-tracking branch 'me-no-dev/master' into performance

# Conflicts:
#	src/WebHandlerImpl.h
#	src/WebHandlers.cpp

* use of sprintf

* Remove sections not related.
2016-06-17 17:42:47 +03:00
Me No Dev 5bbc732028 remove Access-Control-Allow-Origin 2016-06-17 17:41:06 +03:00
Clemens Kirchgatterer 78fc89d462 filename quote changed from ' to " (#43)
now for real. :-)
2016-06-17 17:34:38 +03:00
Me No Dev dc5b7f708a provide original name so proper content type is set for gzipped content 2016-06-17 02:23:18 +03:00
Me No Dev d8809137a3 fix typos 2016-06-17 01:53:21 +03:00
Me No Dev 3709dd5e14 add ability to send File objects directly
utilize request's tempFile to store a handle to the file to send
use open instead of exists in static handler
2016-06-17 01:43:59 +03:00
Me No Dev 16a6016759 fix missed rename 2016-06-16 23:27:01 +03:00
Me No Dev 798fcc3c05 rename to _tempObject and give type void * so it can be used for any object/array 2016-06-16 23:24:09 +03:00
Me No Dev 41228cb246 add uint8_t * request->_tempBuffer to be used for storing body data or other request specific stuff 2016-06-16 23:09:58 +03:00
Me No Dev 5ee66e1842 send just the filename in Content-Disposition
Thanks go to: @hagai-shatz
2016-06-16 22:13:02 +03:00
Hagai Shatz a52873b451 Fix path problems in static handler and improve performance. (#41) 2016-06-16 12:52:11 +03:00
Clemens Kirchgatterer f384cd1f76 fix for file download/rendering response (#40)
tested with chromium and firefox and all content types i had handy.

chrome and firefox render all files inline, if they can. chrome downloads files when asked to download, firefox opens a download dialog.
2016-06-15 18:21:16 +03:00
sticilface ba45a834e9 This handler will serve a 302 response to a client request for a SP… (#36)
*   This handler will serve a 302 response to a client request for a SPIFFS file if the request comes from the STA side of the ESP network.
  If the request comes from the AP side then it serves the file from SPIFFS.

* corrections.  plus readme

* Update README.md

extra space

* move wifi to cpp
2016-06-10 10:46:12 +03:00
Me No Dev bda2cd637a add WebSocket auto-ping option and fix pcb not being released properly on disconnect 2016-05-28 03:50:38 +03:00
Me No Dev 2b501e74a7 add method to disable new connections to a WebSocket instance 2016-05-25 19:48:04 +03:00
Me No Dev 8171edd7e1 attempt fix on some edge cases
attempt to fix a case where \r can be missed and post not parsed
correctly
2016-05-20 00:55:20 +03:00
Charles 29b3f72e80 Added printf_P method (#31)
* Prevent buffer overflow on received data

* pass to 7 char to avoid save to flash by SDK

* return _contentLength, avoid array reparse to know len

* Added FlashStringHelper for text and binary

* Added FlashStringHelper also to AsyncWebSocketClient

* Added PROGMEM doc

* Corrected binary was sending PSTR as text, addded len

* Server calls client method and code as asked @me-no-dev

* server calls client method and code as asked by @me-no-dev

* Changed Code presentation

* Added printf_P methods
2016-05-15 03:00:33 +03:00
Me No Dev 937d442fce urlDecode the GET path 2016-05-13 00:41:21 +03:00
Me No Dev 7cb06b1bb1 fix typo 2016-05-13 00:19:50 +03:00
Me No Dev ffa893f770 Atempt at fixing large uploads
Fixing: https://github.com/me-no-dev/ESPAsyncWebServer/issues/29
2016-05-13 00:01:42 +03:00
Charles 1d275900eb Prevent Buffer Overflow and Added FlashStringHelper for text and binary (#26)
* Prevent buffer overflow on received data

* pass to 7 char to avoid save to flash by SDK

* return _contentLength, avoid array reparse to know len

* Added FlashStringHelper for text and binary

* Added FlashStringHelper also to AsyncWebSocketClient

* Added PROGMEM doc

* Corrected binary was sending PSTR as text, addded len

* Server calls client method and code as asked @me-no-dev

* server calls client method and code as asked by @me-no-dev

* Changed Code presentation
2016-05-12 15:17:35 +03:00
Charles b1492fc213 avoid client ID being 0
Prevent having clientID set to 0
When managing an array of different clientID, it's preferable to a valid
client not having it's ID set to 0
2016-05-06 16:54:15 +02:00
Me No Dev 8dfd328627 quiet debug and add access to the AsyncClient and it's IP/Port 2016-05-03 04:49:51 +03:00
Me No Dev 060183974c return json object by default 2016-05-03 03:59:49 +03:00
Me No Dev d74a84455f AsyncJson: add option to init with root as json array
ref: https://github.com/bblanchon/ArduinoJson/issues/272
2016-05-02 19:54:37 +03:00
Me No Dev 59732a09bd add proper credits 2016-04-23 17:20:51 +03:00
Me No Dev 3c3f38e6f6 fix printf eating the last charecter 2016-04-23 16:11:57 +03:00
Me No Dev 8d67809acf Add AsyncWebSocket plugin 2016-04-23 15:11:32 +03:00
Me No Dev d65e4bd4e5 collect all headers for the default handler 2016-04-20 22:26:19 +03:00