static void http_req_handler(struct http_conn *conn, const struct http_msg *msg, void *arg) { (void)arg; if (0 == pl_strcasecmp(&msg->path, "/")) { http_creply(conn, 200, "OK", "text/html;charset=UTF-8", "%H", html_print_cmd, msg); } else { http_ereply(conn, 404, "Not Found"); } }
void http_request_h(struct http_conn *conn, const struct http_msg *msg, void *arg) { int err; enum app_cmd cmd; const struct http_hdr * expect_hdr; struct mbuf *mb = msg->mb; uint8_t *ret_buf; size_t ret_len; if(pl_strcmp(&msg->met, "POST")) { http_creply(conn, 405, "Method not allowed", "text/plain", "EMET"); return; } expect_hdr = http_msg_hdr(msg, HTTP_HDR_EXPECT); if(expect_hdr != NULL && version_cmp(version, &expect_hdr->val) < 0) { http_creply(conn, 417, "Expectation Failed", "text/plain", "%s", version); return; } cmd = (enum app_cmd)(hash_joaat_ci(msg->path.p, msg->path.l) & 0xfff); err = app_handle(cmd, mbuf_buf(mb), mbuf_get_left(mb), &ret_buf, &ret_len); if(err < 0) { http_creply(conn, 500, "Internal Server Error", "text/plain", "EINT"); return; } if(err > 200) { http_creply(conn, err, "Error", "text/plain", "NO", 2); return; } if(err == 0) { http_creply(conn, 200, "OK", "text/plain; charset=utf-8", "%b", ret_buf, ret_len); } else { http_creply(conn, 403, "Forbidden", "text/plain", "%b", ret_buf, ret_len); } free(ret_buf); }