gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (0a4537e8 -> 1afe8c4a)


From: gnunet
Subject: [libmicrohttpd] branch master updated (0a4537e8 -> 1afe8c4a)
Date: Sun, 13 Jun 2021 20:55:21 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 0a4537e8 connection.c: fixed wrong caseless HTTP method comparison
     new fae8fc5b uncrustify.cfg minor fix
     new 3bd79348 MHD_create_response_*() functions: improved doxy
     new bbbcf483 MHD_add_response_header: added detailed comment about 
automatic headers
     new a6017386 MHD_queue_response(): refuse 1xx codes in HTTP/1.0 mode
     new 1afe8c4a mhd_str: fixed typo in a comment

The 5 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:
 contrib/uncrustify.cfg      |   2 +-
 src/include/microhttpd.h    | 131 ++++++++++++++++++++++++++++++++--------
 src/microhttpd/connection.c |  39 ++++++++++--
 src/microhttpd/mhd_str.c    |   2 +-
 src/microhttpd/mhd_str.h    |   2 +-
 src/microhttpd/response.c   | 143 ++++++++++++++++++++++++++++++++++++--------
 6 files changed, 260 insertions(+), 59 deletions(-)

diff --git a/contrib/uncrustify.cfg b/contrib/uncrustify.cfg
index c751b42a..c21b15b7 100644
--- a/contrib/uncrustify.cfg
+++ b/contrib/uncrustify.cfg
@@ -76,7 +76,7 @@ sp_inside_fparen = remove
 sp_inside_sparen = remove
 
 # Add or remove space around compare operator '<', '>', '==', etc
-sp_compare                                = force    # ignore/add/remove/force
+sp_compare                                = add    # ignore/add/remove/force
 
 # add space before function call and decl: "foo (x)"
 sp_func_call_paren = add
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 4c9937bf..4f09bee5 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -3208,8 +3208,15 @@ enum MHD_ResponseMemoryMode
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -3224,8 +3231,15 @@ MHD_create_response_from_buffer (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -3242,9 +3256,15 @@ MHD_create_response_from_buffer_with_free_callback 
(size_t size,
 
 
 /**
- * Create a response object.
- * The response object can be extended with header information and then be
- * used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -3264,8 +3284,15 @@ MHD_create_response_from_buffer_with_free_callback_cls 
(size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the
@@ -3280,8 +3307,15 @@ MHD_create_response_from_fd (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used ONLY ONCE.
+ * Create a response object with the response body created by reading
+ * the provided pipe.
+ *
+ * The response object can be extended with header information and
+ * then be used ONLY ONCE.
+ *
+ * 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 fd file descriptor referring to a read-end of a pipe with the
  *        data; will be closed when response is destroyed;
@@ -3295,8 +3329,15 @@ MHD_create_response_from_pipe (int fd);
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response;
  *        sizes larger than 2 GiB may be not supported by OS or
@@ -3313,8 +3354,15 @@ MHD_create_response_from_fd64 (uint64_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file with
+ * specified offset used as the response body.
+ *
+ * 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 size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the
@@ -3346,8 +3394,15 @@ MHD_create_response_from_fd_at_offset (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file with
+ * specified offset used as the response body.
+ *
+ * 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 size of the data portion of the response;
  *        sizes larger than 2 GiB may be not supported by OS or
@@ -3368,9 +3423,15 @@ MHD_create_response_from_fd_at_offset64 (uint64_t size,
 
 
 /**
- * Create a response object from an array of memory buffers.
- * The response object can be extended with header information and then be used
- * any number of times.
+ * Create a response object with an array of memory buffers
+ * used as the response body.
+ *
+ * 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 iov the array for response data buffers, an internal copy of this
  *        will be made
@@ -3551,10 +3612,32 @@ MHD_destroy_response (struct MHD_Response *response);
 /**
  * Add a header line to the response.
  *
- * @param response response to add a header to
- * @param header the header to add
- * @param content value to add
- * @return #MHD_NO on error (i.e. invalid header or content format),
+ * When reply is generated with queued response, some headers are generated
+ * automatically. Automatically generated headers are only sent to the client,
+ * but not added back to the response.
+ *
+ * The list of automatic headers:
+ * + "Date" header is added automatically unless already set by
+ *   this function
+ * + "Content-Length" is added automatically when required, attempt to set
+ *   it manually by this function is ignored.
+ *   @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
+ * + "Transfer-Encoding" with value "chunked" is added automatically,
+ *   when chunked transfer encoding is used automatically. Same header with
+ *   the same value can be set manually by this function to enforce chunked
+ *   encoding, however for HTTP/1.0 clients chunked encoding will not be used
+ *   and manually set "Transfer-Encoding" header is automatically removed
+ *   for HTTP/1.0 clients
+ * + "Connection" is added automatically with value "Keep-Alive" or "Close".
+ *   The header "Connection" with value "Close" could be set by this function
+ *   to enforce closure of the connection after sending this response.
+ *   "Keep-Alive" cannot be enforced and will be removed automatically.
+ *
+ * @param response the response to add a header to
+ * @param header the header name to add
+ * @param content the header value to add
+ * @return #MHD_YES on success,
+ *         #MHD_NO on error (i.e. invalid header or content format),
  *         or out of memory
  * @ingroup response
  */
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 3d98f917..e274ace5 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -4247,12 +4247,6 @@ MHD_queue_response (struct MHD_Connection *connection,
 {
   struct MHD_Daemon *daemon;
 
-  if ( (NULL == connection) ||
-       (NULL == response) ||
-       (NULL != connection->response) ||
-       ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
-         (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
-    return MHD_NO;
   daemon = connection->daemon;
 
   if (daemon->shutdown)
@@ -4271,6 +4265,14 @@ MHD_queue_response (struct MHD_Connection *connection,
     return MHD_NO;
   }
 #endif
+
+  if ( (NULL == connection) ||
+       (NULL == response) ||
+       (NULL != connection->response) ||
+       ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) &&
+         (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
+    return MHD_NO;
+
 #ifdef UPGRADE_SUPPORT
   if ( (NULL != response->upgrade_handler) &&
        (0 == (daemon->options & MHD_ALLOW_UPGRADE)) )
@@ -4304,6 +4306,31 @@ MHD_queue_response (struct MHD_Connection *connection,
 #endif
     return MHD_NO;
   }
+  if (200 > (status_code & (~MHD_ICY_FLAG)))
+  {
+    if (MHD_HTTP_VER_1_0 == connection->http_ver)
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Wrong status code (%u) refused. " \
+                   "HTTP/1.0 clients do not support 1xx status codes!\n"),
+                (status_code & (~MHD_ICY_FLAG)));
+#endif
+      return MHD_NO;
+    }
+    if (0 != response->flags & (MHD_RF_HTTP_VERSION_1_0_ONLY
+                                | MHD_RF_HTTP_VERSION_1_0_RESPONSE))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Wrong status code (%u) refused. " \
+                   "HTTP/1.0 reply mode does not support 1xx status codes!\n"),
+                (status_code & (~MHD_ICY_FLAG)));
+#endif
+      return MHD_NO;
+    }
+  }
+
   MHD_increment_response_rc (response);
   connection->response = response;
   connection->responseCode = status_code;
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index c0218bca..eea2500b 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -336,7 +336,7 @@ toxdigitvalue (char c)
 
 #ifndef MHD_FAVOR_SMALL_CODE
 /**
- * Check two string for equality, ignoring case of US-ASCII letters.
+ * Check two strings for equality, ignoring case of US-ASCII letters.
  *
  * @param str1 first string to compare
  * @param str2 second string to compare
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index 25eeb05e..80f3f975 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -52,7 +52,7 @@
 
 #ifndef MHD_FAVOR_SMALL_CODE
 /**
- * Check two string for equality, ignoring case of US-ASCII letters.
+ * Check two strings for equality, ignoring case of US-ASCII letters.
  * @param str1 first string to compare
  * @param str2 second string to compare
  * @return non-zero if two strings are equal, zero otherwise.
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index eb29ab64..ff034194 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -124,10 +124,33 @@ add_response_entry (struct MHD_Response *response,
 /**
  * Add a header line to the response.
  *
- * @param response response to add a header to
- * @param header the header to add
- * @param content value to add
- * @return #MHD_NO on error (i.e. invalid header or content format).
+ * When reply is generated with queued response, some headers are generated
+ * automatically. Automatically generated headers are only sent to the client,
+ * but not added back to the response.
+ *
+ * The list of automatic headers:
+ * + "Date" header is added automatically unless already set by
+ *   this function
+ * + "Content-Length" is added automatically when required, attempt to set
+ *   it manually by this function is ignored.
+ *   @see #MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
+ * + "Transfer-Encoding" with value "chunked" is added automatically,
+ *   when chunked transfer encoding is used automatically. Same header with
+ *   the same value can be set manually by this function to enforce chunked
+ *   encoding, however for HTTP/1.0 clients chunked encoding will not be used
+ *   and manually set "Transfer-Encoding" header is automatically removed
+ *   for HTTP/1.0 clients
+ * + "Connection" is added automatically with value "Keep-Alive" or "Close".
+ *   The header "Connection" with value "Close" could be set by this function
+ *   to enforce closure of the connection after sending this response.
+ *   "Keep-Alive" cannot be enforced and will be removed automatically.
+ *
+ * @param response the response to add a header to
+ * @param header the header name to add
+ * @param content the header value to add
+ * @return #MHD_YES on success,
+ *         #MHD_NO on error (i.e. invalid header or content format),
+ *         or out of memory
  * @ingroup response
  */
 enum MHD_Result
@@ -588,8 +611,15 @@ free_callback (void *cls)
 #undef MHD_create_response_from_fd_at_offset
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file with
+ * specified offset used as the response body.
+ *
+ * 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 size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the
@@ -615,8 +645,15 @@ MHD_create_response_from_fd_at_offset (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file with
+ * specified offset used as the response body.
+ *
+ * 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 size of the data portion of the response;
  *        sizes larger than 2 GiB may be not supported by OS or
@@ -665,8 +702,15 @@ MHD_create_response_from_fd_at_offset64 (uint64_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used ONLY ONCE.
+ * Create a response object with the response body created by reading
+ * the provided pipe.
+ *
+ * The response object can be extended with header information and
+ * then be used ONLY ONCE.
+ *
+ * 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 fd file descriptor referring to a read-end of a pipe with the
  *        data; will be closed when response is destroyed;
@@ -694,8 +738,15 @@ MHD_create_response_from_pipe (int fd)
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the data
@@ -713,8 +764,15 @@ MHD_create_response_from_fd (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided file used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response;
  *        sizes larger than 2 GiB may be not supported by OS or
@@ -736,8 +794,15 @@ MHD_create_response_from_fd64 (uint64_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the @a data portion of the response
  * @param data the data itself
@@ -800,8 +865,15 @@ MHD_create_response_from_data (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -822,8 +894,15 @@ MHD_create_response_from_buffer (size_t size,
 
 
 /**
- * Create a response object.  The response object can be extended with
- * header information and then be used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -851,9 +930,15 @@ MHD_create_response_from_buffer_with_free_callback (size_t 
size,
 
 
 /**
- * Create a response object.
- * The response object can be extended with header information and then be
- * used any number of times.
+ * Create a response object with the content of provided buffer used as
+ * the response body.
+ *
+ * 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 size of the data portion of the response
  * @param buffer size bytes containing the response's data portion
@@ -883,9 +968,15 @@ MHD_create_response_from_buffer_with_free_callback_cls 
(size_t size,
 
 
 /**
- * Create a response object from an array of memory buffers.
- * The response object can be extended with header information and then be used
- * any number of times.
+ * Create a response object with an array of memory buffers
+ * used as the response body.
+ *
+ * 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 iov the array for response data buffers, an internal copy of this
  *        will be made

-- 
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]