From 70baf46d8ddfc07b488d17cf0f5d8e23cf7de14e Mon Sep 17 00:00:00 2001 From: Julien Chaffraix Date: Thu, 19 Aug 2010 00:27:04 +0200 Subject: [PATCH] test: added test 579 to verify progress callback for chunked post The 66 bytes checked are those 38 bytes with the chunked encoding headers added: 8+8+10+35+5 = 66 The three-letter words become 8 bytes on the wire because they are sent like: "3\r\none\r\n" ... and there's the trailing 5 bytes write after the four lines since the final chunk is sent (which is "0\r\n\r\n"). --- tests/data/Makefile.am | 2 +- tests/data/test579 | 85 +++++++++++++++++++++ tests/libtest/Makefile.inc | 4 +- tests/libtest/lib579.c | 149 +++++++++++++++++++++++++++++++++++++ 4 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 tests/data/test579 create mode 100644 tests/libtest/lib579.c diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 0a38477bc..2714b3dd2 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -67,7 +67,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \ test312 test1105 test565 test800 test1106 test801 test566 test802 test803 \ test1107 test1108 test1109 test1110 test1111 test1112 test129 test567 \ test568 test569 test570 test571 test572 test804 test805 test806 test807 \ - test573 test313 test1115 test578 + test573 test313 test1115 test578 test579 filecheck: @mkdir test-place; \ diff --git a/tests/data/test579 b/tests/data/test579 new file mode 100644 index 000000000..5f8794437 --- /dev/null +++ b/tests/data/test579 @@ -0,0 +1,85 @@ + + + +HTTP +HTTP POST +HTTP Digest auth + + +# +# Server-side + + +HTTP/1.1 100 Continue +Server: Microsoft-IIS/5.0 +Date: Sun, 03 Apr 2005 14:57:45 GMT +X-Powered-By: ASP.NET + +HTTP/1.1 401 authentication please swsbounce +Server: Microsoft-IIS/6.0 +WWW-Authenticate: Digest realm="testrealm", nonce="1053604144" +Content-Type: text/html; charset=iso-8859-1 +Content-Length: 0 + + + +HTTP/1.1 200 A OK +Server: Microsoft-IIS/6.0 +Content-Type: text/html; charset=iso-8859-1 +Content-Length: 3 + +ok + + +HTTP/1.1 100 Continue +Server: Microsoft-IIS/5.0 +Date: Sun, 03 Apr 2005 14:57:45 GMT +X-Powered-By: ASP.NET + +HTTP/1.1 401 authentication please swsbounce +Server: Microsoft-IIS/6.0 +WWW-Authenticate: Digest realm="testrealm", nonce="1053604144" +Content-Type: text/html; charset=iso-8859-1 +Content-Length: 0 + +HTTP/1.1 200 A OK +Server: Microsoft-IIS/6.0 +Content-Type: text/html; charset=iso-8859-1 +Content-Length: 3 + +ok + + + +# Client-side + + +http + +# tool is what to use instead of 'curl' + +lib579 + + + +small chunked HTTP POSTs with digest auth. and progress callback + + +http://%HOSTIP:%HTTPPORT/579 log/ip579 + + + +# +# Verify data after the test has been "shot" + + +Progress callback called with UL 0 out of 0 +Progress callback called with UL 0 out of -1 +Progress callback called with UL 8 out of -1 +Progress callback called with UL 16 out of -1 +Progress callback called with UL 26 out of -1 +Progress callback called with UL 61 out of -1 +Progress callback called with UL 66 out of -1 + + + diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index a0d73b8ef..a0f1c0ecb 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -8,7 +8,7 @@ SUPPORTFILES = first.c test.h noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \ lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516 \ lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527 \ - lib574 lib575 lib576 lib577 lib578 \ + lib574 lib575 lib576 lib577 lib578 lib579 \ lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \ lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \ lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \ @@ -162,3 +162,5 @@ lib572_SOURCES = lib572.c $(SUPPORTFILES) lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL) lib578_SOURCES = lib578.c $(SUPPORTFILES) + +lib579_SOURCES = lib579.c $(SUPPORTFILES) diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c new file mode 100644 index 000000000..01e91d8f0 --- /dev/null +++ b/tests/libtest/lib579.c @@ -0,0 +1,149 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include "memdebug.h" + +static const char *post[]={ + "one", + "two", + "three", + "and a final longer crap: four", + NULL +}; + + +struct WriteThis { + int counter; +}; + +static int progress_callback(void *clientp, double dltotal, double dlnow, + double ultotal, double ulnow) +{ + FILE *moo; + (void)clientp; /* UNUSED */ + (void)dltotal; /* UNUSED */ + (void)dlnow; /* UNUSED */ + static int prev_ultotal = -1; + static int prev_ulnow = -1; + + /* to avoid depending on timing, which will cause this progress function to + get called a different number of times depending on circumstances, we + only log these lines if the numbers are different from the previous + invoke */ + if((prev_ultotal != (int)ultotal) || + (prev_ulnow != (int)ulnow)) { + + moo = fopen(libtest_arg2, "ab"); + if(moo) { + fprintf(moo, "Progress callback called with UL %d out of %d\n", + (int)ulnow, (int)ultotal); + fclose(moo); + } + prev_ulnow = (int) ulnow; + prev_ultotal = (int) ultotal; + } + return 0; +} + +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct WriteThis *pooh = (struct WriteThis *)userp; + const char *data; + + if(size*nmemb < 1) + return 0; + + data = post[pooh->counter]; + + if(data) { + size_t len = strlen(data); + memcpy(ptr, data, len); + pooh->counter++; /* advance pointer */ + return len; + } + return 0; /* no more data left to deliver */ +} + +int test(char *URL) +{ + CURL *curl; + CURLcode res=CURLE_OK; + struct curl_slist *slist = NULL; + struct WriteThis pooh; + pooh.counter = 0; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + slist = curl_slist_append(slist, "Transfer-Encoding: chunked"); + if (slist == NULL) { + fprintf(stderr, "curl_slist_append() failed\n"); + curl_easy_cleanup(curl); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + /* First set the URL that is about to receive our POST. */ + test_setopt(curl, CURLOPT_URL, URL); + + /* Now specify we want to POST data */ + test_setopt(curl, CURLOPT_POST, 1L); + +#ifdef CURL_DOES_CONVERSIONS + /* Convert the POST data to ASCII */ + test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L); +#endif + + /* we want to use our own read function */ + test_setopt(curl, CURLOPT_READFUNCTION, read_callback); + + /* pointer to pass to our read function */ + test_setopt(curl, CURLOPT_INFILE, &pooh); + + /* get verbose debug output please */ + test_setopt(curl, CURLOPT_VERBOSE, 1L); + + /* include headers in the output */ + test_setopt(curl, CURLOPT_HEADER, 1L); + + /* enforce chunked transfer by setting the header */ + test_setopt(curl, CURLOPT_HTTPHEADER, slist); + + test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + test_setopt(curl, CURLOPT_USERPWD, "foo:bar"); + + /* we want to use our own progress function */ + test_setopt(curl, CURLOPT_NOPROGRESS, 0L); + test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + +test_cleanup: + + /* clean up the headers list */ + if(slist) + curl_slist_free_all(slist); + + /* always cleanup */ + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return res; +}