diff options
author | Alfred E. Heggestad <aeh@db.org> | 2014-12-26 21:21:22 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2014-12-26 21:21:22 +0100 |
commit | d7c174933ccf2bc9f1979e5013902ebe41086f5b (patch) | |
tree | 17f93333bbab242b8b5a59a3b9fc40d7aafc12cc | |
parent | 11cda4a23f8b9fa158b1dfda87b3b2f5e4bc25af (diff) | |
parent | f79e0c7796930e9a2d85243c473ea2cb90dd403d (diff) |
Merge pull request #33 from lmangani/http-mod
HTTPD module RAW output mode for curling
-rw-r--r-- | modules/httpd/httpd.c | 27 | ||||
-rw-r--r-- | src/config.c | 3 |
2 files changed, 30 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"); } diff --git a/src/config.c b/src/config.c index 68512b9..38f36d1 100644 --- a/src/config.c +++ b/src/config.c @@ -679,6 +679,9 @@ int config_write_template(const char *file, const struct config *cfg) (void)re_fprintf(f, "cons_listen\t\t0.0.0.0:5555\n"); (void)re_fprintf(f, "\n"); + (void)re_fprintf(f, "http_listen\t\t0.0.0.0:8000\n"); + + (void)re_fprintf(f, "\n"); (void)re_fprintf(f, "evdev_device\t\t/dev/input/event0\n"); (void)re_fprintf(f, "\n# Speex codec parameters\n"); |