From d49e965738497f8107b1b913d48cacfcd9ea11e8 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 18 Nov 2014 13:34:29 +0100 Subject: [PATCH] http: improve the request dump (for post) --- src/http.c | 72 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/http.c b/src/http.c index 7236b7e8..53e166ac 100644 --- a/src/http.c +++ b/src/http.c @@ -498,7 +498,38 @@ http_exec(http_connection_t *hc, http_path_t *hp, char *remain) return 0; } +/* + * Dump request + */ +#if ENABLE_TRACE +static void +dump_request(http_connection_t *hc) +{ + char buf[2048] = ""; + http_arg_t *ra; + int first; + first = 1; + TAILQ_FOREACH(ra, &hc->hc_req_args, link) { + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), first ? "?%s=%s" : "&%s=%s", ra->key, ra->val); + first = 0; + } + + first = 1; + TAILQ_FOREACH(ra, &hc->hc_args, link) { + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), first ? "{{%s=%s" : ",%s=%s", ra->key, ra->val); + first = 0; + } + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "}}"); + + tvhtrace("http", "%s%s", hc->hc_url, buf); +} +#else +static inline void +dump_request(http_connection_t *hc) +{ +} +#endif /** * HTTP GET @@ -510,6 +541,8 @@ http_cmd_get(http_connection_t *hc) char *remain; char *args; + dump_request(hc); + hp = http_resolve(hc, &remain, &args); if(hp == NULL) { http_error(hc, HTTP_STATUS_NOT_FOUND); @@ -560,7 +593,7 @@ http_cmd_post(http_connection_t *hc, htsbuf_queue_t *spill) if(tcp_read_data(hc->hc_fd, hc->hc_post_data, hc->hc_post_len, spill) < 0) return -1; - /* Parse content-type */ + /* Parse content-type */ v = http_arg_get(&hc->hc_args, "Content-Type"); if(v != NULL) { char *argv[2]; @@ -574,6 +607,8 @@ http_cmd_post(http_connection_t *hc, htsbuf_queue_t *spill) http_parse_get_args(hc, hc->hc_post_data); } + dump_request(hc); + hp = http_resolve(hc, &remain, &args); if(hp == NULL) { http_error(hc, HTTP_STATUS_NOT_FOUND); @@ -603,39 +638,6 @@ http_process_request(http_connection_t *hc, htsbuf_queue_t *spill) } } -/* - * - */ -#if ENABLE_TRACE -static void -dump_request(http_connection_t *hc) -{ - char buf[2048] = ""; - http_arg_t *ra; - int first; - - first = 1; - TAILQ_FOREACH(ra, &hc->hc_req_args, link) { - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), first ? "?%s=%s" : "&%s=%s", ra->key, ra->val); - first = 0; - } - - first = 1; - TAILQ_FOREACH(ra, &hc->hc_args, link) { - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), first ? "{{%s=%s" : ",%s=%s", ra->key, ra->val); - first = 0; - } - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "}}"); - - tvhtrace("http", "%s%s", hc->hc_url, buf); -} -#else -static inline void -dump_request(http_connection_t *hc) -{ -} -#endif - /** * Process a request, extract info from headers, dispatch command and * clean up @@ -647,8 +649,6 @@ process_request(http_connection_t *hc, htsbuf_queue_t *spill) int n, rval = -1; uint8_t authbuf[150]; - dump_request(hc); - hc->hc_url_orig = tvh_strdupa(hc->hc_url); /* Set keep-alive status */