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").
This commit is contained in:
parent
280d2cff2e
commit
70baf46d8d
@ -67,7 +67,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \
|
|||||||
test312 test1105 test565 test800 test1106 test801 test566 test802 test803 \
|
test312 test1105 test565 test800 test1106 test801 test566 test802 test803 \
|
||||||
test1107 test1108 test1109 test1110 test1111 test1112 test129 test567 \
|
test1107 test1108 test1109 test1110 test1111 test1112 test129 test567 \
|
||||||
test568 test569 test570 test571 test572 test804 test805 test806 test807 \
|
test568 test569 test570 test571 test572 test804 test805 test806 test807 \
|
||||||
test573 test313 test1115 test578
|
test573 test313 test1115 test578 test579
|
||||||
|
|
||||||
filecheck:
|
filecheck:
|
||||||
@mkdir test-place; \
|
@mkdir test-place; \
|
||||||
|
85
tests/data/test579
Normal file
85
tests/data/test579
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<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 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
|
||||||
|
</file>
|
||||||
|
</verify>
|
||||||
|
</testcase>
|
@ -8,7 +8,7 @@ SUPPORTFILES = first.c test.h
|
|||||||
noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \
|
noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \
|
||||||
lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516 \
|
lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516 \
|
||||||
lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527 \
|
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 \
|
lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \
|
||||||
lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \
|
lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \
|
||||||
lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \
|
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)
|
lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL)
|
||||||
|
|
||||||
lib578_SOURCES = lib578.c $(SUPPORTFILES)
|
lib578_SOURCES = lib578.c $(SUPPORTFILES)
|
||||||
|
|
||||||
|
lib579_SOURCES = lib579.c $(SUPPORTFILES)
|
||||||
|
149
tests/libtest/lib579.c
Normal file
149
tests/libtest/lib579.c
Normal file
@ -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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user