aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-06-03 21:33:39 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2021-06-03 22:00:06 +0300
commitcdc1db3d2f1f9f68b2bc35b3903f49480a9181a7 (patch)
tree1399f17637cb1c60b93773a749042da940df21c4
parent533d5cecd4390cec9ea75e6d1baabaae1945f0aa (diff)
downloadlibmicrohttpd-cdc1db3d2f1f9f68b2bc35b3903f49480a9181a7.tar.gz
libmicrohttpd-cdc1db3d2f1f9f68b2bc35b3903f49480a9181a7.zip
test_get_chunked: implemented TODOs
Added check for presence of the footer, Added check for usage of chunked encoding (if 'chunked' header is present libcurl receives only in chunked mode)
-rw-r--r--src/testcurl/test_get_chunked.c108
1 files changed, 102 insertions, 6 deletions
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 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2007 Christian Grothoff 3 Copyright (C) 2007 Christian Grothoff
4 Copyright (C) 2015-2021 Karlson2k (Evgeny Grin)
4 5
5 libmicrohttpd is free software; you can redistribute it and/or modify 6 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 7 it under the terms of the GNU General Public License as published
@@ -21,11 +22,8 @@
21/** 22/**
22 * @file daemontest_get_chunked.c 23 * @file daemontest_get_chunked.c
23 * @brief Testcase for libmicrohttpd GET operations with chunked content encoding 24 * @brief Testcase for libmicrohttpd GET operations with chunked content encoding
24 * TODO:
25 * - how to test that chunking was actually used?
26 * - use CURLOPT_HEADERFUNCTION to validate
27 * footer was sent
28 * @author Christian Grothoff 25 * @author Christian Grothoff
26 * @author Karlson2k (Evgeny Grin)
29 */ 27 */
30 28
31#include "MHD_config.h" 29#include "MHD_config.h"
@@ -49,11 +47,41 @@
49#define MHD_CPU_COUNT 2 47#define MHD_CPU_COUNT 2
50#endif 48#endif
51 49
50#define HDR_CHUNKED_ENCODING MHD_HTTP_HEADER_TRANSFER_ENCODING ": chunked"
51#define RESP_FOOTER_NAME "Footer"
52#define RESP_FOOTER_VALUE "working"
53#define RESP_FOOTER RESP_FOOTER_NAME ": " RESP_FOOTER_VALUE
54
52/** 55/**
53 * Use "Connection: close" header? 56 * Use "Connection: close" header?
54 */ 57 */
55int conn_close; 58int conn_close;
56 59
60struct headers_check_result
61{
62 int found_chunked;
63 int found_footer;
64};
65
66size_t
67lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
68 void *userdata)
69{
70 const size_t data_size = size * nitems;
71 struct headers_check_result *check_res =
72 (struct headers_check_result *) userdata;
73
74 if ((data_size == strlen (HDR_CHUNKED_ENCODING) + 2) &&
75 (0 == memcmp (buffer, HDR_CHUNKED_ENCODING "\r\n", data_size)))
76 check_res->found_chunked = 1;
77 if ((data_size == strlen (RESP_FOOTER) + 2) &&
78 (0 == memcmp (buffer, RESP_FOOTER "\r\n", data_size)))
79 check_res->found_footer = 1;
80
81 return data_size;
82}
83
84
57struct CBC 85struct CBC
58{ 86{
59 char *buf; 87 char *buf;
@@ -92,8 +120,8 @@ crc (void *cls,
92 if (pos == 128 * 10) 120 if (pos == 128 * 10)
93 { 121 {
94 MHD_add_response_footer (*responseptr, 122 MHD_add_response_footer (*responseptr,
95 "Footer", 123 RESP_FOOTER_NAME,
96 "working"); 124 RESP_FOOTER_VALUE);
97 return MHD_CONTENT_READER_END_OF_STREAM; 125 return MHD_CONTENT_READER_END_OF_STREAM;
98 } 126 }
99 if (max < 128) 127 if (max < 128)
@@ -206,6 +234,7 @@ testInternalGet ()
206 CURLcode errornum; 234 CURLcode errornum;
207 int port; 235 int port;
208 struct curl_slist *h_list = NULL; 236 struct curl_slist *h_list = NULL;
237 struct headers_check_result hdr_check;
209 238
210 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 239 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
211 port = 0; 240 port = 0;
@@ -229,6 +258,8 @@ testInternalGet ()
229 } 258 }
230 port = (int) dinfo->port; 259 port = (int) dinfo->port;
231 } 260 }
261 hdr_check.found_chunked = 0;
262 hdr_check.found_footer = 0;
232 c = curl_easy_init (); 263 c = curl_easy_init ();
233 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); 264 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world");
234 curl_easy_setopt (c, CURLOPT_PORT, (long) port); 265 curl_easy_setopt (c, CURLOPT_PORT, (long) port);
@@ -238,6 +269,8 @@ testInternalGet ()
238 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 269 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
239 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 270 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
240 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 271 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
272 curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
273 curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
241 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 274 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
242 if (conn_close) 275 if (conn_close)
243 { 276 {
@@ -259,6 +292,18 @@ testInternalGet ()
259 curl_easy_cleanup (c); 292 curl_easy_cleanup (c);
260 curl_slist_free_all (h_list); 293 curl_slist_free_all (h_list);
261 MHD_stop_daemon (d); 294 MHD_stop_daemon (d);
295 if (1 != hdr_check.found_chunked)
296 {
297 fprintf (stderr,
298 "Chunked encoding header was not found in the response\n");
299 return 8;
300 }
301 if (1 != hdr_check.found_footer)
302 {
303 fprintf (stderr,
304 "The specified footer was not found in the response\n");
305 return 16;
306 }
262 return validate (cbc, 4); 307 return validate (cbc, 4);
263} 308}
264 309
@@ -273,6 +318,7 @@ testMultithreadedGet ()
273 CURLcode errornum; 318 CURLcode errornum;
274 int port; 319 int port;
275 struct curl_slist *h_list = NULL; 320 struct curl_slist *h_list = NULL;
321 struct headers_check_result hdr_check;
276 322
277 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 323 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
278 port = 0; 324 port = 0;
@@ -307,6 +353,10 @@ testMultithreadedGet ()
307 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 353 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
308 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 354 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
309 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 355 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
356 hdr_check.found_chunked = 0;
357 hdr_check.found_footer = 0;
358 curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
359 curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
310 if (conn_close) 360 if (conn_close)
311 { 361 {
312 h_list = curl_slist_append (h_list, "Connection: close"); 362 h_list = curl_slist_append (h_list, "Connection: close");
@@ -327,6 +377,18 @@ testMultithreadedGet ()
327 curl_easy_cleanup (c); 377 curl_easy_cleanup (c);
328 curl_slist_free_all (h_list); 378 curl_slist_free_all (h_list);
329 MHD_stop_daemon (d); 379 MHD_stop_daemon (d);
380 if (1 != hdr_check.found_chunked)
381 {
382 fprintf (stderr,
383 "Chunked encoding header was not found in the response\n");
384 return 8;
385 }
386 if (1 != hdr_check.found_footer)
387 {
388 fprintf (stderr,
389 "The specified footer was not found in the response\n");
390 return 16;
391 }
330 return validate (cbc, 64); 392 return validate (cbc, 64);
331} 393}
332 394
@@ -341,6 +403,7 @@ testMultithreadedPoolGet ()
341 CURLcode errornum; 403 CURLcode errornum;
342 int port; 404 int port;
343 struct curl_slist *h_list = NULL; 405 struct curl_slist *h_list = NULL;
406 struct headers_check_result hdr_check;
344 407
345 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 408 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
346 port = 0; 409 port = 0;
@@ -376,6 +439,10 @@ testMultithreadedPoolGet ()
376 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 439 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
377 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 440 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
378 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 441 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
442 hdr_check.found_chunked = 0;
443 hdr_check.found_footer = 0;
444 curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
445 curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
379 if (conn_close) 446 if (conn_close)
380 { 447 {
381 h_list = curl_slist_append (h_list, "Connection: close"); 448 h_list = curl_slist_append (h_list, "Connection: close");
@@ -396,6 +463,18 @@ testMultithreadedPoolGet ()
396 curl_easy_cleanup (c); 463 curl_easy_cleanup (c);
397 curl_slist_free_all (h_list); 464 curl_slist_free_all (h_list);
398 MHD_stop_daemon (d); 465 MHD_stop_daemon (d);
466 if (1 != hdr_check.found_chunked)
467 {
468 fprintf (stderr,
469 "Chunked encoding header was not found in the response\n");
470 return 8;
471 }
472 if (1 != hdr_check.found_footer)
473 {
474 fprintf (stderr,
475 "The specified footer was not found in the response\n");
476 return 16;
477 }
399 return validate (cbc, 64); 478 return validate (cbc, 64);
400} 479}
401 480
@@ -424,6 +503,7 @@ testExternalGet ()
424 struct timeval tv; 503 struct timeval tv;
425 int port; 504 int port;
426 struct curl_slist *h_list = NULL; 505 struct curl_slist *h_list = NULL;
506 struct headers_check_result hdr_check;
427 507
428 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 508 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
429 port = 0; 509 port = 0;
@@ -458,6 +538,10 @@ testExternalGet ()
458 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 538 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
459 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); 539 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
460 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 540 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
541 hdr_check.found_chunked = 0;
542 hdr_check.found_footer = 0;
543 curl_easy_setopt (c, CURLOPT_HEADERFUNCTION, lcurl_hdr_callback);
544 curl_easy_setopt (c, CURLOPT_HEADERDATA, &hdr_check);
461 if (conn_close) 545 if (conn_close)
462 { 546 {
463 h_list = curl_slist_append (h_list, "Connection: close"); 547 h_list = curl_slist_append (h_list, "Connection: close");
@@ -557,6 +641,18 @@ testExternalGet ()
557 curl_slist_free_all (h_list); 641 curl_slist_free_all (h_list);
558 } 642 }
559 MHD_stop_daemon (d); 643 MHD_stop_daemon (d);
644 if (1 != hdr_check.found_chunked)
645 {
646 fprintf (stderr,
647 "Chunked encoding header was not found in the response\n");
648 return 8;
649 }
650 if (1 != hdr_check.found_footer)
651 {
652 fprintf (stderr,
653 "The specified footer was not found in the response\n");
654 return 16;
655 }
560 return validate (cbc, 8192); 656 return validate (cbc, 8192);
561} 657}
562 658