gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 03/03: Fixed sending response body for the HEAD requests


From: gnunet
Subject: [libmicrohttpd] 03/03: Fixed sending response body for the HEAD requests
Date: Sat, 12 Dec 2020 16:45:49 +0100

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit e09b6df63edaa076388820d63a8cdccfd35e33cb
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sat Dec 12 18:44:15 2020 +0300

    Fixed sending response body for the HEAD requests
    
    Sometimes response body as available but MHD must not send it, like for
    HEAD requests. This commit fixed regression caused by usage of
    MHD_send_on_connection2_ ().
---
 src/microhttpd/connection.c | 39 ++++++++++++++++++++++++++++++---------
 src/microhttpd/mhd_send.c   |  1 +
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 74f07408..8a06f7e2 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2920,15 +2920,35 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       mhd_assert (NULL != connection->response);
       mhd_assert ( (0 == connection->response->data_size) || \
                    (0 == connection->response->data_start) );
+      mhd_assert ( (0 == connection->response_write_position) || \
+                   (response->total_size ==
+                    connection->response_write_position) || \
+                   (MHD_SIZE_UNKNOWN ==
+                    connection->response_write_position) );
 
-      /* Send response headers alongside the response body, if the body
-       * data is available. */
-      ret = MHD_send_on_connection2_ (connection,
-                                      &connection->write_buffer
-                                      [connection->write_buffer_send_offset],
-                                      wb_ready,
-                                      connection->response->data,
-                                      connection->response->data_size);
+      if (0 == connection->response_write_position)
+      {
+        /* Send response headers alongside the response body, if the body
+         * data is available. */
+        ret = MHD_send_on_connection2_ (connection,
+                                        &connection->write_buffer
+                                        [connection->write_buffer_send_offset],
+                                        wb_ready,
+                                        connection->response->data,
+                                        connection->response->data_size);
+      }
+      else
+      {
+        /* This is response for HEAD request or reply body is not allowed
+         * for any other reason. */
+        /* Do not send the body data even if it's available. */
+        ret = MHD_send_on_connection2_ (connection,
+                                        &connection->write_buffer
+                                        [connection->write_buffer_send_offset],
+                                        wb_ready,
+                                        NULL,
+                                        0);
+      }
 
       if (ret < 0)
       {
@@ -2944,9 +2964,10 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
       {
         /* The complete header and some response data have been sent,
          * update both offsets. */
+        mhd_assert (0 == connection->response_write_position);
         mhd_assert (! connection->have_chunked_upload);
         connection->write_buffer_send_offset += wb_ready;
-        connection->response_write_position += ret - wb_ready;
+        connection->response_write_position = ret - wb_ready;
       }
       else
         connection->write_buffer_send_offset += ret;
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index 2bf9a071..f0cdfb58 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -841,6 +841,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
   const bool no_vec = false;
 #endif /* ! HTTPS_SUPPORT */
 #endif /* HAVE_SENDMSG || HAVE_WRITEV */
+  mhd_assert ( (NULL != buffer) || (0 == buffer_size) );
 
   if (
 #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)

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