From 70b5f4130ed57c3f33b2bf689c3d5cc59aab61f7 Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <lsm@cesanta.com>
Date: Thu, 23 Feb 2017 19:45:58 +0200
Subject: [PATCH] Add http post example

PUBLISHED_FROM=94f830a5fa4b806fb2cf60c93a9e8744022ff8d7
---
 mongoose.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index d0dcf8b..11a089d 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -4968,10 +4968,10 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) {
 
 #if MG_ENABLE_HTTP
 
+/* Amalgamated: #include "common/md5.h" */
+/* Amalgamated: #include "common/sha1.h" */
 /* Amalgamated: #include "mongoose/src/internal.h" */
 /* Amalgamated: #include "mongoose/src/util.h" */
-/* Amalgamated: #include "common/sha1.h" */
-/* Amalgamated: #include "common/md5.h" */
 
 static const char *mg_version_header = "Mongoose/" MG_VERSION;
 
@@ -5825,8 +5825,7 @@ static void mg_http_multipart_begin(struct mg_connection *nc,
 
     mbuf_remove(io, req_len);
   }
-exit_mp:
-  ;
+exit_mp:;
 }
 
 #define CONTENT_DISPOSITION "Content-Disposition: "
@@ -7189,8 +7188,7 @@ MG_INTERNAL int mg_uri_to_local_path(struct http_message *hm,
             if (*p == '\0' || *p == DIRSEP
 #ifdef _WIN32
                 /* On Windows, "/" is also accepted, so check for that too. */
-                ||
-                *p == '/'
+                || *p == '/'
 #endif
                 ) {
               ok = 0;
@@ -7732,13 +7730,14 @@ struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr,
     mg_basic_auth_header(user, pass, &auth);
   }
 
+  if (post_data == NULL) post_data = "";
+  if (extra_headers == NULL) extra_headers = "";
+
   mg_printf(nc, "%s %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %" SIZE_T_FMT
                 "\r\n%.*s%s\r\n%s",
-            post_data == NULL ? "GET" : "POST", path, addr,
-            post_data == NULL ? 0 : strlen(post_data), (int) auth.len,
-            (auth.buf == NULL ? "" : auth.buf),
-            extra_headers == NULL ? "" : extra_headers,
-            post_data == NULL ? "" : post_data);
+            post_data[0] == '\0' ? "GET" : "POST", path, addr,
+            strlen(post_data), (int) auth.len,
+            (auth.buf == NULL ? "" : auth.buf), extra_headers, post_data);
 
   mbuf_free(&auth);
   MG_FREE(user);
-- 
2.18.0