>> attached is a patch that fixes a bug where Curl_pgrsSetUploadSize is not >> called if the POST'd data is smaller than MAX_INITIAL_POST_SIZE. I have >> added a simple test case to validate the fix but I am missing one for the >> "Transfer-Encoding: chunked" case (I spend a lot of time on this one but >> could not have it working). > > Can you pass on what you did so far and I can have a look at making it work?
Thanks Daniel! I actually had thrown out the test case and rewrote it copying test565 and it worked. Please, find it attached. I am not sure the results make sense as the data is 38 bytes long but the progress displays a final 66 bytes (we likely add progress for the authentication and / or the chunk part) but at least it covers this case - and is showing progress now. Regards, Julien
From e1904bad8568138a22a75f06f402170f5ef845c1 Mon Sep 17 00:00:00 2001 From: Julien Chaffraix <[email protected]> Date: Tue, 17 Aug 2010 08:04:03 -0700 Subject: [PATCH] progress: callback for POSTs less than MAX_INITIAL_POST_SIZE Follow up test that validate chunked and (digest) authentication. --- tests/data/Makefile.am | 2 +- tests/data/test579 | 92 +++++++++++++++++++++++++++++ tests/libtest/Makefile.inc | 4 +- tests/libtest/lib579.c | 136 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 232 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 0a38477..2714b3d 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 0000000..e335a96 --- /dev/null +++ b/tests/data/test579 @@ -0,0 +1,92 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP POST +HTTP Digest auth +</keywords> +</info> +# +# Server-side +<reply> +<data> +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 + +</data> +<data1> +HTTP/1.1 200 A OK +Server: Microsoft-IIS/6.0 +Content-Type: text/html; charset=iso-8859-1 +Content-Length: 3 + +ok +</data1> +<datacheck> +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 +</datacheck> +</reply> + +# Client-side +<client> +<server> +http +</server> +# tool is what to use instead of 'curl' +<tool> +lib579 +</tool> + + <name> +small chunked HTTP POSTs with digest auth. and progress callback + </name> + <command> +http://%HOSTIP:%HTTPPORT/579 log/ip579 +</command> +</client> + +# +# Verify data after the test has been "shot" +<verify> +<file name="log/ip579" mode="text"> +Progress callback called with UL 0.000000 out of 0.000000 +Progress callback called with UL 0.000000 out of 0.000000 +Progress callback called with UL 0.000000 out of 0.000000 +Progress callback called with UL 0.000000 out of 0.000000 +Progress callback called with UL 0.000000 out of -1.000000 +Progress callback called with UL 0.000000 out of -1.000000 +Progress callback called with UL 8.000000 out of -1.000000 +Progress callback called with UL 16.000000 out of -1.000000 +Progress callback called with UL 26.000000 out of -1.000000 +Progress callback called with UL 61.000000 out of -1.000000 +Progress callback called with UL 66.000000 out of -1.000000 +Progress callback called with UL 66.000000 out of -1.000000 +Progress callback called with UL 66.000000 out of -1.000000 +Progress callback called with UL 66.000000 out of -1.000000 +</file> +</verify> +</testcase> diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index a0d73b8..a0f1c0e 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 0000000..c83d422 --- /dev/null +++ b/tests/libtest/lib579.c @@ -0,0 +1,136 @@ +/***************************************************************************** + * _ _ ____ _ + * 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 = fopen(libtest_arg2, "ab"); + + (void)clientp; /* UNUSED */ + (void)dltotal; /* UNUSED */ + (void)dlnow; /* UNUSED */ + + if(moo) { + fprintf(moo, "Progress callback called with UL %f out of %f\n", ulnow, + ultotal); + fclose(moo); + } + 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; +} -- 1.7.0.4
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
