1
/*****************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
14
static const char * const post[]={
18
"and a final longer crap: four",
27
static int progress_callback(void *clientp, double dltotal, double dlnow,
28
double ultotal, double ulnow)
31
static int prev_ultotal = -1;
32
static int prev_ulnow = -1;
33
(void)clientp; /* UNUSED */
34
(void)dltotal; /* UNUSED */
35
(void)dlnow; /* UNUSED */
37
/* to avoid depending on timing, which will cause this progress function to
38
get called a different number of times depending on circumstances, we
39
only log these lines if the numbers are different from the previous
41
if((prev_ultotal != (int)ultotal) ||
42
(prev_ulnow != (int)ulnow)) {
44
moo = fopen(libtest_arg2, "ab");
46
fprintf(moo, "Progress callback called with UL %d out of %d\n",
47
(int)ulnow, (int)ultotal);
50
prev_ulnow = (int) ulnow;
51
prev_ultotal = (int) ultotal;
56
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
58
struct WriteThis *pooh = (struct WriteThis *)userp;
64
data = post[pooh->counter];
67
size_t len = strlen(data);
68
memcpy(ptr, data, len);
69
pooh->counter++; /* advance pointer */
72
return 0; /* no more data left to deliver */
78
CURLcode res=CURLE_OK;
79
struct curl_slist *slist = NULL;
80
struct WriteThis pooh;
83
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
84
fprintf(stderr, "curl_global_init() failed\n");
85
return TEST_ERR_MAJOR_BAD;
88
if ((curl = curl_easy_init()) == NULL) {
89
fprintf(stderr, "curl_easy_init() failed\n");
90
curl_global_cleanup();
91
return TEST_ERR_MAJOR_BAD;
94
slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
96
fprintf(stderr, "curl_slist_append() failed\n");
97
curl_easy_cleanup(curl);
98
curl_global_cleanup();
99
return TEST_ERR_MAJOR_BAD;
102
/* First set the URL that is about to receive our POST. */
103
test_setopt(curl, CURLOPT_URL, URL);
105
/* Now specify we want to POST data */
106
test_setopt(curl, CURLOPT_POST, 1L);
108
#ifdef CURL_DOES_CONVERSIONS
109
/* Convert the POST data to ASCII */
110
test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
113
/* we want to use our own read function */
114
test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
116
/* pointer to pass to our read function */
117
test_setopt(curl, CURLOPT_INFILE, &pooh);
119
/* get verbose debug output please */
120
test_setopt(curl, CURLOPT_VERBOSE, 1L);
122
/* include headers in the output */
123
test_setopt(curl, CURLOPT_HEADER, 1L);
125
/* enforce chunked transfer by setting the header */
126
test_setopt(curl, CURLOPT_HTTPHEADER, slist);
128
test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
129
test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
131
/* we want to use our own progress function */
132
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
133
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
135
/* Perform the request, res will get the return code */
136
res = curl_easy_perform(curl);
140
/* clean up the headers list */
142
curl_slist_free_all(slist);
145
curl_easy_cleanup(curl);
146
curl_global_cleanup();