From 8f62822a333cd564b9b6cc315435f9fb7fd39a6a Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 31 Dec 2013 13:57:19 +0000 Subject: [PATCH] Using mg_printf() --- examples/post.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/post.c b/examples/post.c index ca324f8a..f8c26fb4 100644 --- a/examples/post.c +++ b/examples/post.c @@ -11,7 +11,7 @@ static const char *html_form = ""; static int handler(struct mg_connection *conn) { - char var1[500], var2[500], reply[2000]; + char var1[500], var2[500]; if (strcmp(conn->uri, "/handle_post_request") == 0) { // User has submitted a form, show submitted data and a variable value @@ -21,21 +21,19 @@ static int handler(struct mg_connection *conn) { // Send reply to the client, showing submitted form values. // POST data is in conn->content, data length is in conn->content_len - snprintf(reply, sizeof(reply), "HTTP/1.0 200 OK\r\n" + mg_printf(conn, "HTTP/1.0 200 OK\r\n" "Content-Type: text/plain\r\n\r\n" "Submitted data: [%.*s]\n" "Submitted data length: %d bytes\n" "input_1: [%s]\n" "input_2: [%s]\n", conn->content_len, conn->content, conn->content_len, var1, var2); - mg_write(conn, reply, strlen(reply)); } else { // Show HTML form. - snprintf(reply, sizeof(reply), "HTTP/1.0 200 OK\r\n" + mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Content-Length: %d\r\n" "Content-Type: text/html\r\n\r\n%s", (int) strlen(html_form), html_form); - mg_write(conn, reply, strlen(reply)); } return 1;