gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (025d2ab1 -> 1b435684)


From: gnunet
Subject: [libmicrohttpd] branch master updated (025d2ab1 -> 1b435684)
Date: Sun, 21 Nov 2021 20:14:35 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 025d2ab1 test_client_put_*: new tests
     new a761eb67 Reworking early close flags
     new 1b435684 Clarified termination reasons description

The 2 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    | 18 +++++-----
 src/microhttpd/connection.c | 82 ++++++++++++++++++++++++++++++---------------
 src/microhttpd/internal.h   |  2 +-
 3 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 483f2fb1..6d9fa67d 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -2004,8 +2004,9 @@ enum MHD_RequestTerminationCode
 
   /**
    * Error handling the connection (resources
-   * exhausted, other side closed connection,
-   * application error accepting request, etc.)
+   * exhausted, application error accepting request,
+   * decrypt error (for HTTPS), connection died when
+   * sending the response etc.)
    * @ingroup request
    */
   MHD_REQUEST_TERMINATED_WITH_ERROR = 1,
@@ -2026,19 +2027,18 @@ enum MHD_RequestTerminationCode
   MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN = 3,
 
   /**
-   * We tried to read additional data, but the other side closed the
-   * connection.  This error is similar to
-   * #MHD_REQUEST_TERMINATED_WITH_ERROR, but specific to the case where
-   * the connection died because the other side did not send expected
-   * data.
+   * We tried to read additional data, but the connection became broken or
+   * the other side hard closed the connection.
+   * This error is similar to #MHD_REQUEST_TERMINATED_WITH_ERROR, but
+   * specific to the case where the connection died before request completely
+   * received.
    * @ingroup request
    */
   MHD_REQUEST_TERMINATED_READ_ERROR = 4,
 
   /**
    * The client terminated the connection by closing the socket
-   * for writing (TCP half-closed); MHD aborted sending the
-   * response according to RFC 2616, section 8.1.4.
+   * for writing (TCP half-closed) while still sending request.
    * @ingroup request
    */
   MHD_REQUEST_TERMINATED_CLIENT_ABORT = 5
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index a068bfe4..442189a4 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -924,7 +924,7 @@ connection_close_error (struct MHD_Connection *connection,
                         const char *emsg)
 {
   connection->stop_with_error = true;
-  connection->early_response = true;
+  connection->discard_request = true;
 #ifdef HAVE_MESSAGES
   if (NULL != emsg)
     MHD_DLOG (connection->daemon,
@@ -1300,8 +1300,8 @@ keepalive_possible (struct MHD_Connection *connection)
   }
 #endif /* UPGRADE_SUPPORT */
 
-  mhd_assert ( (! c->stop_with_error) || (c->early_response));
-  if ((c->read_closed) || (c->early_response))
+  mhd_assert ( (! c->stop_with_error) || (c->discard_request));
+  if ((c->read_closed) || (c->discard_request))
     return MHD_CONN_MUST_CLOSE;
 
   if (0 != (r->flags & MHD_RF_HTTP_1_0_COMPATIBLE_STRICT))
@@ -2265,7 +2265,7 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
     return;
   }
   connection->stop_with_error = true;
-  connection->early_response = true;
+  connection->discard_request = true;
 #ifdef HAVE_MESSAGES
   MHD_DLOG (connection->daemon,
             _ ("Error processing request (HTTP response code is %u ('%s')). " \
@@ -2436,7 +2436,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
                                           REQUEST_TOO_BIG);
         continue;
       }
-      if (! connection->early_response)
+      if (! connection->discard_request)
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
       else
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
@@ -2476,7 +2476,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
         }
       }
       if ( (connection->read_buffer_offset < connection->read_buffer_size) &&
-           (! connection->early_response) )
+           (! connection->discard_request) )
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_READ;
       else
         connection->event_loop_info = MHD_EVENT_LOOP_INFO_BLOCK;
@@ -2485,7 +2485,7 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
     case MHD_CONNECTION_FOOTER_PART_RECEIVED:
       /* while reading footers, we always grow the
          read buffer if needed, no size-check required */
-      if (connection->stop_with_error)
+      if (connection->read_closed)
       {
         CONNECTION_CLOSE_ERROR (connection,
                                 NULL);
@@ -3646,11 +3646,17 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
       return;     /* No new data to process. */
     if (MHD_ERR_CONNRESET_ == bytes_read)
     {
-      CONNECTION_CLOSE_ERROR (connection,
-                              (MHD_CONNECTION_INIT == connection->state) ?
-                              NULL :
-                              _ (
-                                "Socket disconnected while reading request."));
+      if ( (MHD_CONNECTION_INIT < connection->state) &&
+           (MHD_CONNECTION_FULL_REQ_RECEIVED > connection->state) )
+      {
+#ifdef HAVE_MESSAGES
+        MHD_DLOG (connection->daemon,
+                  _ ("Socket has been disconnected when reading request.\n"));
+#endif
+        connection->discard_request = true;
+      }
+      MHD_connection_close_ (connection,
+                             MHD_REQUEST_TERMINATED_READ_ERROR);
       return;
     }
 
@@ -3669,8 +3675,26 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
   if (0 == bytes_read)
   {   /* Remote side closed connection. */
     connection->read_closed = true;
-    MHD_connection_close_ (connection,
-                           MHD_REQUEST_TERMINATED_CLIENT_ABORT);
+    if ( (MHD_CONNECTION_INIT < connection->state) &&
+         (MHD_CONNECTION_FULL_REQ_RECEIVED > connection->state) )
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (connection->daemon,
+                _ ("Connection was closed by remote side with incomplete "
+                   "request.\n"));
+#endif
+      connection->discard_request = true;
+      MHD_connection_close_ (connection,
+                             MHD_REQUEST_TERMINATED_CLIENT_ABORT);
+    }
+    else if (MHD_CONNECTION_INIT == connection->state)
+      /* This termination code cannot be reported to the application
+       * because application has not been informed yet about this request */
+      MHD_connection_close_ (connection,
+                             MHD_REQUEST_TERMINATED_COMPLETED_OK);
+    else
+      MHD_connection_close_ (connection,
+                             MHD_REQUEST_TERMINATED_WITH_ERROR);
     return;
   }
   connection->read_buffer_offset += bytes_read;
@@ -3694,8 +3718,9 @@ MHD_connection_handle_read (struct MHD_Connection 
*connection)
   case MHD_CONNECTION_BODY_RECEIVED:
   case MHD_CONNECTION_FOOTER_PART_RECEIVED:
     /* nothing to do but default action */
-    if ((connection->read_closed) || (connection->stop_with_error))
+    if (connection->read_closed)
     {
+      /* TODO: check whether this really needed */
       MHD_connection_close_ (connection,
                              MHD_REQUEST_TERMINATED_READ_ERROR);
     }
@@ -4176,7 +4201,7 @@ connection_reset (struct MHD_Connection *connection,
     /* Reset connection to process the next request */
     size_t new_read_buf_size;
     mhd_assert (! c->stop_with_error);
-    mhd_assert (! c->early_response);
+    mhd_assert (! c->discard_request);
 
     if ( (NULL != d->notify_completed) &&
          (c->client_aware) )
@@ -4299,7 +4324,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         continue;
       }
       /* NULL means we didn't get a full line yet */
-      if (connection->stop_with_error)
+      if (connection->discard_request)
       {
         mhd_assert (MHD_CONNECTION_INIT != connection->state);
         continue;
@@ -4314,7 +4339,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (MHD_CONNECTION_URL_RECEIVED != connection->state)
           continue;
-        if (connection->stop_with_error)
+        if (connection->read_closed)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4346,7 +4371,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED)
           continue;
-        if (connection->stop_with_error)
+        if (connection->read_closed)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4393,7 +4418,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
         /* we refused (no upload allowed!) */
         connection->remaining_upload_size = 0;
         /* force close, in case client still tries to upload... */
-        connection->early_response = true;
+        connection->discard_request = true;
       }
       connection->state = (0 == connection->remaining_upload_size)
                           ? MHD_CONNECTION_FULL_REQ_RECEIVED
@@ -4413,16 +4438,19 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       if (0 != connection->read_buffer_offset)
       {
         process_request_body (connection);           /* loop call */
-        if (connection->stop_with_error)
+        if (connection->discard_request)
+        {
+          mhd_assert (MHD_CONNECTION_CONTINUE_SENT != connection->state);
           continue;
+        }
       }
       if ( (0 == connection->remaining_upload_size) ||
            ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) &&
              (0 == connection->read_buffer_offset) &&
-             (connection->early_response) ) )
+             (connection->discard_request) ) )
       {
         if ( (connection->have_chunked_upload) &&
-             (! connection->early_response) )
+             (! connection->discard_request) )
           connection->state = MHD_CONNECTION_BODY_RECEIVED;
         else
           connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED;
@@ -4438,7 +4466,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_BODY_RECEIVED)
           continue;
-        if (connection->stop_with_error)
+        if (connection->read_closed)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4472,7 +4500,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       {
         if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED)
           continue;
-        if (connection->stop_with_error)
+        if (connection->read_closed)
         {
           CONNECTION_CLOSE_ERROR (connection,
                                   NULL);
@@ -4661,7 +4689,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
       connection_reset (connection,
                         MHD_CONN_USE_KEEPALIVE == connection->keepalive &&
                         ! connection->read_closed &&
-                        ! connection->early_response);
+                        ! connection->discard_request);
       continue;
     case MHD_CONNECTION_CLOSED:
       cleanup_connection (connection);
@@ -5096,7 +5124,7 @@ MHD_queue_response (struct MHD_Connection *connection,
   {
     /* response was queued "early", refuse to read body / footers or
        further requests! */
-    connection->early_response = true;
+    connection->discard_request = true;
     connection->state = MHD_CONNECTION_START_REPLY;
     connection->remaining_upload_size = 0;
   }
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index b2bd0f6c..da981c80 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1230,7 +1230,7 @@ struct MHD_Connection
    * request is incompletely read and it is unclear where is the initial
    * byte of the next request.
    */
-  bool early_response;
+  bool discard_request;
 
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   /**

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