gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (02634d01 -> 1a46bfd6)


From: gnunet
Subject: [libmicrohttpd] branch master updated (02634d01 -> 1a46bfd6)
Date: Mon, 07 Mar 2022 19:36:07 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 02634d01 daemon: fixed new compiler warnings
     new e9292a95 connection.c: added function to check used reply
     new f46f4b75 MHD_queue_response(): improved doxy
     new aa69e178 response: added automatic flag MHD_RAF_HAS_CONTENT_LENGTH
     new edf32d51 response.c: fixed coding style
     new 406c434c response headers: do not add automatic "Content-Length" 
header if response already has it
     new 56a7664a reply: warn if manual "Content-Length" is used when this 
header is not allowed
     new 1a46bfd6 memorypool: fixed: unpoison memory for ASAN before destroying 
pool

The 7 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:
 src/include/microhttpd.h    |  5 +++
 src/microhttpd/connection.c | 78 +++++++++++++++++++++++++++++++++++----------
 src/microhttpd/internal.h   |  5 +--
 src/microhttpd/memorypool.c |  2 +-
 src/microhttpd/response.c   | 38 ++++++++++++++++++----
 5 files changed, 102 insertions(+), 26 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 42409403..d26702da 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -3224,6 +3224,11 @@ MHD_lookup_connection_value_n (struct MHD_Connection 
*connection,
  * For suspended connection this function can be called at any moment. Response
  * will be sent as soon as connection is resumed.
  *
+ * 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. In practice, the same response object can be used to respond to
+ * both HEAD and GET requests.
+ *
  * @param connection the connection identifying the client
  * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
  * @param response response to transmit, the NULL is tolerated
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index f6a871c0..def03b68 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1814,6 +1814,41 @@ setup_reply_properties (struct MHD_Connection 
*connection)
 }
 
 
+/**
+ * Check whether queued response is suitable for @a connection.
+ * @param connection to connection to check
+ */
+static void
+check_connection_reply (struct MHD_Connection *connection)
+{
+  struct MHD_Connection *const c = connection; /**< a short alias */
+  struct MHD_Response *const r = c->response;  /**< a short alias */
+  mhd_assert (c->rp_props.set);
+
+#ifdef HAVE_MESSAGES
+  if ((! c->rp_props.use_reply_body_headers) && (0 != r->total_size))
+  {
+    MHD_DLOG (c->daemon,
+              _ ("This reply with response code %u cannot use reply body. "
+                 "Non-empty response body is ignored and not used.\n"),
+              (unsigned) (c->responseCode & (~MHD_ICY_FLAG)));
+  }
+  if ( (! c->rp_props.use_reply_body_headers) &&
+       (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) )
+  {
+    MHD_DLOG (c->daemon,
+              _ ("This reply with response code %u cannot use reply body. "
+                 "Application defined \"Content-Length\" header violates"
+                 "HTTP specification.\n"),
+              (unsigned) (c->responseCode & (~MHD_ICY_FLAG)));
+  }
+#else
+  (void) c; /* Mute compiler warning */
+  (void) r; /* Mute compiler warning */
+#endif
+}
+
+
 /**
  * Append data to the buffer if enough space is available,
  * update position.
@@ -2012,6 +2047,8 @@ build_header_response (struct MHD_Connection *connection)
               ! c->rp_props.use_reply_body_headers);
 #endif /* UPGRADE_SUPPORT */
 
+  check_connection_reply (c);
+
   rcode = (unsigned) (c->responseCode & (~MHD_ICY_FLAG));
   if (MHD_CONN_MUST_CLOSE == c->keepalive)
   {
@@ -2147,6 +2184,7 @@ build_header_response (struct MHD_Connection *connection)
   if (c->rp_props.use_reply_body_headers)
   {
     /* Body-specific headers */
+
     if (c->rp_props.chunked)
     { /* Chunked encoding is used */
       if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))
@@ -2157,23 +2195,26 @@ build_header_response (struct MHD_Connection 
*connection)
           return MHD_NO;
       }
     }
-    else
-    { /* Chunked encoding is not used */
+    else /* Chunked encoding is not used */
+    {
       if (MHD_SIZE_UNKNOWN != r->total_size)
-      {
-        if (! buffer_append_s (buf, &pos, buf_size,
-                               MHD_HTTP_HEADER_CONTENT_LENGTH ": "))
-          return MHD_NO;
-        el_size = MHD_uint64_to_str (r->total_size, buf + pos,
-                                     buf_size - pos);
-        if (0 == el_size)
-          return MHD_NO;
-        pos += el_size;
-
-        if (buf_size < pos + 2)
-          return MHD_NO;
-        buf[pos++] = '\r';
-        buf[pos++] = '\n';
+      { /* The size is known */
+        if (0 == (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH))
+        { /* The response does not have "Content-Length" header */
+          if (! buffer_append_s (buf, &pos, buf_size,
+                                 MHD_HTTP_HEADER_CONTENT_LENGTH ": "))
+            return MHD_NO;
+          el_size = MHD_uint64_to_str (r->total_size, buf + pos,
+                                       buf_size - pos);
+          if (0 == el_size)
+            return MHD_NO;
+          pos += el_size;
+
+          if (buf_size < pos + 2)
+            return MHD_NO;
+          buf[pos++] = '\r';
+          buf[pos++] = '\n';
+        }
       }
     }
   }
@@ -5082,6 +5123,11 @@ MHD_set_connection_option (struct MHD_Connection 
*connection,
  * For suspended connection this function can be called at any moment. Response
  * will be sent as soon as connection is resumed.
  *
+ * 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. In practice, the same response object can be used to respond to
+ * both HEAD and GET requests.
+ *
  * @param connection the connection identifying the client
  * @param status_code HTTP status code (i.e. #MHD_HTTP_OK)
  * @param response response to transmit, the NULL is tolerated
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 277510d8..2cfe6455 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -327,8 +327,9 @@ enum MHD_ResponseAutoFlags
   MHD_RAF_NO_FLAGS = 0,                   /**< No auto flags */
   MHD_RAF_HAS_CONNECTION_HDR = 1 << 0,    /**< Has "Connection" header */
   MHD_RAF_HAS_CONNECTION_CLOSE = 1 << 1,  /**< Has "Connection: close" */
-  MHD_RAF_HAS_TRANS_ENC_CHUNKED = 1 << 2, /**< Has "Transfer-Encoding: chunked 
*/
-  MHD_RAF_HAS_DATE_HDR = 1 << 3           /**< Has "Date" header */
+  MHD_RAF_HAS_TRANS_ENC_CHUNKED = 1 << 2, /**< Has "Transfer-Encoding: 
chunked" */
+  MHD_RAF_HAS_CONTENT_LENGTH = 1 << 3,    /**< Has "Content-Length" header */
+  MHD_RAF_HAS_DATE_HDR = 1 << 4           /**< Has "Date" header */
 } _MHD_FIXED_FLAGS_ENUM;
 
 
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 49ed9524..4408378c 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -272,7 +272,7 @@ MHD_pool_destroy (struct MemoryPool *pool)
 
   mhd_assert (pool->end >= pool->pos);
   mhd_assert (pool->size >= pool->end - pool->pos);
-  _MHD_POISON_MEMORY (pool->memory, pool->size);
+  _MHD_UNPOISON_MEMORY (pool->memory, pool->size);
   if (! pool->is_mmap)
     free (pool->memory);
   else
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index ca3639f4..3fd98088 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -541,13 +541,24 @@ MHD_add_response_header (struct MHD_Response *response,
     }
     return MHD_NO;
   }
-  if ( (0 == (MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
-              & response->flags)) &&
-       (MHD_str_equal_caseless_ (header,
-                                 MHD_HTTP_HEADER_CONTENT_LENGTH)) )
+
+  if (MHD_str_equal_caseless_ (header,
+                               MHD_HTTP_HEADER_CONTENT_LENGTH))
   {
-    /* MHD will set Content-length if allowed and possible,
-       reject attempt by application */
+    if (0 == (MHD_RF_INSANITY_HEADER_CONTENT_LENGTH & response->flags))
+    {
+      /* MHD sets automatically correct Content-Length always when needed,
+         reject attempt to manually override it */
+      return MHD_NO;
+    }
+    if (MHD_NO != add_response_entry (response,
+                                      MHD_HEADER_KIND,
+                                      header,
+                                      content))
+    {
+      response->flags_auto |= MHD_RAF_HAS_CONTENT_LENGTH;
+      return MHD_YES;
+    }
     return MHD_NO;
   }
 
@@ -644,6 +655,19 @@ MHD_del_response_header (struct MHD_Response *response,
                                                header_len) )
         response->flags_auto &=
           ~((enum MHD_ResponseAutoFlags) MHD_RAF_HAS_DATE_HDR);
+      else if ( (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_LENGTH) ==
+                 header_len) &&
+                MHD_str_equal_caseless_bin_n_ (header,
+                                               MHD_HTTP_HEADER_CONTENT_LENGTH,
+                                               header_len) )
+      {
+        if (NULL == MHD_get_response_element_n_ (response,
+                                                 MHD_HEADER_KIND,
+                                                 
MHD_HTTP_HEADER_CONTENT_LENGTH,
+                                                 header_len))
+          response->flags_auto &=
+            ~((enum MHD_ResponseAutoFlags) MHD_RAF_HAS_CONTENT_LENGTH);
+      }
       return MHD_YES;
     }
     pos = pos->next;
@@ -966,7 +990,7 @@ file_reader (void *cls,
     pos_uli.QuadPart = (uint64_t) offset64;   /* Simple transformation 64bit 
-> 2x32bit. */
     f_ol.Offset = pos_uli.LowPart;
     f_ol.OffsetHigh = pos_uli.HighPart;
-    if (! ReadFile (fh, (void*) buf, toRead, &resRead, &f_ol))
+    if (! ReadFile (fh, (void *) buf, toRead, &resRead, &f_ol))
       return MHD_CONTENT_READER_END_WITH_ERROR;   /* Read error. */
     if (0 == resRead)
       return MHD_CONTENT_READER_END_OF_STREAM;

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