diff --git a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino index 40bb9ea294..1335c347af 100644 --- a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino +++ b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino @@ -67,6 +67,23 @@ void setup(void) { server.send(200, "text/plain", "this works as well"); }); + server.on("/gif", []() { + static const uint8_t gif[] PROGMEM = { + 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d, + 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c, + 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b + }; + char gif_colored[sizeof(gif)]; + memcpy_P(gif_colored, gif, sizeof(gif)); + // Set the background to a random set of colors + gif_colored[16] = millis() % 256; + gif_colored[17] = millis() % 256; + gif_colored[18] = millis() % 256; + server.send(200, "image/gif", gif_colored, sizeof(gif_colored)); + }); + server.onNotFound(handleNotFound); server.begin(); diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 4281ce8636..60b10249d1 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -127,6 +127,15 @@ class ESP8266WebServerTemplate void send(int code, const char* content_type = NULL, const String& content = String("")); void send(int code, char* content_type, const String& content); void send(int code, const String& content_type, const String& content); + void send(int code, const char *content_type, const char *content, size_t content_length = 0) { + if (content_length == 0) { + content_length = strlen_P(content); + } + send_P(code, content_type, content, content_length); + } + void send(int code, const char *content_type, const uint8_t *content, size_t content_length) { + send_P(code, content_type, (const char *)content, content_length); + } void send_P(int code, PGM_P content_type, PGM_P content); void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);