Procházet zdrojové kódy

MHD_create_response_empty(): added new function

Evgeny Grin (Karlson2k) před 3 roky
rodič
revize
b452fc4b19
2 změnil soubory, kde provedl 58 přidání a 1 odebrání
  1. 20 1
      src/include/microhttpd.h
  2. 38 0
      src/microhttpd/response.c

+ 20 - 1
src/include/microhttpd.h

@@ -96,7 +96,7 @@ extern "C"
  * they are parsed as decimal numbers.
  * Example: 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00097502
+#define MHD_VERSION 0x00097503
 
 /* If generic headers don't work on your platform, include headers
    which define 'va_list', 'size_t', 'ssize_t', 'intptr_t',
@@ -3759,6 +3759,25 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
                                 void *cls);
 
 
+/**
+ * Create a response object with empty (zero size) body.
+ *
+ * The response object can be extended with header information and then be used
+ * any number of times.
+ *
+ * This function is a faster equivalent of #MHD_create_response_from_buffer call
+ * with zero size combined with call of #MHD_set_response_options.
+ *
+ * @param flags the flags for the new response object
+ * @return NULL on error (i.e. invalid arguments, out of memory),
+ *         the pointer to the created response object otherwise
+ * @note Available since #MHD_VERSION 0x00097503
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_empty (enum MHD_ResponseFlags flags);
+
+
 /**
  * Enumeration for actions MHD should perform on the underlying socket
  * of the upgrade.  This API is not finalized, and in particular

+ 38 - 0
src/microhttpd/response.c

@@ -1592,6 +1592,44 @@ MHD_create_response_from_iovec (const struct MHD_IoVec *iov,
 }
 
 
+/**
+ * Create a response object with empty (zero size) body.
+ *
+ * The response object can be extended with header information and then be used
+ * any number of times.
+ *
+ * This function is a faster equivalent of #MHD_create_response_from_buffer call
+ * with zero size combined with call of #MHD_set_response_options.
+ *
+ * @param flags the flags for the new response object
+ * @return NULL on error (i.e. invalid arguments, out of memory),
+ *         the pointer to the created response object otherwise
+ * @note Available since #MHD_VERSION 0x00097503
+ * @ingroup response
+ */
+struct MHD_Response *
+MHD_create_response_empty (enum MHD_ResponseFlags flags)
+{
+  struct MHD_Response *r;
+  r = (struct MHD_Response *) MHD_calloc_ (1, sizeof (struct MHD_Response));
+  if (NULL != r)
+  {
+    if (! MHD_mutex_init_ (&r->mutex))
+    {
+      r->fd = -1;
+      r->reference_count = 1;
+      /* If any flags combination will be not allowed, replace the next
+       * assignment with MHD_set_response_options() call. */
+      r->flags = flags;
+
+      return r; /* Successful result */
+    }
+    free (r);
+  }
+  return NULL; /* Something failed */
+}
+
+
 #ifdef UPGRADE_SUPPORT
 /**
  * This connection-specific callback is provided by MHD to