diff options
author | Lorenzo Mangani <lorenzo.mangani@gmail.com> | 2014-12-26 20:52:27 +0100 |
---|---|---|
committer | Lorenzo Mangani <lorenzo.mangani@gmail.com> | 2014-12-26 20:52:27 +0100 |
commit | 988e1efa85a1bace8c0557fe1ff5df5502419f59 (patch) | |
tree | bb242895cad3b6fd70ed5bb2a9c1d2b98bc2c935 /modules/httpd/httpd.c | |
parent | 8be5dac1296d79c34b1de2938b0ad55cb0e1a0e2 (diff) |
HTTPD module RAW output mode for curling (/raw/?cmd)
Diffstat (limited to 'modules/httpd/httpd.c')
-rw-r--r-- | modules/httpd/httpd.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/httpd/httpd.c b/modules/httpd/httpd.c index a837b35..3d21203 100644 --- a/modules/httpd/httpd.c +++ b/modules/httpd/httpd.c @@ -51,6 +51,27 @@ static int html_print_cmd(struct re_printf *pf, const struct http_msg *req) } +static int html_print_raw(struct re_printf *pf, const struct http_msg *req) +{ + struct pl params; + + if (!pf || !req) + return EINVAL; + + if (pl_isset(&req->prm)) { + params.p = req->prm.p + 1; + params.l = req->prm.l - 1; + } + else { + params.p = "h"; + params.l = 1; + } + + return re_hprintf(pf, + "%H", + ui_input_pl, ¶ms); +} + static void http_req_handler(struct http_conn *conn, const struct http_msg *msg, void *arg) { @@ -62,6 +83,12 @@ static void http_req_handler(struct http_conn *conn, "text/html;charset=UTF-8", "%H", html_print_cmd, msg); } + else if (0 == pl_strcasecmp(&msg->path, "/raw/")) { + + http_creply(conn, 200, "OK", + "text/plain;charset=UTF-8", + "%H", html_print_raw, msg); + } else { http_ereply(conn, 404, "Not Found"); } |