gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r5451 - in libmicrohttpd: . src/daemon
Date: Fri, 10 Aug 2007 18:14:18 -0600 (MDT)

Author: grothoff
Date: 2007-08-10 18:14:18 -0600 (Fri, 10 Aug 2007)
New Revision: 5451

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/daemon/connection.c
   libmicrohttpd/src/daemon/daemontest_get.c
   libmicrohttpd/src/daemon/daemontest_post.c
   libmicrohttpd/src/daemon/daemontest_put.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/daemon/response.c
Log:
100 continue

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2007-08-10 23:32:57 UTC (rev 5450)
+++ libmicrohttpd/ChangeLog     2007-08-11 00:14:18 UTC (rev 5451)
@@ -1,7 +1,8 @@
 Fri Aug 10 17:31:23 MDT 2007
         Fixed problems with handling of responses created from
         callbacks.  Allowing accept policy callback to be NULL
-        (to accept from all).  Added minimal fileserver example. -CG
+        (to accept from all).  Added minimal fileserver example.
+        Only send 100 continue header when specifically requested. - CG
 
 Wed Aug  8 01:46:06 MDT 2007
         Added pool allocation and connection limitations (total

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2007-08-10 23:32:57 UTC (rev 
5450)
+++ libmicrohttpd/src/daemon/connection.c       2007-08-11 00:14:18 UTC (rev 
5451)
@@ -31,11 +31,6 @@
 #include "response.h"
 
 /**
- * Size by which MHD usually tries to increment read/write buffers.
- */
-#define MHD_BUF_INC_SIZE 2048
-
-/**
  * Message to transmit when http 1.1 request is received
  */
 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n"
@@ -141,7 +136,26 @@
   return MHD_YES;
 }
 
+/**
+ * Do we (still) need to send a 100 continue
+ * message for this connection?
+ */
+static int 
+MHD_need_100_continue(struct MHD_Connection * connection) {
+  const char * expect;
 
+  return ( (connection->version != NULL) &&
+          (0 == strcasecmp(connection->version,
+                           MHD_HTTP_VERSION_1_1)) &&
+          (connection->headersReceived == 1) &&
+          (NULL != (expect = MHD_lookup_connection_value(connection,
+                                                         MHD_HEADER_KIND,
+                                                         
MHD_HTTP_HEADER_EXPECT))) &&
+          (0 == strcasecmp(expect,
+                           "100-continue")) &&
+          (connection->continuePos < strlen(HTTP_100_CONTINUE)) );
+}
+
 /**
  * Obtain the select sets for this connection
  *
@@ -186,10 +200,7 @@
     }
   } 
   if ( (connection->response != NULL) ||
-       ( (connection->version != NULL) &&
-        (0 == strcasecmp(connection->version,
-                         MHD_HTTP_VERSION_1_1)) &&
-        (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) ) {
+       MHD_need_100_continue(connection) ) {
     FD_SET(fd, write_fd_set);
     if (fd > *max_fd) 
       *max_fd = fd;
@@ -998,10 +1009,7 @@
   struct MHD_Response * response;
   int ret;
 
-  if ( (connection->version != NULL) &&
-       (0 == strcasecmp(connection->version,
-                       MHD_HTTP_VERSION_1_1)) &&
-       (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) {
+  if (MHD_need_100_continue(connection)) {
     ret = SEND(connection->socket_fd,
               &HTTP_100_CONTINUE[connection->continuePos],
               strlen(HTTP_100_CONTINUE) - connection->continuePos,
@@ -1067,24 +1075,18 @@
   if (response->crc != NULL)
     pthread_mutex_lock(&response->mutex);
 
-  /* prepare send buffer */
-  if ( (response->data == NULL) ||
-       (response->data_start > connection->messagePos) ||
-       (response->data_start + response->data_size <= connection->messagePos) 
) {
-    if (response->data_size == 0) {
-      if (response->data != NULL)
-       free(response->data);
-      response->data = malloc(MHD_BUF_INC_SIZE);
-      response->data_size = MHD_BUF_INC_SIZE;
-    }
+  /* prepare send buffer */  
+  if ( (response->crc != NULL) &&
+       ( (response->data_start > connection->messagePos) ||
+        (response->data_start + response->data_size <= connection->messagePos) 
) ) {
     ret = response->crc(response->crc_cls,
                        connection->messagePos,
                        response->data,
-                       MIN(response->data_size,
+                       MIN(response->data_buffer_size,
                            response->total_size - connection->messagePos));
     if (ret == -1) {
       /* end of message, signal other side by closing! */
-      response->data_size = connection->messagePos;
+      response->total_size = connection->messagePos;
       CLOSE(connection->socket_fd);
       connection->socket_fd = -1;
       if (response->crc != NULL)

Modified: libmicrohttpd/src/daemon/daemontest_get.c
===================================================================
--- libmicrohttpd/src/daemon/daemontest_get.c   2007-08-10 23:32:57 UTC (rev 
5450)
+++ libmicrohttpd/src/daemon/daemontest_get.c   2007-08-11 00:14:18 UTC (rev 
5451)
@@ -165,8 +165,8 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
                       1081,
-                      &apc_all,
                       NULL,
+                      NULL,
                       &ahc_echo,
                       "GET",
                       MHD_OPTION_END);
@@ -248,8 +248,8 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_DEBUG,
                       1082,
-                      &apc_all,
                       NULL,
+                      NULL,
                       &ahc_echo,
                       "GET",
                       MHD_OPTION_END);

Modified: libmicrohttpd/src/daemon/daemontest_post.c
===================================================================
--- libmicrohttpd/src/daemon/daemontest_post.c  2007-08-10 23:32:57 UTC (rev 
5450)
+++ libmicrohttpd/src/daemon/daemontest_post.c  2007-08-11 00:14:18 UTC (rev 
5451)
@@ -197,8 +197,8 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION |MHD_USE_DEBUG,
                       1081,
-                      &apc_all,
                       NULL,
+                      NULL,
                       &ahc_echo,
                       NULL,
                       MHD_OPTION_END);
@@ -290,8 +290,8 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_DEBUG,
                       1082,
-                      &apc_all,
                       NULL,
+                      NULL,
                       &ahc_echo,
                       NULL,
                       MHD_OPTION_END);

Modified: libmicrohttpd/src/daemon/daemontest_put.c
===================================================================
--- libmicrohttpd/src/daemon/daemontest_put.c   2007-08-10 23:32:57 UTC (rev 
5450)
+++ libmicrohttpd/src/daemon/daemontest_put.c   2007-08-11 00:14:18 UTC (rev 
5451)
@@ -212,8 +212,7 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
                       1081,
-                      &apc_all,
-                      NULL,
+                      NULL,                   NULL,
                       &ahc_echo,
                       &done_flag,
                       MHD_OPTION_END);
@@ -310,8 +309,8 @@
   cbc.pos = 0;
   d = MHD_start_daemon(MHD_USE_DEBUG,
                       1082,
-                      &apc_all,
                       NULL,
+                      NULL,
                       &ahc_echo,
                       &done_flag,
                       MHD_OPTION_END);

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2007-08-10 23:32:57 UTC (rev 5450)
+++ libmicrohttpd/src/daemon/internal.h 2007-08-11 00:14:18 UTC (rev 5451)
@@ -53,6 +53,10 @@
 #define MAX(a,b) ((a)<(b)) ? (b) : (a)
 #define MIN(a,b) ((a)<(b)) ? (a) : (b)
 
+/**
+ * Size by which MHD usually tries to increment read/write buffers.
+ */
+#define MHD_BUF_INC_SIZE 2048
 
 /**
  * fprintf-like helper function for logging debug
@@ -147,6 +151,11 @@
   size_t data_size;
 
   /**
+   * Size of the data buffer.
+   */
+  size_t data_buffer_size;
+
+  /**
    * At what offset in the stream is the
    * beginning of data located?
    */

Modified: libmicrohttpd/src/daemon/response.c
===================================================================
--- libmicrohttpd/src/daemon/response.c 2007-08-10 23:32:57 UTC (rev 5450)
+++ libmicrohttpd/src/daemon/response.c 2007-08-11 00:14:18 UTC (rev 5451)
@@ -168,7 +168,14 @@
   memset(retVal,
         0,
         sizeof(struct MHD_Response));
+  retVal->data = malloc(MHD_BUF_INC_SIZE);
+  if (retVal->data == NULL) {
+    free(retVal);
+    return NULL;
+  }
+  retVal->data_buffer_size = MHD_BUF_INC_SIZE;
   if (pthread_mutex_init(&retVal->mutex, NULL) != 0) {
+    free(retVal->data);
     free(retVal);
     return NULL;
   }
@@ -258,6 +265,8 @@
     free(pos->value);
     free(pos);
   }
+  if (response->crc != NULL) 
+    free(response->data);
   free(response);
 }
 





reply via email to

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