gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (03c29b63 -> 4b6419b1)


From: gnunet
Subject: [libmicrohttpd] branch master updated (03c29b63 -> 4b6419b1)
Date: Tue, 19 Apr 2022 19:31:07 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 03c29b63 configure: improved usage of 'pie' mode for hardening
     new 4ff10247 refactoring: use 'const' for response buffers
     new 1c116801 Added _MHD_EXTERN to the all public functions definitions
     new 71633eb9 Refactored create response functions.
     new b0a2a0ad microhttpd.h: removed empty line
     new f71019f0 MHD_get_version(): fixed signed value bit shift
     new d3ae3c43 Added new API function 
MHD_create_response_from_buffer_static()
     new df5b770e Fixed drop of 'const' when building internal error response
     new 57cc8b71 Fixed missing 'const' qualifiers
     new b6eb14d6 Added workaround for external APIs
     new ae4fcbad Minor simplification for ALPN protocols code
     new 43cca25d Added new API function MHD_create_response_from_buffer_copy()
     new 81daa705 microhttpd.h: minor doxy improvement
     new 85775e29 src/examples: Fixed drop of 'const' qualifiers and minor 
fixes.
     new 4b6419b1 doc/examples: Fixed drop of 'const' qualifiers

The 14 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/examples/basicauthentication.c                |   8 +-
 doc/examples/hellobrowser.c                       |   4 +-
 doc/examples/largepost.c                          |   5 +-
 doc/examples/responseheaders.c                    |   4 +-
 doc/examples/sessions.c                           |  14 +-
 doc/examples/simplepost.c                         |   4 +-
 doc/examples/tlsauthentication.c                  |   4 +-
 src/examples/authorization_example.c              |  18 +-
 src/examples/benchmark.c                          |   7 +-
 src/examples/benchmark_https.c                    |   7 +-
 src/examples/demo.c                               |  27 ++-
 src/examples/demo_https.c                         |  27 ++-
 src/examples/digest_auth_example.c                |  19 +-
 src/examples/dual_stack_example.c                 |  19 +-
 src/examples/fileserver_example.c                 |   9 +-
 src/examples/fileserver_example_dirs.c            |   7 +-
 src/examples/fileserver_example_external_select.c |   9 +-
 src/examples/https_fileserver_example.c           |   8 +-
 src/examples/minimal_example.c                    |  22 +-
 src/examples/post_example.c                       |  19 +-
 src/examples/querystring_example.c                |  10 +-
 src/examples/refuse_post_example.c                |  27 ++-
 src/examples/suspend_resume_epoll.c               |   8 +-
 src/examples/timeout.c                            |  10 +-
 src/examples/websocket_threaded_example.c         |  19 +-
 src/include/microhttpd.h                          |  63 +++++-
 src/microhttpd/basicauth.c                        |   4 +-
 src/microhttpd/connection.c                       |  21 +-
 src/microhttpd/daemon.c                           |  72 ++++---
 src/microhttpd/digestauth.c                       |   6 +-
 src/microhttpd/internal.c                         |   2 +-
 src/microhttpd/internal.h                         |   9 +-
 src/microhttpd/mhd_panic.c                        |   2 +-
 src/microhttpd/mhd_send.c                         |   4 +-
 src/microhttpd/mhd_str.c                          |   2 +-
 src/microhttpd/postprocessor.c                    |   6 +-
 src/microhttpd/reason_phrase.c                    |   4 +-
 src/microhttpd/response.c                         | 235 ++++++++++++++--------
 src/microhttpd/response.h                         |   2 +-
 39 files changed, 450 insertions(+), 297 deletions(-)

diff --git a/doc/examples/basicauthentication.c 
b/doc/examples/basicauthentication.c
index 3b105a1d..d75ba636 100644
--- a/doc/examples/basicauthentication.c
+++ b/doc/examples/basicauthentication.c
@@ -54,9 +54,7 @@ answer_to_connection (void *cls, struct MHD_Connection 
*connection,
   if (fail)
   {
     const char *page = "<html><body>Go away.</body></html>";
-    response =
-      MHD_create_response_from_buffer (strlen (page), (void *) page,
-                                       MHD_RESPMEM_PERSISTENT);
+    response = MHD_create_response_from_buffer_static (strlen (page), page);
     ret = MHD_queue_basic_auth_fail_response (connection,
                                               "my realm",
                                               response);
@@ -64,9 +62,7 @@ answer_to_connection (void *cls, struct MHD_Connection 
*connection,
   else
   {
     const char *page = "<html><body>A secret.</body></html>";
-    response =
-      MHD_create_response_from_buffer (strlen (page), (void *) page,
-                                       MHD_RESPMEM_PERSISTENT);
+    response = MHD_create_response_from_buffer_static (strlen (page), page);
     ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   }
   MHD_destroy_response (response);
diff --git a/doc/examples/hellobrowser.c b/doc/examples/hellobrowser.c
index b14ea6d8..0b7d9071 100644
--- a/doc/examples/hellobrowser.c
+++ b/doc/examples/hellobrowser.c
@@ -31,9 +31,7 @@ answer_to_connection (void *cls, struct MHD_Connection 
*connection,
   (void) upload_data_size;  /* Unused. Silent compiler warning. */
   (void) req_cls;           /* Unused. Silent compiler warning. */
 
-  response =
-    MHD_create_response_from_buffer (strlen (page), (void *) page,
-                                     MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (page), page);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
 
diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c
index ee9e85da..b7cccc04 100644
--- a/doc/examples/largepost.c
+++ b/doc/examples/largepost.c
@@ -98,10 +98,7 @@ send_page (struct MHD_Connection *connection,
   enum MHD_Result ret;
   struct MHD_Response *response;
 
-  response =
-    MHD_create_response_from_buffer (strlen (page),
-                                     (void *) page,
-                                     MHD_RESPMEM_MUST_COPY);
+  response = MHD_create_response_from_buffer_static (strlen (page), page);
   if (! response)
     return MHD_NO;
   MHD_add_response_header (response,
diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c
index 80eebbe9..162e5e2d 100644
--- a/doc/examples/responseheaders.c
+++ b/doc/examples/responseheaders.c
@@ -49,9 +49,7 @@ answer_to_connection (void *cls, struct MHD_Connection 
*connection,
     if (fd != -1)
       (void) close (fd);
     response =
-      MHD_create_response_from_buffer (strlen (errorstr),
-                                       (void *) errorstr,
-                                       MHD_RESPMEM_PERSISTENT);
+      MHD_create_response_from_buffer_static (strlen (errorstr), errorstr);
     if (NULL != response)
     {
       ret =
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index 5dd74e2c..0fe143eb 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -311,9 +311,7 @@ serve_simple_form (const void *cls,
   struct MHD_Response *response;
 
   /* return static form */
-  response = MHD_create_response_from_buffer (strlen (form),
-                                              (void *) form,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (form), form);
   add_session_cookie (session, response);
   MHD_add_response_header (response,
                            MHD_HTTP_HEADER_CONTENT_ENCODING,
@@ -431,9 +429,8 @@ not_found_page (const void *cls,
   (void) session; /* Unused. Silent compiler warning. */
 
   /* unsupported HTTP method */
-  response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR),
-                                              (void *) NOT_FOUND_ERROR,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (NOT_FOUND_ERROR),
+                                                     NOT_FOUND_ERROR);
   ret = MHD_queue_response (connection,
                             MHD_HTTP_NOT_FOUND,
                             response);
@@ -651,9 +648,8 @@ create_response (void *cls,
     return ret;
   }
   /* unsupported HTTP method */
-  response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
-                                              (void *) METHOD_ERROR,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (METHOD_ERROR),
+                                                     METHOD_ERROR);
   ret = MHD_queue_response (connection,
                             MHD_HTTP_NOT_ACCEPTABLE,
                             response);
diff --git a/doc/examples/simplepost.c b/doc/examples/simplepost.c
index ea3899d1..51cf23c0 100644
--- a/doc/examples/simplepost.c
+++ b/doc/examples/simplepost.c
@@ -55,9 +55,7 @@ send_page (struct MHD_Connection *connection, const char 
*page)
   struct MHD_Response *response;
 
 
-  response =
-    MHD_create_response_from_buffer (strlen (page), (void *) page,
-                                     MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (page), page);
   if (! response)
     return MHD_NO;
 
diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index 4db00b7f..1898e730 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -208,9 +208,7 @@ secret_page (struct MHD_Connection *connection)
   struct MHD_Response *response;
   const char *page = "<html><body>A secret.</body></html>";
 
-  response =
-    MHD_create_response_from_buffer (strlen (page), (void *) page,
-                                     MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (page), page);
   if (! response)
     return MHD_NO;
 
diff --git a/src/examples/authorization_example.c 
b/src/examples/authorization_example.c
index e7a099ed..d5011e5d 100644
--- a/src/examples/authorization_example.c
+++ b/src/examples/authorization_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2008 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -21,6 +22,7 @@
  * @file authorization_example.c
  * @brief example for how to use libmicrohttpd with HTTP authentication
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -48,12 +50,12 @@ ahc_echo (void *cls,
           const char *upload_data, size_t *upload_data_size, void **req_cls)
 {
   static int aptr;
-  const char *me = cls;
   struct MHD_Response *response;
   enum MHD_Result ret;
   char *user;
   char *pass;
   int fail;
+  (void) cls;               /* Unused. Silent compiler warning. */
   (void) url;               /* Unused. Silent compiler warning. */
   (void) version;           /* Unused. Silent compiler warning. */
   (void) upload_data;       /* Unused. Silent compiler warning. */
@@ -78,16 +80,16 @@ ahc_echo (void *cls,
            (0 != strcmp (pass, "open sesame") ) );
   if (fail)
   {
-    response = MHD_create_response_from_buffer (strlen (DENIED),
-                                                (void *) DENIED,
-                                                MHD_RESPMEM_PERSISTENT);
+    response =
+      MHD_create_response_from_buffer_static (strlen (DENIED),
+                                              (const void *) DENIED);
     ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response);
   }
   else
   {
-    response = MHD_create_response_from_buffer (strlen (me),
-                                                (void *) me,
-                                                MHD_RESPMEM_PERSISTENT);
+    response =
+      MHD_create_response_from_buffer_static (strlen (PAGE),
+                                              (const void *) PAGE);
     ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   }
   if (NULL != user)
@@ -117,7 +119,7 @@ main (int argc, char *const *argv)
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
+                        NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
   if (d == NULL)
     return 1;
   fprintf (stderr, "HTTP server running. Press ENTER to stop the server.\n");
diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c
index 185e3824..1abdad24 100644
--- a/src/examples/benchmark.c
+++ b/src/examples/benchmark.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2013 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file benchmark.c
  * @brief minimal code to benchmark MHD GET performance
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -145,9 +147,8 @@ main (int argc, char *const *argv)
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
-  response = MHD_create_response_from_buffer (strlen (PAGE),
-                                              (void *) PAGE,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (PAGE),
+                                                     (const void *) PAGE);
 #if 0
   (void) MHD_add_response_header (response,
                                   MHD_HTTP_HEADER_CONNECTION,
diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c
index 36a46aa8..c25e46c3 100644
--- a/src/examples/benchmark_https.c
+++ b/src/examples/benchmark_https.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2013 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file benchmark_https.c
  * @brief minimal code to benchmark MHD GET performance with HTTPS
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -211,9 +213,8 @@ main (int argc, char *const *argv)
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
-  response = MHD_create_response_from_buffer (strlen (PAGE),
-                                              (void *) PAGE,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (PAGE),
+                                                     (const void *) PAGE);
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
 #ifdef EPOLL_SUPPORT
                         | MHD_USE_EPOLL | MHD_USE_TURBO
diff --git a/src/examples/demo.c b/src/examples/demo.c
index 6ff7adae..5b3e75d1 100644
--- a/src/examples/demo.c
+++ b/src/examples/demo.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -27,6 +28,7 @@
  *        run tests against.  Note that the number of threads may need
  *        to be adjusted depending on the number of available cores.
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 #include "MHD_config.h"
 #include "platform.h"
@@ -909,23 +911,18 @@ main (int argc, char *const *argv)
 #endif /* MHD_HAVE_LIBMAGIC */
 
   (void) pthread_mutex_init (&mutex, NULL);
-  file_not_found_response = MHD_create_response_from_buffer (strlen (
-                                                               
FILE_NOT_FOUND_PAGE),
-                                                             (void *)
-                                                             
FILE_NOT_FOUND_PAGE,
-                                                             
MHD_RESPMEM_PERSISTENT);
+  file_not_found_response =
+    MHD_create_response_from_buffer_static (strlen (FILE_NOT_FOUND_PAGE),
+                                            (const void *) 
FILE_NOT_FOUND_PAGE);
   mark_as_html (file_not_found_response);
-  request_refused_response = MHD_create_response_from_buffer (strlen (
-                                                                
REQUEST_REFUSED_PAGE),
-                                                              (void *)
-                                                              
REQUEST_REFUSED_PAGE,
-                                                              
MHD_RESPMEM_PERSISTENT);
+  request_refused_response =
+    MHD_create_response_from_buffer_static (strlen (REQUEST_REFUSED_PAGE),
+                                            (const void *)
+                                            REQUEST_REFUSED_PAGE);
   mark_as_html (request_refused_response);
-  internal_error_response = MHD_create_response_from_buffer (strlen (
-                                                               
INTERNAL_ERROR_PAGE),
-                                                             (void *)
-                                                             
INTERNAL_ERROR_PAGE,
-                                                             
MHD_RESPMEM_PERSISTENT);
+  internal_error_response =
+    MHD_create_response_from_buffer_static (strlen (INTERNAL_ERROR_PAGE),
+                                            (const void *) 
INTERNAL_ERROR_PAGE);
   mark_as_html (internal_error_response);
   update_directory ();
   d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
index ef59e7d9..397bd770 100644
--- a/src/examples/demo_https.c
+++ b/src/examples/demo_https.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -30,6 +31,7 @@
  *        This demonstration uses key/cert stored in static string. Optionally,
  *        use gnutls_load_file() to load them from file.
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 #include "platform.h"
 #include <microhttpd.h>
@@ -974,23 +976,18 @@ main (int argc, char *const *argv)
 #endif /* MHD_HAVE_LIBMAGIC */
 
   (void) pthread_mutex_init (&mutex, NULL);
-  file_not_found_response = MHD_create_response_from_buffer (strlen (
-                                                               
FILE_NOT_FOUND_PAGE),
-                                                             (void *)
-                                                             
FILE_NOT_FOUND_PAGE,
-                                                             
MHD_RESPMEM_PERSISTENT);
+  file_not_found_response =
+    MHD_create_response_from_buffer_static (strlen (FILE_NOT_FOUND_PAGE),
+                                            (const void *) 
FILE_NOT_FOUND_PAGE);
   mark_as_html (file_not_found_response);
-  request_refused_response = MHD_create_response_from_buffer (strlen (
-                                                                
REQUEST_REFUSED_PAGE),
-                                                              (void *)
-                                                              
REQUEST_REFUSED_PAGE,
-                                                              
MHD_RESPMEM_PERSISTENT);
+  request_refused_response =
+    MHD_create_response_from_buffer_static (strlen (REQUEST_REFUSED_PAGE),
+                                            (const void *)
+                                            REQUEST_REFUSED_PAGE);
   mark_as_html (request_refused_response);
-  internal_error_response = MHD_create_response_from_buffer (strlen (
-                                                               
INTERNAL_ERROR_PAGE),
-                                                             (void *)
-                                                             
INTERNAL_ERROR_PAGE,
-                                                             
MHD_RESPMEM_PERSISTENT);
+  internal_error_response =
+    MHD_create_response_from_buffer_static (strlen (INTERNAL_ERROR_PAGE),
+                                            (const void *) 
INTERNAL_ERROR_PAGE);
   mark_as_html (internal_error_response);
   update_directory ();
   d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
diff --git a/src/examples/digest_auth_example.c 
b/src/examples/digest_auth_example.c
index 68d13c84..f8208d97 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2010 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file digest_auth_example.c
  * @brief minimal example for how to use digest auth with libmicrohttpd
  * @author Amr Ali
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -67,9 +69,9 @@ ahc_echo (void *cls,
   username = MHD_digest_auth_get_username (connection);
   if (NULL == username)
   {
-    response = MHD_create_response_from_buffer (strlen (DENIED),
-                                                DENIED,
-                                                MHD_RESPMEM_PERSISTENT);
+    response =
+      MHD_create_response_from_buffer_static (strlen (DENIED),
+                                              DENIED);
     ret = MHD_queue_auth_fail_response2 (connection, realm,
                                          MY_OPAQUE_STR,
                                          response,
@@ -86,9 +88,9 @@ ahc_echo (void *cls,
   if ( (res == MHD_INVALID_NONCE) ||
        (res == MHD_NO) )
   {
-    response = MHD_create_response_from_buffer (strlen (DENIED),
-                                                DENIED,
-                                                MHD_RESPMEM_PERSISTENT);
+    response =
+      MHD_create_response_from_buffer_static (strlen (DENIED),
+                                              DENIED);
     if (NULL == response)
       return MHD_NO;
     ret = MHD_queue_auth_fail_response2 (connection, realm,
@@ -100,8 +102,7 @@ ahc_echo (void *cls,
     MHD_destroy_response (response);
     return ret;
   }
-  response = MHD_create_response_from_buffer (strlen (PAGE), PAGE,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (PAGE), PAGE);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
   return ret;
@@ -148,7 +149,7 @@ main (int argc, char *const *argv)
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE,
+                        NULL, NULL, &ahc_echo, NULL,
                         MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd,
                         MHD_OPTION_NONCE_NC_SIZE, 300,
                         MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
diff --git a/src/examples/dual_stack_example.c 
b/src/examples/dual_stack_example.c
index 175583ac..957daf07 100644
--- a/src/examples/dual_stack_example.c
+++ b/src/examples/dual_stack_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2012 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file dual_stack_example.c
  * @brief how to use MHD with both IPv4 and IPv6 support (dual-stack)
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -28,6 +30,11 @@
 #define PAGE \
   "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd 
demo</body></html>"
 
+struct handler_param
+{
+  const char *response_page;
+};
+
 static enum MHD_Result
 ahc_echo (void *cls,
           struct MHD_Connection *connection,
@@ -37,7 +44,7 @@ ahc_echo (void *cls,
           const char *upload_data, size_t *upload_data_size, void **req_cls)
 {
   static int aptr;
-  const char *me = cls;
+  struct handler_param *param = (struct handler_param *) cls;
   struct MHD_Response *response;
   enum MHD_Result ret;
   (void) url;               /* Unused. Silent compiler warning. */
@@ -54,9 +61,9 @@ ahc_echo (void *cls,
     return MHD_YES;
   }
   *req_cls = NULL;                  /* reset when done */
-  response = MHD_create_response_from_buffer (strlen (me),
-                                              (void *) me,
-                                              MHD_RESPMEM_PERSISTENT);
+  response =
+    MHD_create_response_from_buffer_static (strlen (param->response_page),
+                                            param->response_page);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
   return ret;
@@ -67,16 +74,18 @@ int
 main (int argc, char *const *argv)
 {
   struct MHD_Daemon *d;
+  struct handler_param data_for_handler;
 
   if (argc != 2)
   {
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
+  data_for_handler.response_page = PAGE;
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
                         | MHD_USE_DUAL_STACK,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE,
+                        NULL, NULL, &ahc_echo, &data_for_handler,
                         MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
                         MHD_OPTION_END);
   (void) getc (stdin);
diff --git a/src/examples/fileserver_example.c 
b/src/examples/fileserver_example.c
index 76879eec..e300f6ed 100644
--- a/src/examples/fileserver_example.c
+++ b/src/examples/fileserver_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file fileserver_example.c
  * @brief minimal example for how to use libmicrohttpd to serve files
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -91,9 +93,8 @@ ahc_echo (void *cls,
   }
   if (-1 == fd)
   {
-    response = MHD_create_response_from_buffer (strlen (PAGE),
-                                                (void *) PAGE,
-                                                MHD_RESPMEM_PERSISTENT);
+    response = MHD_create_response_from_buffer_static (strlen (PAGE),
+                                                       PAGE);
     ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
     MHD_destroy_response (response);
   }
@@ -126,7 +127,7 @@ main (int argc, char *const *argv)
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
+                        NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
   if (d == NULL)
     return 1;
   (void) getc (stdin);
diff --git a/src/examples/fileserver_example_dirs.c 
b/src/examples/fileserver_example_dirs.c
index 796cb42e..0a977ddf 100644
--- a/src/examples/fileserver_example_dirs.c
+++ b/src/examples/fileserver_example_dirs.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -21,6 +22,7 @@
  * @file fileserver_example_dirs.c
  * @brief example for how to use libmicrohttpd to serve files (with directory 
support)
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -28,9 +30,6 @@
 #include <microhttpd.h>
 #include <unistd.h>
 
-#define PAGE \
-  "<html><head><title>File not found</title></head><body>File not 
found</body></html>"
-
 
 static ssize_t
 file_reader (void *cls, uint64_t pos, char *buf, size_t max)
@@ -199,7 +198,7 @@ main (int argc, char *const *argv)
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
+                        NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
   if (NULL == d)
     return 1;
   (void) getc (stdin);
diff --git a/src/examples/fileserver_example_external_select.c 
b/src/examples/fileserver_example_external_select.c
index 09f7be0a..cdd455ec 100644
--- a/src/examples/fileserver_example_external_select.c
+++ b/src/examples/fileserver_example_external_select.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2008 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file fileserver_example_external_select.c
  * @brief minimal example for how to use libmicrohttpd to server files
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -98,9 +100,8 @@ ahc_echo (void *cls,
 
   if (NULL == file)
   {
-    response = MHD_create_response_from_buffer (strlen (PAGE),
-                                                (void *) PAGE,
-                                                MHD_RESPMEM_PERSISTENT);
+    response = MHD_create_response_from_buffer_static (strlen (PAGE),
+                                                       PAGE);
     ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
     MHD_destroy_response (response);
   }
@@ -142,7 +143,7 @@ main (int argc, char *const *argv)
   }
   d = MHD_start_daemon (MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
+                        NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
   if (d == NULL)
     return 1;
   end = time (NULL) + atoi (argv[2]);
diff --git a/src/examples/https_fileserver_example.c 
b/src/examples/https_fileserver_example.c
index 5dc340f7..9f17d0a7 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2008 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -30,6 +31,7 @@
  * 'certtool' may be used to generate these if required.
  *
  * @author Sagie Amir
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
@@ -180,9 +182,9 @@ http_ahc (void *cls,
 
   if (NULL == file)
   {
-    response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE),
-                                                (void *) EMPTY_PAGE,
-                                                MHD_RESPMEM_PERSISTENT);
+    response =
+      MHD_create_response_from_buffer_static (strlen (EMPTY_PAGE),
+                                              (const void *) EMPTY_PAGE);
     ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
     MHD_destroy_response (response);
   }
diff --git a/src/examples/minimal_example.c b/src/examples/minimal_example.c
index ce604555..1e3f63f7 100644
--- a/src/examples/minimal_example.c
+++ b/src/examples/minimal_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,13 +21,20 @@
  * @file minimal_example.c
  * @brief minimal example for how to use libmicrohttpd
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "platform.h"
 #include <microhttpd.h>
 
 #define PAGE \
-  "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd 
demo</body></html>"
+  "<html><head><title>libmicrohttpd demo</title></head>" \
+  "<body>libmicrohttpd demo</body></html>"
+
+struct handler_param
+{
+  const char *response_page;
+};
 
 static enum MHD_Result
 ahc_echo (void *cls,
@@ -39,7 +47,7 @@ ahc_echo (void *cls,
           void **req_cls)
 {
   static int aptr;
-  const char *me = cls;
+  struct handler_param *param = (struct handler_param *) cls;
   struct MHD_Response *response;
   enum MHD_Result ret;
 
@@ -57,9 +65,9 @@ ahc_echo (void *cls,
     return MHD_YES;
   }
   *req_cls = NULL;                  /* reset when done */
-  response = MHD_create_response_from_buffer (strlen (me),
-                                              (void *) me,
-                                              MHD_RESPMEM_PERSISTENT);
+  response =
+    MHD_create_response_from_buffer_static (strlen (param->response_page),
+                                            param->response_page);
   ret = MHD_queue_response (connection,
                             MHD_HTTP_OK,
                             response);
@@ -73,19 +81,21 @@ main (int argc,
       char *const *argv)
 {
   struct MHD_Daemon *d;
+  struct handler_param data_for_handler;
 
   if (argc != 2)
   {
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
+  data_for_handler.response_page = PAGE;
   d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | 
MHD_USE_ERROR_LOG, */
     MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
     /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
     /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | 
MHD_USE_ERROR_LOG | MHD_USE_POLL, */
     /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | 
MHD_USE_ERROR_LOG, */
     atoi (argv[1]),
-    NULL, NULL, &ahc_echo, PAGE,
+    NULL, NULL, &ahc_echo, &data_for_handler,
     MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
     MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
     MHD_OPTION_END);
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index d8f58d49..5df56afb 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
  * @file post_example.c
  * @brief example for processing POST requests using libmicrohttpd
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include <stdlib.h>
@@ -285,9 +287,8 @@ serve_simple_form (const void *cls,
   struct MHD_Response *response;
 
   /* return static form */
-  response = MHD_create_response_from_buffer (strlen (form),
-                                              (void *) form,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (form),
+                                                     (const void *) form);
   if (NULL == response)
     return MHD_NO;
   add_session_cookie (session, response);
@@ -422,9 +423,9 @@ not_found_page (const void *cls,
   (void) session; /* Unused. Silent compiler warning. */
 
   /* unsupported HTTP method */
-  response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR),
-                                              (void *) NOT_FOUND_ERROR,
-                                              MHD_RESPMEM_PERSISTENT);
+  response =
+    MHD_create_response_from_buffer_static (strlen (NOT_FOUND_ERROR),
+                                            (const void *) NOT_FOUND_ERROR);
   if (NULL == response)
     return MHD_NO;
   ret = MHD_queue_response (connection,
@@ -643,9 +644,9 @@ create_response (void *cls,
     return ret;
   }
   /* unsupported HTTP method */
-  response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
-                                              (void *) METHOD_ERROR,
-                                              MHD_RESPMEM_PERSISTENT);
+  response =
+    MHD_create_response_from_buffer_static (strlen (METHOD_ERROR),
+                                            (const void *) METHOD_ERROR);
   ret = MHD_queue_response (connection,
                             MHD_HTTP_NOT_ACCEPTABLE,
                             response);
diff --git a/src/examples/querystring_example.c 
b/src/examples/querystring_example.c
index d33767cb..57de5aa7 100644
--- a/src/examples/querystring_example.c
+++ b/src/examples/querystring_example.c
@@ -38,12 +38,12 @@ ahc_echo (void *cls,
           const char *upload_data, size_t *upload_data_size, void **req_cls)
 {
   static int aptr;
-  const char *fmt = cls;
   const char *val;
   char *me;
   struct MHD_Response *response;
   enum MHD_Result ret;
   int resp_len;
+  (void) cls;               /* Unused. Silent compiler warning. */
   (void) url;               /* Unused. Silent compiler warning. */
   (void) version;           /* Unused. Silent compiler warning. */
   (void) upload_data;       /* Unused. Silent compiler warning. */
@@ -58,18 +58,16 @@ ahc_echo (void *cls,
     return MHD_YES;
   }
   *req_cls = NULL;  /* reset when done */
-  if (NULL == fmt)
-    return MHD_NO;  /* The cls must not be NULL */
   val = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "q");
   if (NULL == val)
     return MHD_NO;  /* No "q" argument was found */
-  resp_len = snprintf (NULL, 0, fmt, "q", val);
+  resp_len = snprintf (NULL, 0, PAGE, "q", val);
   if (0 > resp_len)
     return MHD_NO;  /* Error calculating response size */
   me = malloc (resp_len + 1);
   if (me == NULL)
     return MHD_NO;  /* Error allocating memory */
-  if (resp_len != snprintf (me, resp_len + 1, fmt, "q", val))
+  if (resp_len != snprintf (me, resp_len + 1, PAGE, "q", val))
   {
     free (me);
     return MHD_NO;  /* Error forming the response body */
@@ -108,7 +106,7 @@ main (int argc, char *const *argv)
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         (uint16_t) port,
-                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
+                        NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
   if (NULL == d)
     return 1;
   (void) getc (stdin);
diff --git a/src/examples/refuse_post_example.c 
b/src/examples/refuse_post_example.c
index dc261575..70cfe4b3 100644
--- a/src/examples/refuse_post_example.c
+++ b/src/examples/refuse_post_example.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007, 2008 Christian Grothoff (and other contributing 
authors)
+     Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -20,10 +21,16 @@
  * @file refuse_post_example.c
  * @brief example for how to refuse a POST request properly
  * @author Christian Grothoff and Sebastian Gerhardt
+ * @author Karlson2k (Evgeny Grin)
  */
 #include "platform.h"
 #include <microhttpd.h>
 
+struct handler_param
+{
+  const char *response_page;
+};
+
 const char *askpage =
   "<html><body>\n\
                        Upload a file, please!<br>\n\
@@ -44,7 +51,7 @@ ahc_echo (void *cls,
           const char *upload_data, size_t *upload_data_size, void **req_cls)
 {
   static int aptr;
-  const char *me = cls;
+  struct handler_param *param = (struct handler_param *) cls;
   struct MHD_Response *response;
   enum MHD_Result ret;
   (void) cls;               /* Unused. Silent compiler warning. */
@@ -63,9 +70,9 @@ ahc_echo (void *cls,
     /* always to busy for POST requests */
     if (0 == strcmp (method, "POST"))
     {
-      response = MHD_create_response_from_buffer (strlen (BUSYPAGE),
-                                                  (void *) BUSYPAGE,
-                                                  MHD_RESPMEM_PERSISTENT);
+      response =
+        MHD_create_response_from_buffer_static (strlen (BUSYPAGE),
+                                                (const void *) BUSYPAGE);
       ret =
         MHD_queue_response (connection, MHD_HTTP_SERVICE_UNAVAILABLE,
                             response);
@@ -75,9 +82,10 @@ ahc_echo (void *cls,
   }
 
   *req_cls = NULL;                  /* reset when done */
-  response = MHD_create_response_from_buffer (strlen (me),
-                                              (void *) me,
-                                              MHD_RESPMEM_PERSISTENT);
+  response =
+    MHD_create_response_from_buffer_static (strlen (param->response_page),
+                                            (const void *)
+                                            param->response_page);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
   return ret;
@@ -89,15 +97,18 @@ main (int argc, char *const *argv)
 {
   struct MHD_Daemon *d;
 
+  struct handler_param data_for_handler;
+
   if (argc != 2)
   {
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
+  data_for_handler.response_page = askpage;
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, (void *) askpage,
+                        NULL, NULL, &ahc_echo, &data_for_handler,
                         MHD_OPTION_END);
   if (d == NULL)
     return 1;
diff --git a/src/examples/suspend_resume_epoll.c 
b/src/examples/suspend_resume_epoll.c
index 6b660b00..b63f80be 100644
--- a/src/examples/suspend_resume_epoll.c
+++ b/src/examples/suspend_resume_epoll.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2018 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -22,6 +23,7 @@
  *        resume a suspended connection
  * @author Robert D Kocisko
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 #include "platform.h"
 #include <microhttpd.h>
@@ -57,7 +59,6 @@ ahc_echo (void *cls,
   struct itimerspec ts;
 
   (void) cls;
-  (void) url;               /* Unused. Silence compiler warning. */
   (void) method;
   (void) version;           /* Unused. Silence compiler warning. */
   (void) upload_data;       /* Unused. Silence compiler warning. */
@@ -78,9 +79,8 @@ ahc_echo (void *cls,
   if (-1 != req->timerfd)
   {
     /* send response (echo request url) */
-    response = MHD_create_response_from_buffer (strlen (url),
-                                                (void *) url,
-                                                MHD_RESPMEM_MUST_COPY);
+    response = MHD_create_response_from_buffer_copy (strlen (url),
+                                                     (const void *) url);
     if (NULL == response)
       return MHD_NO;
     ret = MHD_queue_response (connection,
diff --git a/src/examples/timeout.c b/src/examples/timeout.c
index b52f508f..dacc93fd 100644
--- a/src/examples/timeout.c
+++ b/src/examples/timeout.c
@@ -1,7 +1,8 @@
 /*
      This file is part of libmicrohttpd
-     Copyright (C) 2016, 2017 Christian Grothoff,
-     Silvio Clecio (silvioprog), Karlson2k (Evgeny Grin)
+     Copyright (C) 2016-2017 Christian Grothoff,
+     Silvio Clecio (silvioprog), Evgeny Grin (Karlson2k)
+     Copyright (C) 2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -50,9 +51,8 @@ answer_to_connection (void *cls,
   (void) upload_data_size;  /* Unused. Silent compiler warning. */
   (void) req_cls;           /* Unused. Silent compiler warning. */
 
-  response = MHD_create_response_from_buffer (strlen (page),
-                                              (void *) page,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (strlen (page),
+                                                     (const void *) page);
   MHD_add_response_header (response,
                            MHD_HTTP_HEADER_CONTENT_TYPE,
                            "text/html");
diff --git a/src/examples/websocket_threaded_example.c 
b/src/examples/websocket_threaded_example.c
index 04b972d4..542d7c3a 100644
--- a/src/examples/websocket_threaded_example.c
+++ b/src/examples/websocket_threaded_example.c
@@ -2,6 +2,7 @@
      This file is part of libmicrohttpd
      Copyright (C) 2020 Christian Grothoff, Silvio Clecio (and other
      contributing authors)
+     Copyright (C) 2020-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -22,6 +23,7 @@
  * @file websocket_threaded_example.c
  * @brief example for how to provide a tiny threaded websocket server
  * @author Silvio Clecio (silvioprog)
+ * @author Karlson2k (Evgeny Grin)
  */
 
 /* TODO: allow to send large messages. */
@@ -434,8 +436,8 @@ send_chat_page (struct MHD_Connection *con)
   struct MHD_Response *res;
   enum MHD_Result ret;
 
-  res = MHD_create_response_from_buffer (strlen (CHAT_PAGE), (void *) 
CHAT_PAGE,
-                                         MHD_RESPMEM_PERSISTENT);
+  res = MHD_create_response_from_buffer_static (strlen (CHAT_PAGE),
+                                                (const void *) CHAT_PAGE);
   ret = MHD_queue_response (con, MHD_HTTP_OK, res);
   MHD_destroy_response (res);
   return ret;
@@ -448,9 +450,9 @@ send_bad_request (struct MHD_Connection *con)
   struct MHD_Response *res;
   enum MHD_Result ret;
 
-  res = MHD_create_response_from_buffer (strlen (BAD_REQUEST_PAGE),
-                                         (void *) BAD_REQUEST_PAGE,
-                                         MHD_RESPMEM_PERSISTENT);
+  res =
+    MHD_create_response_from_buffer_static (strlen (BAD_REQUEST_PAGE),
+                                            (const void *) BAD_REQUEST_PAGE);
   ret = MHD_queue_response (con, MHD_HTTP_BAD_REQUEST, res);
   MHD_destroy_response (res);
   return ret;
@@ -463,9 +465,10 @@ send_upgrade_required (struct MHD_Connection *con)
   struct MHD_Response *res;
   enum MHD_Result ret;
 
-  res = MHD_create_response_from_buffer (strlen (UPGRADE_REQUIRED_PAGE),
-                                         (void *) UPGRADE_REQUIRED_PAGE,
-                                         MHD_RESPMEM_PERSISTENT);
+  res =
+    MHD_create_response_from_buffer_static (strlen (UPGRADE_REQUIRED_PAGE),
+                                            (const void *)
+                                            UPGRADE_REQUIRED_PAGE);
   MHD_add_response_header (res, MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION,
                            WS_SEC_WEBSOCKET_VERSION);
   ret = MHD_queue_response (con, MHD_HTTP_UPGRADE_REQUIRED, res);
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index e0351159..309929ca 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -96,7 +96,7 @@ extern "C"
  * they are parsed as decimal numbers.
  * Example: 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00097503
+#define MHD_VERSION 0x00097507
 
 /* If generic headers don't work on your platform, include headers
    which define 'va_list', 'size_t', 'ssize_t', 'intptr_t',
@@ -3076,7 +3076,6 @@ MHD_get_connection_values_n (struct MHD_Connection 
*connection,
  * return them -- and the `struct MHD_PostProcessor` will also see
  * them).  This maybe required in certain situations (see Mantis
  * #1399) where (broken) HTTP implementations fail to supply values
-
  * needed by the post processor (or other parts of the application).
  *
  * This function MUST only be called from within the
@@ -3500,6 +3499,10 @@ enum MHD_ResponseMemoryMode
    * Buffer is heap-allocated with `malloc()` (or equivalent) and
    * should be freed by MHD after processing the response has
    * concluded (response reference counter reaches zero).
+   * @warning Make sure that your application and MHD are using the same
+   *          C-runtime library (especially important for W32). if in doubt,
+   *          use function MHD_create_response_from_buffer_with_free_callback()
+   *          with '&free' as crfc parameter.
    * @ingroup response
    */
   MHD_RESPMEM_MUST_FREE,
@@ -3539,6 +3542,59 @@ MHD_create_response_from_buffer (size_t size,
                                  enum MHD_ResponseMemoryMode mode);
 
 
+/**
+ * Create a response object with the content of provided statically allocated
+ * buffer used as the response body.
+ *
+ * The buffer must be valid for the lifetime of the response. The easiest way
+ * to achieve this is to use a statically allocated buffer.
+ *
+ * The response object can be extended with header information and then
+ * be used any number of times.
+ *
+ * If response object is used to answer HEAD request then the body
+ * of the response is not used, while all headers (including automatic
+ * headers) are used.
+ *
+ * @param size the size of the data in @a buffer, can be zero
+ * @param buffer the buffer with the data for the response body, can be NULL
+ *               if @a size is zero
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @note Available since #MHD_VERSION 0x00097506
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_buffer_static (size_t size,
+                                        const void *buffer);
+
+
+/**
+ * Create a response object with the content of provided statically allocated
+ * buffer used as the response body.
+ *
+ * An internal copy of the buffer will be made automatically, so buffer have
+ * to be valid only during the call of this function (as a typical example:
+ * buffer is a local (non-static) array).
+ *
+ * The response object can be extended with header information and then
+ * be used any number of times.
+ *
+ * If response object is used to answer HEAD request then the body
+ * of the response is not used, while all headers (including automatic
+ * headers) are used.
+ *
+ * @param size the size of the data in @a buffer, can be zero
+ * @param buffer the buffer with the data for the response body, can be NULL
+ *               if @a size is zero
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @note Available since #MHD_VERSION 0x00097507
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_buffer_copy (size_t size,
+                                      const void *buffer);
+
+
 /**
  * Create a response object with the content of provided buffer used as
  * the response body.
@@ -3582,11 +3638,12 @@ MHD_create_response_from_buffer_with_free_callback 
(size_t size,
  * @param crfc_cls an argument for @a crfc
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @note Available since #MHD_VERSION 0x00097302
+ * @note 'const' qualifier is used for @a buffer since #MHD_VERSION 0x00097504
  * @ingroup response
  */
 _MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_buffer_with_free_callback_cls (size_t size,
-                                                        void *buffer,
+                                                        const void *buffer,
                                                         
MHD_ContentReaderFreeCallback
                                                         crfc,
                                                         void *crfc_cls);
diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c
index b6d88ba3..f3c5f5b9 100644
--- a/src/microhttpd/basicauth.c
+++ b/src/microhttpd/basicauth.c
@@ -43,7 +43,7 @@
  *      to the username if found
  * @ingroup authentication
  */
-char *
+_MHD_EXTERN char *
 MHD_basic_auth_get_username_password (struct MHD_Connection *connection,
                                       char **password)
 {
@@ -120,7 +120,7 @@ MHD_basic_auth_get_username_password (struct MHD_Connection 
*connection,
  * @return #MHD_YES on success, #MHD_NO otherwise
  * @ingroup authentication
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_queue_basic_auth_fail_response (struct MHD_Connection *connection,
                                     const char *realm,
                                     struct MHD_Response *response)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 36e74900..eac75824 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -380,7 +380,7 @@ recv_param_adapter (struct MHD_Connection *connection,
  *         -1 if connection is NULL.
  * @ingroup request
  */
-int
+_MHD_EXTERN int
 MHD_get_connection_values (struct MHD_Connection *connection,
                            enum MHD_ValueKind kind,
                            MHD_KeyValueIterator iterator,
@@ -419,7 +419,7 @@ MHD_get_connection_values (struct MHD_Connection 
*connection,
  *         -1 if connection is NULL.
  * @ingroup request
  */
-int
+_MHD_EXTERN int
 MHD_get_connection_values_n (struct MHD_Connection *connection,
                              enum MHD_ValueKind kind,
                              MHD_KeyValueIteratorN iterator,
@@ -532,7 +532,7 @@ MHD_set_connection_value_n_nocheck_ (struct MHD_Connection 
*connection,
  *         #MHD_YES on success
  * @ingroup request
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_set_connection_value_n (struct MHD_Connection *connection,
                             enum MHD_ValueKind kind,
                             const char *key,
@@ -579,7 +579,7 @@ MHD_set_connection_value_n (struct MHD_Connection 
*connection,
  *         #MHD_YES on success
  * @ingroup request
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_set_connection_value (struct MHD_Connection *connection,
                           enum MHD_ValueKind kind,
                           const char *key,
@@ -608,7 +608,7 @@ MHD_set_connection_value (struct MHD_Connection *connection,
  * @return NULL if no such item was found
  * @ingroup request
  */
-const char *
+_MHD_EXTERN const char *
 MHD_lookup_connection_value (struct MHD_Connection *connection,
                              enum MHD_ValueKind kind,
                              const char *key)
@@ -2391,9 +2391,8 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
     MHD_destroy_response (connection->response);
     connection->response = NULL;
   }
-  response = MHD_create_response_from_buffer (message_len,
-                                              (void *) message,
-                                              MHD_RESPMEM_PERSISTENT);
+  response = MHD_create_response_from_buffer_static (message_len,
+                                                     message);
   if (NULL == response)
   {
 #ifdef HAVE_MESSAGES
@@ -5004,7 +5003,7 @@ MHD_set_http_callbacks_ (struct MHD_Connection 
*connection)
  *         (or if the @a info_type is unknown)
  * @ingroup specialized
  */
-const union MHD_ConnectionInfo *
+_MHD_EXTERN const union MHD_ConnectionInfo *
 MHD_get_connection_info (struct MHD_Connection *connection,
                          enum MHD_ConnectionInfoType info_type,
                          ...)
@@ -5068,7 +5067,7 @@ MHD_get_connection_info (struct MHD_Connection 
*connection,
  * @return #MHD_YES on success, #MHD_NO if setting the option failed
  * @ingroup specialized
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_set_connection_option (struct MHD_Connection *connection,
                            enum MHD_CONNECTION_OPTION option,
                            ...)
@@ -5175,7 +5174,7 @@ MHD_set_connection_option (struct MHD_Connection 
*connection,
  * @ingroup response
  * @sa #MHD_AccessHandlerCallback
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_queue_response (struct MHD_Connection *connection,
                     unsigned int status_code,
                     struct MHD_Response *response)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 1cca1b30..21b82131 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -534,7 +534,7 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
 #endif
       return -1;
     }
-    cert.data = (unsigned char *) daemon->https_mem_trust;
+    cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_trust);
     cert.size = (unsigned int) paramlen;
     if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred,
                                                &cert,
@@ -571,9 +571,9 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
 #endif
       return -1;
     }
-    key.data = (unsigned char *) daemon->https_mem_key;
+    key.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_key);
     key.size = (unsigned int) param1len;
-    cert.data = (unsigned char *) daemon->https_mem_cert;
+    cert.data = (unsigned char *) _MHD_DROP_CONST (daemon->https_mem_cert);
     cert.size = (unsigned int) param2len;
 
     if (NULL != daemon->https_key_password)
@@ -691,7 +691,7 @@ MHD_TLS_init (struct MHD_Daemon *daemon)
  *         fit fd_set.
  * @ingroup event
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_get_fdset (struct MHD_Daemon *daemon,
                fd_set *read_fd_set,
                fd_set *write_fd_set,
@@ -1099,7 +1099,7 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
  *         fit fd_set.
  * @ingroup event
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_get_fdset2 (struct MHD_Daemon *daemon,
                 fd_set *read_fd_set,
                 fd_set *write_fd_set,
@@ -2576,19 +2576,17 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
 #if (GNUTLS_VERSION_NUMBER + 0 >= 0x030200)
     if (! daemon->disable_alpn)
     {
-      gnutls_datum_t prts[2];
-      const char prt1[] = "http/1.1"; /* Registered code for HTTP/1.1 */
-      const char prt2[] = "http/1.0"; /* Registered code for HTTP/1.0 */
-
-      prts[0].data = (void *) prt1;
-      prts[0].size = MHD_STATICSTR_LEN_ (prt1);
-      prts[1].data = (void *) prt2;
-      prts[1].size = MHD_STATICSTR_LEN_ (prt2);
+      static const char prt1[] = "http/1.1"; /* Registered code for HTTP/1.1 */
+      static const char prt2[] = "http/1.0"; /* Registered code for HTTP/1.0 */
+      static const gnutls_datum_t prts[2] =
+      { {_MHD_DROP_CONST (prt1), MHD_STATICSTR_LEN_ (prt1)},
+        {_MHD_DROP_CONST (prt2), MHD_STATICSTR_LEN_ (prt2)} };
+
       if (GNUTLS_E_SUCCESS !=
           gnutls_alpn_set_protocols (connection->tls_session,
                                      prts,
                                      sizeof(prts) / sizeof(prts[0]),
-                                     0 /* || GNUTLS_ALPN_SERVER_PRECEDENCE */))
+                                     0 /* | GNUTLS_ALPN_SERVER_PRECEDENCE */))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
@@ -3171,7 +3169,7 @@ internal_suspend_connection_ (struct MHD_Connection 
*connection)
  *
  * @sa #MHD_AccessHandlerCallback
  */
-void
+_MHD_EXTERN void
 MHD_suspend_connection (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *const daemon = connection->daemon;
@@ -3214,7 +3212,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
  *
  * @param connection the connection to resume
  */
-void
+_MHD_EXTERN void
 MHD_resume_connection (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
@@ -3411,7 +3409,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
  *        set to indicate further details about the error.
  * @ingroup specialized
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_add_connection (struct MHD_Daemon *daemon,
                     MHD_socket client_socket,
                     const struct sockaddr *addr,
@@ -3893,7 +3891,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
  *         not used and no data processing is pending.
  * @ingroup event
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_get_timeout (struct MHD_Daemon *daemon,
                  MHD_UNSIGNED_LONG_LONG *timeout)
 {
@@ -4125,7 +4123,7 @@ internal_run_from_select (struct MHD_Daemon *daemon,
  * @return #MHD_NO on serious errors, #MHD_YES on success
  * @ingroup event
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_run_from_select (struct MHD_Daemon *daemon,
                      const fd_set *read_fd_set,
                      const fd_set *write_fd_set,
@@ -4948,7 +4946,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
          (-1 != daemon->epoll_upgrade_fd) ) )
   {
     event.events = EPOLLIN | EPOLLOUT;
-    event.data.ptr = (void *) upgrade_marker;
+    event.data.ptr = _MHD_DROP_CONST (upgrade_marker);
     if (0 != epoll_ctl (daemon->epoll_fd,
                         EPOLL_CTL_ADD,
                         daemon->epoll_upgrade_fd,
@@ -5205,7 +5203,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
  *         options for this call.
  * @ingroup event
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_run (struct MHD_Daemon *daemon)
 {
   if ( (daemon->shutdown) ||
@@ -5449,7 +5447,7 @@ unescape_wrapper (void *cls,
  * @return NULL on error, handle to daemon on success
  * @ingroup event
  */
-struct MHD_Daemon *
+_MHD_EXTERN struct MHD_Daemon *
 MHD_start_daemon (unsigned int flags,
                   uint16_t port,
                   MHD_AcceptPolicyCallback apc,
@@ -5494,7 +5492,7 @@ MHD_start_daemon (unsigned int flags,
  *         the daemon was already not listening anymore
  * @ingroup specialized
  */
-MHD_socket
+_MHD_EXTERN MHD_socket
 MHD_quiesce_daemon (struct MHD_Daemon *daemon)
 {
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -5850,7 +5848,7 @@ parse_options_va (struct MHD_Daemon *daemon,
 #endif
           return MHD_NO;
         }
-        dhpar.data = (unsigned char *) pstr;
+        dhpar.data = (unsigned char *) _MHD_DROP_CONST (pstr);
         pstr_len = strlen (pstr);
         if (UINT_MAX < pstr_len)
         {
@@ -6340,7 +6338,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
   if (MHD_ITC_IS_VALID_ (daemon->itc))
   {
     event.events = EPOLLIN;
-    event.data.ptr = (void *) epoll_itc_marker;
+    event.data.ptr = _MHD_DROP_CONST (epoll_itc_marker);
     if (0 != epoll_ctl (daemon->epoll_fd,
                         EPOLL_CTL_ADD,
                         MHD_itc_r_fd_ (daemon->itc),
@@ -6382,7 +6380,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
  * @return NULL on error, handle to daemon on success
  * @ingroup event
  */
-struct MHD_Daemon *
+_MHD_EXTERN struct MHD_Daemon *
 MHD_start_daemon_va (unsigned int flags,
                      uint16_t port,
                      MHD_AcceptPolicyCallback apc,
@@ -6743,7 +6741,7 @@ MHD_start_daemon_va (unsigned int flags,
       if (0 > setsockopt (listen_fd,
                           SOL_SOCKET,
                           SO_REUSEADDR,
-                          (void *) &on, sizeof (on)))
+                          (const void *) &on, sizeof (on)))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
@@ -6762,7 +6760,7 @@ MHD_start_daemon_va (unsigned int flags,
       if (0 > setsockopt (listen_fd,
                           SOL_SOCKET,
                           SO_REUSEADDR,
-                          (void *) &on, sizeof (on)))
+                          (const void *) &on, sizeof (on)))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
@@ -6784,7 +6782,7 @@ MHD_start_daemon_va (unsigned int flags,
 #else  /* MHD_WINSOCK_SOCKETS */
                           SO_REUSEADDR,
 #endif /* MHD_WINSOCK_SOCKETS */
-                          (void *) &on,
+                          (const void *) &on,
                           sizeof (on)))
       {
 #ifdef HAVE_MESSAGES
@@ -7651,7 +7649,7 @@ close_all_connections (struct MHD_Daemon *daemon)
  * @param daemon daemon to stop
  * @ingroup event
  */
-void
+_MHD_EXTERN void
 MHD_stop_daemon (struct MHD_Daemon *daemon)
 {
   MHD_socket fd;
@@ -7833,7 +7831,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
  *         (or if the @a info_type is unknown)
  * @ingroup specialized
  */
-const union MHD_DaemonInfo *
+_MHD_EXTERN const union MHD_DaemonInfo *
 MHD_get_daemon_info (struct MHD_Daemon *daemon,
                      enum MHD_DaemonInfoType info_type,
                      ...)
@@ -7889,7 +7887,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
  * @return static version string, e.g. "0.9.9"
  * @ingroup specialized
  */
-const char *
+_MHD_EXTERN const char *
 MHD_get_version (void)
 {
 #ifdef PACKAGE_VERSION
@@ -7901,11 +7899,11 @@ MHD_get_version (void)
     int res = MHD_snprintf_ (ver,
                              sizeof(ver),
                              "%x.%x.%x",
-                             (((int) MHD_VERSION >> 24) & 0xFF),
-                             (((int) MHD_VERSION >> 16) & 0xFF),
-                             (((int) MHD_VERSION >> 8) & 0xFF));
+                             (int) (((uint32_t) MHD_VERSION >> 24) & 0xFF),
+                             (int) (((uint32_t) MHD_VERSION >> 16) & 0xFF),
+                             (int) (((uint32_t) MHD_VERSION >> 8) & 0xFF));
     if ((0 >= res) || (sizeof(ver) <= res))
-      return "0.0.0"; /* Can't return real version*/
+      return "0.0.0"; /* Can't return real version */
   }
   return ver;
 #endif /* !PACKAGE_VERSION */
@@ -7923,7 +7921,7 @@ MHD_get_version (void)
  * feature is not supported or feature is unknown.
  * @ingroup specialized
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_is_feature_supported (enum MHD_FEATURE feature)
 {
   switch (feature)
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 8526ae40..8b9abd18 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -614,7 +614,7 @@ check_nonce_nc (struct MHD_Connection *connection,
  * @warning Returned value must be freed by #MHD_free().
  * @ingroup authentication
  */
-char *
+_MHD_EXTERN char *
 MHD_digest_auth_get_username (struct MHD_Connection *connection)
 {
   char user[MAX_USERNAME_LENGTH];
@@ -1342,7 +1342,7 @@ MHD_digest_auth_check_digest (struct MHD_Connection 
*connection,
  * @note Available since #MHD_VERSION 0x00096200
  * @ingroup authentication
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
                                const char *realm,
                                const char *opaque,
@@ -1470,7 +1470,7 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection 
*connection,
  * @ingroup authentication
  * @deprecated use MHD_queue_auth_fail_response2()
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_queue_auth_fail_response (struct MHD_Connection *connection,
                               const char *realm,
                               const char *opaque,
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index 055deb32..5453329c 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -142,7 +142,7 @@ MHD_unescape_plus (char *arg)
  * @return length of the resulting val (`strlen(val)` may be
  *  shorter afterwards due to elimination of escape sequences)
  */
-size_t
+_MHD_EXTERN size_t
 MHD_http_unescape (char *val)
 {
   char *rpos = val;
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 50c1a1ec..3bedf8ed 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -63,6 +63,13 @@
 #include "mhd_sockets.h"
 #include "mhd_itc_types.h"
 
+/**
+ * Macro to drop 'const' qualifier from pointer without compiler warning.
+ * To be used *only* to deal with broken external APIs, which require non-const
+ * pointer to unmodifiable data.
+ * Must not be used to transform pointers for MHD needs.
+ */
+#define _MHD_DROP_CONST(ptr)    ((void *)((uintptr_t)((const void *)(ptr))))
 
 /**
  * @def _MHD_MACRO_NO
@@ -449,7 +456,7 @@ struct MHD_Response
    * Buffer pointing to data that we are supposed
    * to send as a response.
    */
-  char *data;
+  const char *data;
 
   /**
    * Closure to give to the content reader @e crc
diff --git a/src/microhttpd/mhd_panic.c b/src/microhttpd/mhd_panic.c
index 1efba20d..ae2db248 100644
--- a/src/microhttpd/mhd_panic.c
+++ b/src/microhttpd/mhd_panic.c
@@ -88,7 +88,7 @@ mhd_panic_std (void *cls,
  * @param cls passed to @a cb
  * @ingroup logging
  */
-void
+_MHD_EXTERN void
 MHD_set_panic_func (MHD_PanicCallback cb,
                     void *cls)
 {
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index f0ebd38d..009283d6 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -1054,9 +1054,9 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
 #endif /* ! HAVE_SENDMSG */
                    push_hdr || push_body);
 #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
-  vector[0].iov_base = (void *) header;
+  vector[0].iov_base = _MHD_DROP_CONST (header);
   vector[0].iov_len = header_size;
-  vector[1].iov_base = (void *) body;
+  vector[1].iov_base = _MHD_DROP_CONST (body);
   vector[1].iov_len = body_size;
 
 #if defined(HAVE_SENDMSG)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index 08781cb9..fdbed4f8 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1366,7 +1366,7 @@ MHD_bin_to_hex (const void *bin,
   for (i = 0; i < size; ++i)
   {
     uint8_t j;
-    const uint8_t b = ((uint8_t *) bin)[i];
+    const uint8_t b = ((const uint8_t *) bin)[i];
     j = b >> 4;
     hex[i * 2] = (char) ((j < 10) ? (j + '0') : (j - 10 + 'a'));
     j = b & 0x0f;
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 0d6a00ab..d32ecc22 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -252,7 +252,7 @@ struct MHD_PostProcessor
 };
 
 
-struct MHD_PostProcessor *
+_MHD_EXTERN struct MHD_PostProcessor *
 MHD_create_post_processor (struct MHD_Connection *connection,
                            size_t buffer_size,
                            MHD_PostDataIterator iter,
@@ -1455,7 +1455,7 @@ END:
 }
 
 
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_post_process (struct MHD_PostProcessor *pp,
                   const char *post_data,
                   size_t post_data_len)
@@ -1483,7 +1483,7 @@ MHD_post_process (struct MHD_PostProcessor *pp,
 }
 
 
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
 {
   enum MHD_Result ret;
diff --git a/src/microhttpd/reason_phrase.c b/src/microhttpd/reason_phrase.c
index 9a07b2ad..5ccc44b4 100644
--- a/src/microhttpd/reason_phrase.c
+++ b/src/microhttpd/reason_phrase.c
@@ -174,7 +174,7 @@ static const struct MHD_Reason_Block reasons[] = {
 };
 
 
-const char *
+_MHD_EXTERN const char *
 MHD_get_reason_phrase_for (unsigned int code)
 {
   if ( (code >= 100) &&
@@ -185,7 +185,7 @@ MHD_get_reason_phrase_for (unsigned int code)
 }
 
 
-size_t
+_MHD_EXTERN size_t
 MHD_get_reason_phrase_len_for (unsigned int code)
 {
   if ( (code >= 100) &&
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 8ac0c58e..47e28046 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -1,7 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007-2021 Daniel Pittman and Christian Grothoff
-     Copyright (C) 2015-2021 Evgeny Grin (Karlson2k)
+     Copyright (C) 2015-2022 Evgeny Grin (Karlson2k)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -489,7 +489,7 @@ del_response_header_connection (struct MHD_Response 
*response,
  *         or out of memory
  * @ingroup response
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_add_response_header (struct MHD_Response *response,
                          const char *header,
                          const char *content)
@@ -584,7 +584,7 @@ MHD_add_response_header (struct MHD_Response *response,
  * @return #MHD_NO on error (i.e. invalid footer or content format).
  * @ingroup response
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_add_response_footer (struct MHD_Response *response,
                          const char *footer,
                          const char *content)
@@ -610,7 +610,7 @@ MHD_add_response_footer (struct MHD_Response *response,
  * @return #MHD_NO on error (no such header known)
  * @ingroup response
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_del_response_header (struct MHD_Response *response,
                          const char *header,
                          const char *content)
@@ -692,7 +692,7 @@ MHD_del_response_header (struct MHD_Response *response,
  * @return number of entries iterated over
  * @ingroup response
  */
-int
+_MHD_EXTERN int
 MHD_get_response_headers (struct MHD_Response *response,
                           MHD_KeyValueIterator iterator,
                           void *iterator_cls)
@@ -724,7 +724,7 @@ MHD_get_response_headers (struct MHD_Response *response,
  * @return NULL if header does not exist
  * @ingroup response
  */
-const char *
+_MHD_EXTERN const char *
 MHD_get_response_header (struct MHD_Response *response,
                          const char *key)
 {
@@ -856,7 +856,7 @@ MHD_check_response_header_token_ci (const struct 
MHD_Response *response,
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_callback (uint64_t size,
                                    size_t block_size,
                                    MHD_ContentReaderCallback crc,
@@ -897,7 +897,7 @@ MHD_create_response_from_callback (uint64_t size,
  * @param ... #MHD_RO_END terminated list of options
  * @return #MHD_YES on success, #MHD_NO on error
  */
-enum MHD_Result
+_MHD_EXTERN enum MHD_Result
 MHD_set_response_options (struct MHD_Response *response,
                           enum MHD_ResponseFlags flags,
                           ...)
@@ -1111,7 +1111,7 @@ free_callback (void *cls)
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_fd_at_offset (size_t size,
                                        int fd,
                                        off_t offset)
@@ -1231,7 +1231,7 @@ MHD_create_response_from_pipe (int fd)
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_fd (size_t size,
                              int fd)
 {
@@ -1290,55 +1290,22 @@ MHD_create_response_from_fd64 (uint64_t size,
  * @deprecated use #MHD_create_response_from_buffer instead
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_data (size_t size,
                                void *data,
                                int must_free,
                                int must_copy)
 {
-  struct MHD_Response *response;
-  void *tmp;
+  enum MHD_ResponseMemoryMode mode;
 
-  if ((NULL == data) && (size > 0))
-    return NULL;
-  if (MHD_SIZE_UNKNOWN == size)
-    return NULL;
-  if (NULL == (response = MHD_calloc_ (1, sizeof (struct MHD_Response))))
-    return NULL;
-  response->fd = -1;
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-  if (! MHD_mutex_init_ (&response->mutex))
-  {
-    free (response);
-    return NULL;
-  }
-#endif
-  if ((must_copy) && (size > 0))
-  {
-    if (NULL == (tmp = malloc (size)))
-    {
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-      MHD_mutex_destroy_chk_ (&response->mutex);
-#endif
-      free (response);
-      return NULL;
-    }
-    memcpy (tmp, data, size);
-    must_free = MHD_YES;
-    data = tmp;
-  }
-  if (must_free)
-  {
-    response->crfc = &free;
-    response->crc_cls = data;
-  }
-  response->reference_count = 1;
-  response->total_size = size;
-  response->data = data;
-  response->data_size = size;
-  if (must_copy)
-    response->data_buffer_size = size;
-  return response;
+  if (0 != must_copy)
+    mode = MHD_RESPMEM_MUST_COPY;
+  else if (0 != must_free)
+    mode = MHD_RESPMEM_MUST_FREE;
+  else
+    mode = MHD_RESPMEM_PERSISTENT;
+
+  return MHD_create_response_from_buffer (size, data, mode);
 }
 
 
@@ -1359,15 +1326,114 @@ MHD_create_response_from_data (size_t size,
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_buffer (size_t size,
                                  void *buffer,
                                  enum MHD_ResponseMemoryMode mode)
 {
-  return MHD_create_response_from_data (size,
-                                        buffer,
-                                        mode == MHD_RESPMEM_MUST_FREE,
-                                        mode == MHD_RESPMEM_MUST_COPY);
+  if (MHD_RESPMEM_MUST_FREE == mode)
+    return MHD_create_response_from_buffer_with_free_callback_cls (size,
+                                                                   buffer,
+                                                                   &free,
+                                                                   buffer);
+  if (MHD_RESPMEM_MUST_COPY == mode)
+    return MHD_create_response_from_buffer_copy (size,
+                                                 buffer);
+
+  return MHD_create_response_from_buffer_with_free_callback_cls (size,
+                                                                 buffer,
+                                                                 NULL,
+                                                                 NULL);
+}
+
+
+/**
+ * Create a response object with the content of provided statically allocated
+ * buffer used as the response body.
+ *
+ * The buffer must be valid for the lifetime of the response. The easiest way
+ * to achieve this is to use a statically allocated buffer.
+ *
+ * The response object can be extended with header information and then
+ * be used any number of times.
+ *
+ * If response object is used to answer HEAD request then the body
+ * of the response is not used, while all headers (including automatic
+ * headers) are used.
+ *
+ * @param size the size of the data in @a buffer, can be zero
+ * @param buffer the buffer with the data for the response body, can be NULL
+ *               if @a size is zero
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @note Available since #MHD_VERSION 0x00097506
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_buffer_static (size_t size,
+                                        const void *buffer)
+{
+  return MHD_create_response_from_buffer_with_free_callback_cls (size,
+                                                                 buffer,
+                                                                 NULL,
+                                                                 NULL);
+}
+
+
+/**
+ * Create a response object with the content of provided statically allocated
+ * buffer used as the response body.
+ *
+ * An internal copy of the buffer will be made automatically, so buffer have
+ * to be valid only during the call of this function (as a typical example:
+ * buffer is a local (non-static) array).
+ *
+ * The response object can be extended with header information and then
+ * be used any number of times.
+ *
+ * If response object is used to answer HEAD request then the body
+ * of the response is not used, while all headers (including automatic
+ * headers) are used.
+ *
+ * @param size the size of the data in @a buffer, can be zero
+ * @param buffer the buffer with the data for the response body, can be NULL
+ *               if @a size is zero
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @note Available since #MHD_VERSION 0x00097507
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_buffer_copy (size_t size,
+                                      const void *buffer)
+{
+  struct MHD_Response *r;
+  void *mhd_copy;
+
+  if (0 == size)
+    return MHD_create_response_from_buffer_with_free_callback_cls (0,
+                                                                   NULL,
+                                                                   NULL,
+                                                                   NULL);
+  if (NULL == buffer)
+    return NULL;
+
+  mhd_copy = malloc (size);
+  if (NULL == mhd_copy)
+    return NULL;
+  memcpy (mhd_copy, buffer, size);
+
+  r = MHD_create_response_from_buffer_with_free_callback_cls (size,
+                                                              mhd_copy,
+                                                              &free,
+                                                              mhd_copy);
+  if (NULL == r)
+    free (mhd_copy);
+  else
+  {
+    /* TODO: remove the next assignment, the buffer should not be modifiable */
+    r->data_buffer_size = size;
+  }
+
+  return r;
 }
 
 
@@ -1394,16 +1460,10 @@ MHD_create_response_from_buffer_with_free_callback 
(size_t size,
                                                     
MHD_ContentReaderFreeCallback
                                                     crfc)
 {
-  struct MHD_Response *r;
-
-  r = MHD_create_response_from_data (size,
-                                     buffer,
-                                     MHD_YES,
-                                     MHD_NO);
-  if (NULL == r)
-    return r;
-  r->crfc = crfc;
-  return r;
+  return MHD_create_response_from_buffer_with_free_callback_cls (size,
+                                                                 buffer,
+                                                                 crfc,
+                                                                 buffer);
 }
 
 
@@ -1425,22 +1485,39 @@ MHD_create_response_from_buffer_with_free_callback 
(size_t size,
  * @param crfc_cls an argument for @a crfc
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @note Available since #MHD_VERSION 0x00097302
+ * @note 'const' qualifier is used for @a buffer since #MHD_VERSION 0x00097504
  * @ingroup response
  */
 _MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_buffer_with_free_callback_cls (size_t size,
-                                                        void *buffer,
+                                                        const void *buffer,
                                                         
MHD_ContentReaderFreeCallback
                                                         crfc,
                                                         void *crfc_cls)
 {
   struct MHD_Response *r;
 
-  r = MHD_create_response_from_buffer_with_free_callback (size,
-                                                          buffer,
-                                                          crfc);
-  if (NULL != r)
-    r->crc_cls = crfc_cls;
+  if ((NULL == buffer) && (size > 0))
+    return NULL;
+  if (MHD_SIZE_UNKNOWN == size)
+    return NULL;
+  r = MHD_calloc_ (1, sizeof (struct MHD_Response));
+  if (NULL == r)
+    return NULL;
+#if defined(MHD_USE_THREADS)
+  if (! MHD_mutex_init_ (&r->mutex))
+  {
+    free (r);
+    return NULL;
+  }
+#endif
+  r->fd = -1;
+  r->reference_count = 1;
+  r->total_size = size;
+  r->data = buffer;
+  r->data_size = size;
+  r->crfc = crfc;
+  r->crc_cls = crfc_cls;
   return r;
 }
 
@@ -1544,7 +1621,7 @@ MHD_create_response_from_iovec (const struct MHD_IoVec 
*iov,
   if (1 == i_cp)
   {
     mhd_assert (NULL != last_valid_buffer);
-    response->data = (void *) last_valid_buffer;
+    response->data = last_valid_buffer;
     response->data_size = (size_t) total_size;
     return response;
   }
@@ -1573,14 +1650,14 @@ MHD_create_response_from_iovec (const struct MHD_IoVec 
*iov,
 #if defined(MHD_WINSOCK_SOCKETS) && defined(_WIN64)
       while (MHD_IOV_ELMN_MAX_SIZE < element_size)
       {
-        iov_copy[i_cp].iov_base = (char *) buf;
+        iov_copy[i_cp].iov_base = (char *) _MHD_DROP_CONST (buf);
         iov_copy[i_cp].iov_len = ULONG_MAX;
         buf += ULONG_MAX;
         element_size -= ULONG_MAX;
         i_cp++;
       }
 #endif /* MHD_WINSOCK_SOCKETS && _WIN64 */
-      iov_copy[i_cp].iov_base = (void *) buf;
+      iov_copy[i_cp].iov_base = _MHD_DROP_CONST (buf);
       iov_copy[i_cp].iov_len = (MHD_iov_size_) element_size;
       i_cp++;
     }
@@ -1607,7 +1684,7 @@ MHD_create_response_from_iovec (const struct MHD_IoVec 
*iov,
  * @note Available since #MHD_VERSION 0x00097503
  * @ingroup response
  */
-struct MHD_Response *
+_MHD_EXTERN struct MHD_Response *
 MHD_create_response_empty (enum MHD_ResponseFlags flags)
 {
   struct MHD_Response *r;
@@ -2038,7 +2115,7 @@ MHD_create_response_for_upgrade (MHD_UpgradeHandler 
upgrade_handler,
  * @param response response to destroy
  * @ingroup response
  */
-void
+_MHD_EXTERN void
 MHD_destroy_response (struct MHD_Response *response)
 {
   struct MHD_HTTP_Res_Header *pos;
diff --git a/src/microhttpd/response.h b/src/microhttpd/response.h
index 4d1e84b5..ba6c4ab8 100644
--- a/src/microhttpd/response.h
+++ b/src/microhttpd/response.h
@@ -1,7 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007 Daniel Pittman and Christian Grothoff
-     Copyright (C) 2015-2021 Karlson2k (Evgeny Grin)
+     Copyright (C) 2015-2022 Karlson2k (Evgeny Grin)
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]