gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (f33328ef -> cdc1db3d)


From: gnunet
Subject: [libmicrohttpd] branch master updated (f33328ef -> cdc1db3d)
Date: Thu, 03 Jun 2021 21:23:08 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from f33328ef Code and comments minor fixes
     new 533d5cec chunked_example: fixed resource leak
     new cdc1db3d test_get_chunked: implemented TODOs

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/examples/chunked_example.c  |   1 +
 src/testcurl/test_get_chunked.c | 108 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index ed20d472..68b7ea1e 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -143,6 +143,7 @@ ahc_echo (void *cls,
                                          "chunked"))
   {
     free (callback_param);
+    MHD_destroy_response (response);
     return MHD_NO;
   }
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index 2b18c50a..b2939c8e 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -1,6 +1,7 @@
 /*
      This file is part of libmicrohttpd
      Copyright (C) 2007 Christian Grothoff
+     Copyright (C) 2015-2021 Karlson2k (Evgeny Grin)
 
      libmicrohttpd is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,11 +22,8 @@
 /**
  * @file daemontest_get_chunked.c
  * @brief  Testcase for libmicrohttpd GET operations with chunked content 
encoding
- *         TODO:
- *         - how to test that chunking was actually used?
- *         - use CURLOPT_HEADERFUNCTION to validate
- *           footer was sent
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "MHD_config.h"
@@ -49,11 +47,41 @@
 #define MHD_CPU_COUNT 2
 #endif
 
+#define HDR_CHUNKED_ENCODING MHD_HTTP_HEADER_TRANSFER_ENCODING ": chunked"
+#define RESP_FOOTER_NAME "Footer"
+#define RESP_FOOTER_VALUE "working"
+#define RESP_FOOTER RESP_FOOTER_NAME ": " RESP_FOOTER_VALUE
+
 /**
  * Use "Connection: close" header?
  */
 int conn_close;
 
+struct headers_check_result
+{
+  int found_chunked;
+  int found_footer;
+};
+
+size_t
+lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
+                    void *userdata)
+{
+  const size_t data_size = size * nitems;
+  struct headers_check_result *check_res =
+    (struct headers_check_result *) userdata;
+
+  if ((data_size == strlen (HDR_CHUNKED_ENCODING) + 2) &&
+      (0 == memcmp (buffer, HDR_CHUNKED_ENCODING "\r\n", data_size)))
+    check_res->found_chunked = 1;
+  if ((data_size == strlen (RESP_FOOTER) + 2) &&
+      (0 == memcmp (buffer, RESP_FOOTER "\r\n", data_size)))
+    check_res->found_footer = 1;
+
+  return data_size;
+}
+
+
 struct CBC
 {
   char *buf;
@@ -92,8 +120,8 @@ crc (void *cls,
   if (pos == 128 * 10)
   {
     MHD_add_response_footer (*responseptr,
-                             "Footer",
-                             "working");
+                             RESP_FOOTER_NAME,
+                             RESP_FOOTER_VALUE);
     return MHD_CONTENT_READER_END_OF_STREAM;
   }
   if (max < 128)
@@ -206,6 +234,7 @@ testInternalGet ()
   CURLcode errornum;
   int port;
   struct curl_slist *h_list = NULL;
+  struct headers_check_result hdr_check;
 
   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
     port = 0;
@@ -229,6 +258,8 @@ testInternalGet ()
     }
     port = (int) dinfo->port;
   }
+  hdr_check.found_chunked = 0;
+  hdr_check.found_footer = 0;
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
   curl_easy_setopt (c, CURLOPT_PORT, (long) port);
@@ -238,6 +269,8 @@ testInternalGet ()
   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
   curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+  curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
+  curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
   if (conn_close)
   {
@@ -259,6 +292,18 @@ testInternalGet ()
   curl_easy_cleanup (c);
   curl_slist_free_all (h_list);
   MHD_stop_daemon (d);
+  if (1 != hdr_check.found_chunked)
+  {
+    fprintf (stderr,
+             "Chunked encoding header was not found in the response\n");
+    return 8;
+  }
+  if (1 != hdr_check.found_footer)
+  {
+    fprintf (stderr,
+             "The specified footer was not found in the response\n");
+    return 16;
+  }
   return validate (cbc, 4);
 }
 
@@ -273,6 +318,7 @@ testMultithreadedGet ()
   CURLcode errornum;
   int port;
   struct curl_slist *h_list = NULL;
+  struct headers_check_result hdr_check;
 
   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
     port = 0;
@@ -307,6 +353,10 @@ testMultithreadedGet ()
   curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+  hdr_check.found_chunked = 0;
+  hdr_check.found_footer = 0;
+  curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
+  curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
   if (conn_close)
   {
     h_list = curl_slist_append (h_list, "Connection: close");
@@ -327,6 +377,18 @@ testMultithreadedGet ()
   curl_easy_cleanup (c);
   curl_slist_free_all (h_list);
   MHD_stop_daemon (d);
+  if (1 != hdr_check.found_chunked)
+  {
+    fprintf (stderr,
+             "Chunked encoding header was not found in the response\n");
+    return 8;
+  }
+  if (1 != hdr_check.found_footer)
+  {
+    fprintf (stderr,
+             "The specified footer was not found in the response\n");
+    return 16;
+  }
   return validate (cbc, 64);
 }
 
@@ -341,6 +403,7 @@ testMultithreadedPoolGet ()
   CURLcode errornum;
   int port;
   struct curl_slist *h_list = NULL;
+  struct headers_check_result hdr_check;
 
   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
     port = 0;
@@ -376,6 +439,10 @@ testMultithreadedPoolGet ()
   curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+  hdr_check.found_chunked = 0;
+  hdr_check.found_footer = 0;
+  curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
+  curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
   if (conn_close)
   {
     h_list = curl_slist_append (h_list, "Connection: close");
@@ -396,6 +463,18 @@ testMultithreadedPoolGet ()
   curl_easy_cleanup (c);
   curl_slist_free_all (h_list);
   MHD_stop_daemon (d);
+  if (1 != hdr_check.found_chunked)
+  {
+    fprintf (stderr,
+             "Chunked encoding header was not found in the response\n");
+    return 8;
+  }
+  if (1 != hdr_check.found_footer)
+  {
+    fprintf (stderr,
+             "The specified footer was not found in the response\n");
+    return 16;
+  }
   return validate (cbc, 64);
 }
 
@@ -424,6 +503,7 @@ testExternalGet ()
   struct timeval tv;
   int port;
   struct curl_slist *h_list = NULL;
+  struct headers_check_result hdr_check;
 
   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
     port = 0;
@@ -458,6 +538,10 @@ testExternalGet ()
   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+  hdr_check.found_chunked = 0;
+  hdr_check.found_footer = 0;
+  curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
+  curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
   if (conn_close)
   {
     h_list = curl_slist_append (h_list, "Connection: close");
@@ -557,6 +641,18 @@ testExternalGet ()
     curl_slist_free_all (h_list);
   }
   MHD_stop_daemon (d);
+  if (1 != hdr_check.found_chunked)
+  {
+    fprintf (stderr,
+             "Chunked encoding header was not found in the response\n");
+    return 8;
+  }
+  if (1 != hdr_check.found_footer)
+  {
+    fprintf (stderr,
+             "The specified footer was not found in the response\n");
+    return 16;
+  }
   return validate (cbc, 8192);
 }
 

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