aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_get_chunked.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_get_chunked.c')
-rw-r--r--src/testcurl/test_get_chunked.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index aa753314..2b18c50a 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -40,6 +40,8 @@
40#include <unistd.h> 40#include <unistd.h>
41#endif 41#endif
42 42
43#include "mhd_has_in_name.h"
44
43#if defined(MHD_CPU_COUNT) && (MHD_CPU_COUNT + 0) < 2 45#if defined(MHD_CPU_COUNT) && (MHD_CPU_COUNT + 0) < 2
44#undef MHD_CPU_COUNT 46#undef MHD_CPU_COUNT
45#endif 47#endif
@@ -47,6 +49,11 @@
47#define MHD_CPU_COUNT 2 49#define MHD_CPU_COUNT 2
48#endif 50#endif
49 51
52/**
53 * Use "Connection: close" header?
54 */
55int conn_close;
56
50struct CBC 57struct CBC
51{ 58{
52 char *buf; 59 char *buf;
@@ -135,17 +142,22 @@ ahc_echo (void *cls,
135 } 142 }
136 responseptr = malloc (sizeof (struct MHD_Response *)); 143 responseptr = malloc (sizeof (struct MHD_Response *));
137 if (NULL == responseptr) 144 if (NULL == responseptr)
138 return MHD_NO; 145 _exit (99);
139 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 146 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
140 1024, 147 1024,
141 &crc, 148 &crc,
142 responseptr, 149 responseptr,
143 &crcf); 150 &crcf);
144 if (NULL == response) 151 if (NULL == response)
145 { 152 abort ();
146 free (responseptr); 153 if (conn_close)
147 return MHD_NO; 154 { /* Enforce chunked response even for non-Keep-Alive */
155 if (MHD_NO == MHD_add_response_header (response,
156 MHD_HTTP_HEADER_TRANSFER_ENCODING,
157 "chunked"))
158 abort ();
148 } 159 }
160
149 *responseptr = response; 161 *responseptr = response;
150 ret = MHD_queue_response (connection, 162 ret = MHD_queue_response (connection,
151 MHD_HTTP_OK, 163 MHD_HTTP_OK,
@@ -193,6 +205,7 @@ testInternalGet ()
193 struct CBC cbc; 205 struct CBC cbc;
194 CURLcode errornum; 206 CURLcode errornum;
195 int port; 207 int port;
208 struct curl_slist *h_list = NULL;
196 209
197 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 210 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
198 port = 0; 211 port = 0;
@@ -225,20 +238,26 @@ testInternalGet ()
225 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 238 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
226 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 239 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
227 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 240 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
228 /* NOTE: use of CONNECTTIMEOUT without also
229 * setting NOSIGNAL results in really weird
230 * crashes on my system! */
231 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 241 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
242 if (conn_close)
243 {
244 h_list = curl_slist_append (h_list, "Connection: close");
245 if (NULL == h_list)
246 abort ();
247 curl_easy_setopt (c, CURLOPT_HTTPHEADER, h_list);
248 }
232 if (CURLE_OK != (errornum = curl_easy_perform (c))) 249 if (CURLE_OK != (errornum = curl_easy_perform (c)))
233 { 250 {
234 fprintf (stderr, 251 fprintf (stderr,
235 "curl_easy_perform failed: `%s'\n", 252 "curl_easy_perform failed: `%s'\n",
236 curl_easy_strerror (errornum)); 253 curl_easy_strerror (errornum));
237 curl_easy_cleanup (c); 254 curl_easy_cleanup (c);
255 curl_slist_free_all (h_list);
238 MHD_stop_daemon (d); 256 MHD_stop_daemon (d);
239 return 2; 257 return 2;
240 } 258 }
241 curl_easy_cleanup (c); 259 curl_easy_cleanup (c);
260 curl_slist_free_all (h_list);
242 MHD_stop_daemon (d); 261 MHD_stop_daemon (d);
243 return validate (cbc, 4); 262 return validate (cbc, 4);
244} 263}
@@ -253,6 +272,7 @@ testMultithreadedGet ()
253 struct CBC cbc; 272 struct CBC cbc;
254 CURLcode errornum; 273 CURLcode errornum;
255 int port; 274 int port;
275 struct curl_slist *h_list = NULL;
256 276
257 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 277 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
258 port = 0; 278 port = 0;
@@ -286,20 +306,26 @@ testMultithreadedGet ()
286 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 306 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
287 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 307 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
288 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 308 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
289 /* NOTE: use of CONNECTTIMEOUT without also
290 * setting NOSIGNAL results in really weird
291 * crashes on my system! */
292 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 309 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
310 if (conn_close)
311 {
312 h_list = curl_slist_append (h_list, "Connection: close");
313 if (NULL == h_list)
314 abort ();
315 curl_easy_setopt (c, CURLOPT_HTTPHEADER, h_list);
316 }
293 if (CURLE_OK != (errornum = curl_easy_perform (c))) 317 if (CURLE_OK != (errornum = curl_easy_perform (c)))
294 { 318 {
295 fprintf (stderr, 319 fprintf (stderr,
296 "curl_easy_perform failed: `%s'\n", 320 "curl_easy_perform failed: `%s'\n",
297 curl_easy_strerror (errornum)); 321 curl_easy_strerror (errornum));
298 curl_easy_cleanup (c); 322 curl_easy_cleanup (c);
323 curl_slist_free_all (h_list);
299 MHD_stop_daemon (d); 324 MHD_stop_daemon (d);
300 return 32; 325 return 32;
301 } 326 }
302 curl_easy_cleanup (c); 327 curl_easy_cleanup (c);
328 curl_slist_free_all (h_list);
303 MHD_stop_daemon (d); 329 MHD_stop_daemon (d);
304 return validate (cbc, 64); 330 return validate (cbc, 64);
305} 331}
@@ -314,6 +340,7 @@ testMultithreadedPoolGet ()
314 struct CBC cbc; 340 struct CBC cbc;
315 CURLcode errornum; 341 CURLcode errornum;
316 int port; 342 int port;
343 struct curl_slist *h_list = NULL;
317 344
318 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 345 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
319 port = 0; 346 port = 0;
@@ -348,20 +375,26 @@ testMultithreadedPoolGet ()
348 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 375 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
349 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 376 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
350 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); 377 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
351 /* NOTE: use of CONNECTTIMEOUT without also
352 * setting NOSIGNAL results in really weird
353 * crashes on my system! */
354 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 378 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
379 if (conn_close)
380 {
381 h_list = curl_slist_append (h_list, "Connection: close");
382 if (NULL == h_list)
383 abort ();
384 curl_easy_setopt (c, CURLOPT_HTTPHEADER, h_list);
385 }
355 if (CURLE_OK != (errornum = curl_easy_perform (c))) 386 if (CURLE_OK != (errornum = curl_easy_perform (c)))
356 { 387 {
357 fprintf (stderr, 388 fprintf (stderr,
358 "curl_easy_perform failed: `%s'\n", 389 "curl_easy_perform failed: `%s'\n",
359 curl_easy_strerror (errornum)); 390 curl_easy_strerror (errornum));
360 curl_easy_cleanup (c); 391 curl_easy_cleanup (c);
392 curl_slist_free_all (h_list);
361 MHD_stop_daemon (d); 393 MHD_stop_daemon (d);
362 return 32; 394 return 32;
363 } 395 }
364 curl_easy_cleanup (c); 396 curl_easy_cleanup (c);
397 curl_slist_free_all (h_list);
365 MHD_stop_daemon (d); 398 MHD_stop_daemon (d);
366 return validate (cbc, 64); 399 return validate (cbc, 64);
367} 400}
@@ -390,6 +423,7 @@ testExternalGet ()
390 time_t start; 423 time_t start;
391 struct timeval tv; 424 struct timeval tv;
392 int port; 425 int port;
426 struct curl_slist *h_list = NULL;
393 427
394 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 428 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
395 port = 0; 429 port = 0;
@@ -423,16 +457,20 @@ testExternalGet ()
423 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 457 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
424 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); 458 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
425 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); 459 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
426 /* NOTE: use of CONNECTTIMEOUT without also
427 * setting NOSIGNAL results in really weird
428 * crashes on my system! */
429 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); 460 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
430 461 if (conn_close)
462 {
463 h_list = curl_slist_append (h_list, "Connection: close");
464 if (NULL == h_list)
465 abort ();
466 curl_easy_setopt (c, CURLOPT_HTTPHEADER, h_list);
467 }
431 468
432 multi = curl_multi_init (); 469 multi = curl_multi_init ();
433 if (multi == NULL) 470 if (multi == NULL)
434 { 471 {
435 curl_easy_cleanup (c); 472 curl_easy_cleanup (c);
473 curl_slist_free_all (h_list);
436 MHD_stop_daemon (d); 474 MHD_stop_daemon (d);
437 return 512; 475 return 512;
438 } 476 }
@@ -441,6 +479,7 @@ testExternalGet ()
441 { 479 {
442 curl_multi_cleanup (multi); 480 curl_multi_cleanup (multi);
443 curl_easy_cleanup (c); 481 curl_easy_cleanup (c);
482 curl_slist_free_all (h_list);
444 MHD_stop_daemon (d); 483 MHD_stop_daemon (d);
445 return 1024; 484 return 1024;
446 } 485 }
@@ -459,6 +498,7 @@ testExternalGet ()
459 curl_multi_remove_handle (multi, c); 498 curl_multi_remove_handle (multi, c);
460 curl_multi_cleanup (multi); 499 curl_multi_cleanup (multi);
461 curl_easy_cleanup (c); 500 curl_easy_cleanup (c);
501 curl_slist_free_all (h_list);
462 MHD_stop_daemon (d); 502 MHD_stop_daemon (d);
463 return 2048; 503 return 2048;
464 } 504 }
@@ -467,6 +507,7 @@ testExternalGet ()
467 curl_multi_remove_handle (multi, c); 507 curl_multi_remove_handle (multi, c);
468 curl_multi_cleanup (multi); 508 curl_multi_cleanup (multi);
469 curl_easy_cleanup (c); 509 curl_easy_cleanup (c);
510 curl_slist_free_all (h_list);
470 MHD_stop_daemon (d); 511 MHD_stop_daemon (d);
471 return 4096; 512 return 4096;
472 } 513 }
@@ -513,6 +554,7 @@ testExternalGet ()
513 curl_multi_remove_handle (multi, c); 554 curl_multi_remove_handle (multi, c);
514 curl_easy_cleanup (c); 555 curl_easy_cleanup (c);
515 curl_multi_cleanup (multi); 556 curl_multi_cleanup (multi);
557 curl_slist_free_all (h_list);
516 } 558 }
517 MHD_stop_daemon (d); 559 MHD_stop_daemon (d);
518 return validate (cbc, 8192); 560 return validate (cbc, 8192);
@@ -527,6 +569,7 @@ main (int argc, char *const *argv)
527 569
528 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 570 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
529 return 2; 571 return 2;
572 conn_close = has_in_name (argv[0], "_close");
530 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)) 573 if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
531 { 574 {
532 errorCount += testInternalGet (); 575 errorCount += testInternalGet ();