Add extra param to http_reply()

This commit is contained in:
cpq
2020-12-17 22:47:55 +00:00
parent 29d31ba919
commit 82a378e519
9 changed files with 47 additions and 40 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
// Event handler for an accepted connection
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
mg_http_reply(c, 200, "Hello from ESP32!");
mg_http_reply(c, 200, "", "Hello from ESP32!");
}
}
+2 -2
View File
@@ -14,9 +14,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/f1")) {
mg_http_reply(c, 200, "{\"result\": %d}\n", 123); // Serve REST response
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123); // Serve REST
} else if (mg_http_match_uri(hm, "/api/f2/*")) {
mg_http_reply(c, 200, "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
hm->uri.ptr);
} else {
mg_http_serve_dir(c, ev_data, s_web_directory); // Serve static files
+1 -1
View File
@@ -24,7 +24,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mg_ws_upgrade(c, hm);
} else if (mg_http_match_uri(hm, "/rest")) {
// Serve REST response
mg_http_reply(c, 200, "{\"result\": %d}\n", 123);
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
} else {
// Serve static files
mg_http_serve_dir(c, ev_data, s_web_directory);