gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r17892 - in libmicrohttpd: . src/daemon


From: gnunet
Subject: [GNUnet-SVN] r17892 - in libmicrohttpd: . src/daemon
Date: Tue, 1 Nov 2011 18:52:48 +0100

Author: grothoff
Date: 2011-11-01 18:52:48 +0100 (Tue, 01 Nov 2011)
New Revision: 17892

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/daemon/connection.c
Log:
send connection:close always if we shutdown socket for reading, see mantis #1760

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2011-11-01 11:04:43 UTC (rev 17891)
+++ libmicrohttpd/ChangeLog     2011-11-01 17:52:48 UTC (rev 17892)
@@ -1,3 +1,8 @@
+Tue Nov  1 18:51:50 CET 2011
+       Force adding of 'Connection: close' to the header if we (for whatever
+       reason) are shutting down the socket for reading (see also
+       #1760). -CG
+
 Thu Oct 27 14:16:34 CEST 2011
        Treat EAGAIN the same way as EINTR (helps on W32). -LRN
 

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2011-11-01 11:04:43 UTC (rev 
17891)
+++ libmicrohttpd/src/daemon/connection.c       2011-11-01 17:52:48 UTC (rev 
17892)
@@ -608,10 +608,10 @@
   return MHD_YES;
 }
 
+
 /**
- * Allocate the connection's write buffer and
- * fill it with all of the headers (or footers,
- * if we have already sent the body) from the
+ * Allocate the connection's write buffer and fill it with all of the
+ * headers (or footers, if we have already sent the body) from the
  * HTTPd's response.
  */
 static int
@@ -626,6 +626,7 @@
   enum MHD_ValueKind kind;
   const char *reason_phrase;
   uint32_t rc;
+  int must_add_close;
 
   EXTRA_CHECK (NULL != connection->version);
   if (0 == strlen(connection->version))
@@ -669,6 +670,13 @@
       kind = MHD_FOOTER_KIND;
       off = 0;
     }
+  must_add_close = ( (connection->read_closed == MHD_YES) &&
+                    (0 == strcasecmp (connection->version,
+                                      MHD_HTTP_VERSION_1_1)) &&
+                    (NULL == MHD_get_response_header (connection->response,
+                                                      
MHD_HTTP_HEADER_CONNECTION)) );
+  if (must_add_close)
+    size += strlen ("Connection: close\r\n");
   pos = connection->response->first_header;
   while (pos != NULL)
     {
@@ -689,6 +697,16 @@
     {
       memcpy (data, code, off);
     }
+  if (must_add_close)
+    {
+      /* we must add the 'close' header because circumstances forced us to
+        stop reading from the socket; however, we are not adding the header
+        to the response as the response may be used in a different context
+        as well */
+      memcpy (&data[off], "Connection: close\r\n",
+             strlen ("Connection: close\r\n"));
+      off += strlen ("Connection: close\r\n");
+    }
   pos = connection->response->first_header;
   while (pos != NULL)
     {
@@ -703,6 +721,7 @@
     }
   memcpy (&data[off], "\r\n", 2);
   off += 2;
+
   if (off != size)
     mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
   connection->write_buffer = data;
@@ -712,6 +731,7 @@
   return MHD_YES;
 }
 
+
 /**
  * We encountered an error processing the request.
  * Handle it properly by stopping to read data




reply via email to

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