gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r5553 - in libmicrohttpd: . src/daemon src/include
Date: Sun, 26 Aug 2007 03:13:05 -0600 (MDT)

Author: grothoff
Date: 2007-08-26 03:13:05 -0600 (Sun, 26 Aug 2007)
New Revision: 5553

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/README
   libmicrohttpd/src/daemon/connection.c
   libmicrohttpd/src/include/microhttpd.h
Log:
fixing mantis 1264

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2007-08-26 08:25:30 UTC (rev 5552)
+++ libmicrohttpd/ChangeLog     2007-08-26 09:13:05 UTC (rev 5553)
@@ -1,3 +1,8 @@
+Sun Aug 26 03:11:46 MDT 2007
+        Added MHD_USE_PEDANTIC_CHECKS option which enforces
+        receiving a "Host:" header in HTTP 1.1 (and sends a
+        HTTP 400 status back if this is violated).
+
 Tue Aug 21 01:01:46 MDT 2007
         Fixing assertion failure that occured when a client
         closed the connection after sending some data but

Modified: libmicrohttpd/README
===================================================================
--- libmicrohttpd/README        2007-08-26 08:25:30 UTC (rev 5552)
+++ libmicrohttpd/README        2007-08-26 09:13:05 UTC (rev 5553)
@@ -15,7 +15,6 @@
 ========================
 connection.c:
 - support chunked requests from clients (#1260, ARCH, TEST)
-- send proper error code back if client forgot the "Host" header (#1264, TRIV)
 
 For POST:
 =========

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2007-08-26 08:25:30 UTC (rev 
5552)
+++ libmicrohttpd/src/daemon/connection.c       2007-08-26 09:13:05 UTC (rev 
5553)
@@ -37,12 +37,24 @@
 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n"
 
 /**
- * Response used when the request (http header) is too big to
+ * Response text used when the request (http header) is too big to
  * be processed.
+ *
+ * Intentionally empty here to keep our memory footprint 
+ * minimal.
  */
 #define REQUEST_TOO_BIG ""
 
 /**
+ * Response text used when the request (http header) does not
+ * contain a "Host:" header and still claims to be HTTP 1.1.
+ *
+ * Intentionally empty here to keep our memory footprint 
+ * minimal.
+ */
+#define REQUEST_LACKS_HOST ""
+
+/**
  * Add extra debug messages with reasons for closing connections
  * (non-error reasons).
  */ 
@@ -305,9 +317,7 @@
 {
   struct MHD_Response *response;
 
-  /* die, header far too long to be reasonable;
-     FIXME: send proper response to client
-     (stop reading, queue proper response) */
+  /* die, header far too long to be reasonable */
   connection->read_close = MHD_YES;
   connection->headersReceived = MHD_YES;
   connection->bodyReceived = MHD_YES;
@@ -589,6 +599,7 @@
   const char *clen;
   const char *end;
   unsigned long long cval;
+  struct MHD_Response * response;
 
   if (connection->bodyReceived == 1)
     abort ();
@@ -638,7 +649,7 @@
       if (strlen (line) == 0)
         {
           /* end of header */
-          connection->headersReceived = 1;
+          connection->headersReceived = MHD_YES;
           clen = MHD_lookup_connection_value (connection,
                                               MHD_HEADER_KIND,
                                               MHD_HTTP_HEADER_CONTENT_LENGTH);
@@ -680,6 +691,29 @@
                  this request */
               connection->read_close = MHD_YES;
             }
+         
+         if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) &&
+              (NULL != connection->version) &&
+              (0 == strcasecmp(MHD_HTTP_VERSION_1_1,
+                               connection->version)) &&
+              (NULL == MHD_lookup_connection_value(connection,
+                                                   MHD_HEADER_KIND,
+                                                   MHD_HTTP_HEADER_HOST)) ) {
+           /* die, http 1.1 request without host and we are pedantic */
+           connection->bodyReceived = MHD_YES;
+           connection->read_close = MHD_YES;
+           MHD_DLOG (connection->daemon,
+                     "Received `%s' request without `%s' header.\n",
+                     MHD_HTTP_VERSION_1_1,
+                     MHD_HTTP_HEADER_HOST);
+           response = MHD_create_response_from_data (strlen 
(REQUEST_LACKS_HOST),
+                                                     REQUEST_LACKS_HOST, 
MHD_NO, MHD_NO);
+           MHD_queue_response (connection,
+                               MHD_HTTP_BAD_REQUEST,
+                               response);
+           MHD_destroy_response (response);
+         }
+                             
           break;
         }
       /* line should be normal header line, find colon */

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2007-08-26 08:25:30 UTC (rev 
5552)
+++ libmicrohttpd/src/include/microhttpd.h      2007-08-26 09:13:05 UTC (rev 
5553)
@@ -274,6 +274,17 @@
    */
   MHD_USE_IPv6 = 16,
 
+  /**
+   * Be pedantic about the protocol (as opposed to as tolerant as
+   * possible).  Specifically, at the moment, this flag causes MHD to
+   * reject http 1.1 connections without a "Host" header.  This is
+   * required by the standard, but of course in violation of the "be
+   * as liberal as possible in what you accept" norm.  It is
+   * recommended to turn this ON if you are testing clients against
+   * MHD, and OFF in production.
+   */
+  MHD_USE_PEDANTIC_CHECKS = 32,
+
 };
 
 /**





reply via email to

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