From 988e1efa85a1bace8c0557fe1ff5df5502419f59 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Fri, 26 Dec 2014 20:52:27 +0100 Subject: HTTPD module RAW output mode for curling (/raw/?cmd) --- modules/httpd/httpd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'modules/httpd/httpd.c') 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"); } -- cgit v1.2.3