Skip to content

Commit

Permalink
remove http_match_uri()
Browse files Browse the repository at this point in the history
  • Loading branch information
scaprile committed Apr 17, 2024
1 parent e6bf658 commit ef61d6e
Show file tree
Hide file tree
Showing 34 changed files with 83 additions and 93 deletions.
2 changes: 1 addition & 1 deletion examples/arduino/teensy41-http/teensy41-http.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void simple_http_listener(struct mg_connection *c, int ev, void *ev_data)
struct mg_http_message *hm = (struct mg_http_message *) ev_data;

// If the requested URI is "/api/hi", send a simple JSON response back
if (mg_http_match_uri(hm, "/api/hi")) {
if (mg_match(hm->uri, mg_str("/api/hi"), NULL)) {
// Use mg_http_reply() API function to generate JSON response. It adds a
// Content-Length header automatically. In the response, we show
// the requested URI and HTTP body:
Expand Down
28 changes: 14 additions & 14 deletions examples/device-dashboard/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,33 +273,33 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct user *u = authenticate(hm);

if (mg_http_match_uri(hm, "/api/#") && u == NULL) {
if (mg_match(hm->uri, mg_str("/api/#"), NULL) && u == NULL) {
mg_http_reply(c, 403, "", "Not Authorised\n");
} else if (mg_http_match_uri(hm, "/api/login")) {
} else if (mg_match(hm->uri, mg_str("/api/login"), NULL)) {
handle_login(c, u);
} else if (mg_http_match_uri(hm, "/api/logout")) {
} else if (mg_match(hm->uri, mg_str("/api/logout"), NULL)) {
handle_logout(c);
} else if (mg_http_match_uri(hm, "/api/debug")) {
} else if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
handle_debug(c, hm);
} else if (mg_http_match_uri(hm, "/api/stats/get")) {
} else if (mg_match(hm->uri, mg_str("/api/stats/get"), NULL)) {
handle_stats_get(c);
} else if (mg_http_match_uri(hm, "/api/events/get")) {
} else if (mg_match(hm->uri, mg_str("/api/events/get"), NULL)) {
handle_events_get(c, hm);
} else if (mg_http_match_uri(hm, "/api/settings/get")) {
} else if (mg_match(hm->uri, mg_str("/api/settings/get"), NULL)) {
handle_settings_get(c);
} else if (mg_http_match_uri(hm, "/api/settings/set")) {
} else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/firmware/upload")) {
} else if (mg_match(hm->uri, mg_str("/api/firmware/upload"), NULL)) {
handle_firmware_upload(c, hm);
} else if (mg_http_match_uri(hm, "/api/firmware/commit")) {
} else if (mg_match(hm->uri, mg_str("/api/firmware/commit"), NULL)) {
handle_firmware_commit(c);
} else if (mg_http_match_uri(hm, "/api/firmware/rollback")) {
} else if (mg_match(hm->uri, mg_str("/api/firmware/rollback"), NULL)) {
handle_firmware_rollback(c);
} else if (mg_http_match_uri(hm, "/api/firmware/status")) {
} else if (mg_match(hm->uri, mg_str("/api/firmware/status"), NULL)) {
handle_firmware_status(c);
} else if (mg_http_match_uri(hm, "/api/device/reset")) {
} else if (mg_match(hm->uri, mg_str("/api/device/reset"), NULL)) {
handle_device_reset(c);
} else if (mg_http_match_uri(hm, "/api/device/eraselast")) {
} else if (mg_match(hm->uri, mg_str("/api/device/eraselast"), NULL)) {
handle_device_eraselast(c);
} else {
struct mg_http_serve_opts opts;
Expand Down
2 changes: 1 addition & 1 deletion examples/file-transfer/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void handle_uploads(struct mg_connection *c, int ev, void *ev_data) {
// HTTP headers but not necessarily full HTTP body
if (ev == MG_EV_HTTP_HDRS) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/upload/#")) {
if (mg_match(hm->uri, mg_str("/upload/#"), NULL)) {
c->pfn = NULL; // Silence HTTP protocol handler, we'll take over
if (!authuser(hm)) {
mg_http_reply(c, 403, "", "Denied\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-html-form/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len,
hm->uri.buf, (unsigned long) hm->body.len));
if (mg_http_match_uri(hm, "/upload")) {
if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
struct mg_http_part part;
size_t ofs = 0;
while ((ofs = mg_http_next_multipart(hm->body, ofs, &part)) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-multiple-posts/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
static void cb(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/upload")) {
if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
mg_http_upload(c, hm, &mg_fs_posix, "/tmp", 99999);
} else {
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
Expand Down
4 changes: 2 additions & 2 deletions examples/http-restful-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_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/stats")) {
if (mg_match(hm->uri, mg_str("/api/stats"), NULL)) {
// Print some statistics about currently established connections
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n");
Expand All @@ -81,7 +81,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
mg_print_ip, &t->loc, mg_print_ip, &t->rem);
}
mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk
} else if (mg_http_match_uri(hm, "/api/f2/*")) {
} else if (mg_match(hm->uri, mg_str("/api/f2/*"), NULL)) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
hm->uri.buf);
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/huge-response/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) {
static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data;
if (mg_http_match_uri(hm, "/api/data")) {
if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
const char *headers = "content-type: text/json\r\n";
long start = getparam(hm, "$.start");
long version = getparam(hm, "$.version");
Expand Down
2 changes: 1 addition & 1 deletion examples/json-rpc-over-websocket/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
c->data[0] = 'W'; // Mark this connection as an established WS client
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) {
if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
// Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm, NULL);
Expand Down
4 changes: 2 additions & 2 deletions examples/live-log/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
static void cb(struct mg_connection *c, int ev, void *ev_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/log/static")) {
if (mg_match(hm->uri, mg_str("/api/log/static"), NULL)) {
struct mg_http_serve_opts opts = {.root_dir = NULL};
mg_http_serve_file(c, hm, "log.txt", &opts);
} else if (mg_http_match_uri(hm, "/api/log/live")) {
} else if (mg_match(hm->uri, mg_str("/api/log/live"), NULL)) {
c->data[0] = 'L'; // Mark that connection as live log listener
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/mip-pcap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ static void fn2(struct mg_connection *c, int ev, void *ev_data) {
static void fn(struct mg_connection *c, int ev, void *ev_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/debug")) {
if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
} else if (mg_http_match_uri(hm, "/api/url")) {
} else if (mg_match(hm->uri, mg_str("/api/url"), NULL)) {
char *url = mg_json_get_str(hm->body, "$.url");
if (url == NULL) {
mg_http_reply(c, 200, NULL, "no url, rl %d\r\n", (int) c->recv.len);
Expand Down
10 changes: 5 additions & 5 deletions examples/modbus-dashboard/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;

if (mg_http_match_uri(hm, "/api/settings/get")) {
if (mg_match(hm->uri, mg_str("/api/settings/get"), NULL)) {
handle_settings_get(c);
} else if (mg_http_match_uri(hm, "/api/settings/set")) {
} else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/settings/set")) {
} else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/modbus/exec")) {
} else if (mg_match(hm->uri, mg_str("/api/modbus/exec"), NULL)) {
handle_modbus_exec(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/device/reset")) {
} else if (mg_match(hm->uri, mg_str("/api/device/reset"), NULL)) {
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL);
mg_http_reply(c, 200, s_json_header, "true\n");
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-threaded-12m/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
start_thread(thread_function, data); // Start thread and pass data
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) {
if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on a connection
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-threaded/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void *thread_function(void *param) {
static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/fast")) {
if (mg_match(hm->uri, mg_str("/fast"), NULL)) {
// Single-threaded code path, for performance comparison
// The /fast URI responds immediately
mg_http_reply(c, 200, "Host: foo.com\r\n", "hi\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_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/debug")) {
if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_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/debug")) {
if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32/nucleo-g031-make-baremetal-builtin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->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/hello")) { // Request to /api/hello
if (mg_match(hm->uri, mg_str("/api/hello"), NULL)) { // Request to /api/hello
mg_http_reply(c, 200, "", "{%m:%u,%m:%u,%m:%u,%m:%u,%m:%u}\n",
MG_ESC("eth"), ifp->state, MG_ESC("frames_received"),
ifp->nrecv, MG_ESC("frames_sent"), ifp->nsent,
MG_ESC("frames_dropped"), ifp->ndrop,
MG_ESC("interface_errors"), ifp->nerr);
} else if (mg_http_match_uri(hm, "/")) { // Index page
} else if (mg_match(hm->uri, mg_str("/"), NULL)) { // Index page
mg_http_reply(
c, 200, "", "%s",
"<html><head><link rel='icon' href='data:;base64,='></head><body>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_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/debug")) {
if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
Expand Down
2 changes: 1 addition & 1 deletion examples/timers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static const char *s_web_root = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) {
if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on a connection
} else {
Expand Down
6 changes: 3 additions & 3 deletions examples/uart-bridge/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data) {
// mg_log_set(MG_LL_DEBUG); // Set log level
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/hi")) {
if (mg_match(hm->uri, mg_str("/api/hi"), NULL)) {
mg_http_reply(c, 200, "", "hi\n"); // Testing endpoint
} else if (mg_http_match_uri(hm, "/api/config/set")) {
} else if (mg_match(hm->uri, mg_str("/api/config/set"), NULL)) {
config_apply(hm->body);
config_write(hm->body);
mg_http_reply(c, 200, "", "true\n");
} else if (mg_http_match_uri(hm, "/api/config/get")) {
} else if (mg_match(hm->uri, mg_str("/api/config/get"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s},"
"%m:%d,%m:%d,%m:%d}\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/video-stream/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
static void cb(struct mg_connection *c, int ev, void *ev_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/video1")) {
if (mg_match(hm->uri, mg_str("/api/video1"), NULL)) {
c->data[0] = 'S'; // Mark that connection as live streamer
mg_printf(
c, "%s",
Expand Down
4 changes: 2 additions & 2 deletions examples/websocket-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
// c->is_hexdumping = 1;
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) {
if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
// Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm, NULL);
} else if (mg_http_match_uri(hm, "/rest")) {
} else if (mg_match(hm->uri, mg_str("/rest"), NULL)) {
// Serve REST response
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
} else {
Expand Down
6 changes: 3 additions & 3 deletions examples/webui-login/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct user *u = getuser(hm);
if (u == NULL && mg_http_match_uri(hm, "/api/#")) {
if (u == NULL && mg_match(hm->uri, mg_str("/api/#"), NULL)) {
// All URIs starting with /api/ must be authenticated
mg_http_reply(c, 403, "", "Denied\n");
} else if (mg_http_match_uri(hm, "/api/data")) {
} else if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m}\n", MG_ESC("text"), MG_ESC("Hello!"),
MG_ESC("data"), MG_ESC("somedata"));
} else if (mg_http_match_uri(hm, "/api/login")) {
} else if (mg_match(hm->uri, mg_str("/api/login"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m}\n", MG_ESC("user"), MG_ESC(u->name),
MG_ESC("token"), MG_ESC(u->token));
Expand Down
4 changes: 2 additions & 2 deletions examples/webui-plain/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
s_config.sub = strdup(MQTT_SUBSCRIBE_TOPIC);
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/config/get")) {
if (mg_match(hm->uri, mg_str("/api/config/get"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m,%m:%m}\n", MG_ESC("url"),
MG_ESC(s_config.url), MG_ESC("pub"), MG_ESC(s_config.pub),
MG_ESC("sub"), MG_ESC(s_config.sub));
} else if (mg_http_match_uri(hm, "/api/config/set")) {
} else if (mg_match(hm->uri, mg_str("/api/config/set"), NULL)) {
struct mg_str json = hm->body;
update_config(json, "$.url", &s_config.url);
update_config(json, "$.pub", &s_config.pub);
Expand Down
2 changes: 1 addition & 1 deletion examples/webui-push-rest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) {
static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data;
if (mg_http_match_uri(hm, "/api/data")) {
if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
long version = getparam(hm, "$.version");
if (version > 0 && version == s_version) {
// Version match: no changes
Expand Down
2 changes: 1 addition & 1 deletion examples/webui-push-ws/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static const char *s_web_root = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_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/watch")) {
if (mg_match(hm->uri, mg_str("/api/watch"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on the connection
} else {
Expand Down
4 changes: 2 additions & 2 deletions examples/webui-rest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ static const char *s_root_dir = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_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")) {
if (mg_match(hm->uri, mg_str("/api/f1"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:%d}\n",
MG_ESC("result"), 123);
} else if (mg_http_match_uri(hm, "/api/sum")) {
} else if (mg_match(hm->uri, mg_str("/api/sum"), NULL)) {
// Attempt to fetch a JSON array from the body, hm->body
struct mg_str json = hm->body;
double num1, num2;
Expand Down
Loading

0 comments on commit ef61d6e

Please sign in to comment.