aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/test_get.c')
-rw-r--r--src/testcurl/test_get.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c
index 142b41f4..c7821b21 100644
--- a/src/testcurl/test_get.c
+++ b/src/testcurl/test_get.c
@@ -501,6 +501,105 @@ testStopRace (int poll_flag)
501} 501}
502 502
503 503
504static int
505ahc_empty (void *cls,
506 struct MHD_Connection *connection,
507 const char *url,
508 const char *method,
509 const char *version,
510 const char *upload_data, size_t *upload_data_size,
511 void **unused)
512{
513 static int ptr;
514 struct MHD_Response *response;
515 int ret;
516
517 if (0 != strcmp ("GET", method))
518 return MHD_NO; /* unexpected method */
519 if (&ptr != *unused)
520 {
521 *unused = &ptr;
522 return MHD_YES;
523 }
524 *unused = NULL;
525 response = MHD_create_response_from_buffer (0,
526 NULL,
527 MHD_RESPMEM_PERSISTENT);
528 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
529 MHD_destroy_response (response);
530 if (ret == MHD_NO)
531 abort ();
532 return ret;
533}
534
535
536static int
537curlExcessFound(CURL *c, curl_infotype type, char *data, size_t size, void *cls)
538{
539 static const char *excess_found = "Excess found";
540 const size_t str_size = strlen (excess_found);
541
542 if (CURLINFO_TEXT == type
543 && size >= str_size
544 && 0 == strncmp(excess_found, data, str_size))
545 *(int *)cls = 1;
546 return 0;
547}
548
549
550static int
551testEmptyGet (int poll_flag)
552{
553 struct MHD_Daemon *d;
554 CURL *c;
555 char buf[2048];
556 struct CBC cbc;
557 CURLcode errornum;
558 int excess_found = 0;
559
560 cbc.buf = buf;
561 cbc.size = 2048;
562 cbc.pos = 0;
563 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag,
564 11081, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END);
565 if (d == NULL)
566 return 4194304;
567 c = curl_easy_init ();
568 curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
569 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
570 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
571 curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound);
572 curl_easy_setopt (c, CURLOPT_DEBUGDATA, &excess_found);
573 curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
574 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
575 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
576 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
577 if (oneone)
578 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
579 else
580 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
581 /* NOTE: use of CONNECTTIMEOUT without also
582 setting NOSIGNAL results in really weird
583 crashes on my system!*/
584 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
585 if (CURLE_OK != (errornum = curl_easy_perform (c)))
586 {
587 fprintf (stderr,
588 "curl_easy_perform failed: `%s'\n",
589 curl_easy_strerror (errornum));
590 curl_easy_cleanup (c);
591 MHD_stop_daemon (d);
592 return 8388608;
593 }
594 curl_easy_cleanup (c);
595 MHD_stop_daemon (d);
596 if (cbc.pos != 0)
597 return 16777216;
598 if (excess_found)
599 return 33554432;
600 return 0;
601}
602
504 603
505int 604int
506main (int argc, char *const *argv) 605main (int argc, char *const *argv)
@@ -516,17 +615,20 @@ main (int argc, char *const *argv)
516 errorCount += testUnknownPortGet (0); 615 errorCount += testUnknownPortGet (0);
517 errorCount += testStopRace (0); 616 errorCount += testStopRace (0);
518 errorCount += testExternalGet (); 617 errorCount += testExternalGet ();
618 errorCount += testEmptyGet (0);
519#ifndef WINDOWS 619#ifndef WINDOWS
520 errorCount += testInternalGet (MHD_USE_POLL); 620 errorCount += testInternalGet (MHD_USE_POLL);
521 errorCount += testMultithreadedGet (MHD_USE_POLL); 621 errorCount += testMultithreadedGet (MHD_USE_POLL);
522 errorCount += testMultithreadedPoolGet (MHD_USE_POLL); 622 errorCount += testMultithreadedPoolGet (MHD_USE_POLL);
523 errorCount += testUnknownPortGet (MHD_USE_POLL); 623 errorCount += testUnknownPortGet (MHD_USE_POLL);
524 errorCount += testStopRace (MHD_USE_POLL); 624 errorCount += testStopRace (MHD_USE_POLL);
625 errorCount += testEmptyGet (MHD_USE_POLL);
525#endif 626#endif
526#if EPOLL_SUPPORT 627#if EPOLL_SUPPORT
527 errorCount += testInternalGet (MHD_USE_EPOLL_LINUX_ONLY); 628 errorCount += testInternalGet (MHD_USE_EPOLL_LINUX_ONLY);
528 errorCount += testMultithreadedPoolGet (MHD_USE_EPOLL_LINUX_ONLY); 629 errorCount += testMultithreadedPoolGet (MHD_USE_EPOLL_LINUX_ONLY);
529 errorCount += testUnknownPortGet (MHD_USE_EPOLL_LINUX_ONLY); 630 errorCount += testUnknownPortGet (MHD_USE_EPOLL_LINUX_ONLY);
631 errorCount += testEmptyGet (MHD_USE_EPOLL_LINUX_ONLY);
530#endif 632#endif
531 if (errorCount != 0) 633 if (errorCount != 0)
532 fprintf (stderr, "Error (code: %u)\n", errorCount); 634 fprintf (stderr, "Error (code: %u)\n", errorCount);