Skip to content

Commit aecbcff

Browse files
committed
Added image resource to show effects of Connection: keep-alive
1 parent 6336cdb commit aecbcff

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

https_server.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ void testCallback(HTTPRequest * req, HTTPResponse * res) {
2626
res->println("</head>");
2727
res->println("<body>");
2828
res->println("<h1>Hello world!</h1>");
29-
res->println("<p>From your ESP32</p>");
29+
res->println("<p>... from your ESP32</p>");
30+
// The image resource is created in the awesomeCallback some lines below
31+
res->println("<img src=\"images/awesome.svg\" alt=\"Awesome face\" />");
3032
res->print("<p>System has been up for ");
3133
res->print((int)(millis()/1000), DEC);
3234
res->println(" seconds.</p>");
@@ -46,6 +48,27 @@ void faviconCallback(HTTPRequest * req, HTTPResponse * res) {
4648
res->write(FAVICON_DATA, FAVICON_LENGTH);
4749
}
4850

51+
void awesomeCallback(HTTPRequest * req, HTTPResponse * res) {
52+
res->setHeader("Content-Type", "image/svg+xml");
53+
// We can write anything here :)
54+
res->setStatusText("Awesome");
55+
56+
// Print the data
57+
// Source: https://commons.wikimedia.org/wiki/File:718smiley.svg
58+
res->print("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
59+
res->print("<svg id=\"svg1923\" width=\"733\" xmlns=\"http://www.w3.org/2000/svg\" height=\"733\">");
60+
res->print("<circle cy=\"366.5\" cx=\"366.5\" r=\"366.5\"/>");
61+
res->print("<circle cy=\"366.5\" cx=\"366.5\" r=\"336.5\" fill=\"#fede58\"/>");
62+
res->print("<path d=\"m325 665c-121-21-194-115-212-233v-8l-25-1-1-18h481c6 13 10 27 13 41 13 94-38 146-114 193-45 23-93 29-142 26z\"/>");
63+
res->print("<path d=\"m372 647c52-6 98-28 138-62 28-25 46-56 51-87 4-20 1-57-5-70l-423-1c-2 56 39 118 74 157 31 34 72 54 116 63 11 2 38 2 49 0z\" fill=\"#871945\"/>");
64+
res->print("<path d=\"m76 342c-13-26-13-57-9-85 6-27 18-52 35-68 21-20 50-23 77-18 15 4 28 12 39 23 18 17 30 40 36 67 4 20 4 41 0 60l-6 21z\"/>");
65+
res->print("<path d=\"m234 323c5-6 6-40 2-58-3-16-4-16-10-10-14 14-38 14-52 0-15-18-12-41 6-55 3-3 5-5 5-6-1-4-22-8-34-7-42 4-57.6 40-66.2 77-3 17-1 53 4 59h145.2z\" fill=\"#fff\"/>");
66+
res->print("<path d=\"m378 343c-2-3-6-20-7-29-5-28-1-57 11-83 15-30 41-52 72-60 29-7 57 0 82 15 26 17 45 49 50 82 2 12 2 33 0 45-1 10-5 26-8 30z\"/>");
67+
res->print("<path d=\"m565 324c4-5 5-34 4-50-2-14-6-24-8-24-1 0-3 2-6 5-17 17-47 13-58-9-7-16-4-31 8-43 4-4 7-8 7-9 0 0-4-2-8-3-51-17-105 20-115 80-3 15 0 43 3 53z\" fill=\"#fff\"/>");
68+
res->print("<path d=\"m504 590s-46 40-105 53c-66 15-114-7-114-7s14-76 93-95c76-18 126 49 126 49z\" fill=\"#f9bedd\"/>");
69+
res->print("</svg>");
70+
}
71+
4972
/**
5073
* This callback will be registered as default callback. The default callback is used
5174
* if no other node matches the request.
@@ -128,6 +151,9 @@ void serverTask(void *params) {
128151
// is used to show the icon in the tab of that website.
129152
ResourceNode faviconNode = ResourceNode("/favicon.ico", "GET", &faviconCallback);
130153

154+
// The awesomeCallback is very similar to the favicon.
155+
ResourceNode awesomeNode = ResourceNode("/images/awesome.svg", "GET", &awesomeCallback);
156+
131157
// The root node (on GET /) will be called when no directory on the server is specified in
132158
// the request, so this node can be accessed through https://myesp/
133159
ResourceNode rootNode = ResourceNode("/", "GET", &testCallback);
@@ -147,6 +173,7 @@ void serverTask(void *params) {
147173
server.setDefaultNode(&notFoundNode);
148174
server.registerNode(&rootNode);
149175
server.registerNode(&faviconNode);
176+
server.registerNode(&awesomeNode);
150177

151178
// The web server can be start()ed and stop()ed. When it's stopped, it will close its server port and
152179
// all open connections and free the resources. Theoretically, it should be possible to run multiple

0 commit comments

Comments
 (0)