1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
14 static const char *post[]={
18 "and a final longer crap: four",
27 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
29 struct WriteThis *pooh = (struct WriteThis *)userp;
35 data = post[pooh->counter];
38 size_t len = strlen(data);
39 memcpy(ptr, data, len);
40 pooh->counter++; /* advance pointer */
43 return 0; /* no more data left to deliver */
49 CURLcode res=CURLE_OK;
50 struct curl_slist *slist = NULL;
51 struct WriteThis pooh;
54 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
55 fprintf(stderr, "curl_global_init() failed\n");
56 return TEST_ERR_MAJOR_BAD;
59 if ((curl = curl_easy_init()) == NULL) {
60 fprintf(stderr, "curl_easy_init() failed\n");
61 curl_global_cleanup();
62 return TEST_ERR_MAJOR_BAD;
65 slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
67 fprintf(stderr, "curl_slist_append() failed\n");
68 curl_easy_cleanup(curl);
69 curl_global_cleanup();
70 return TEST_ERR_MAJOR_BAD;
73 /* First set the URL that is about to receive our POST. */
74 test_setopt(curl, CURLOPT_URL, URL);
76 /* Now specify we want to POST data */
77 test_setopt(curl, CURLOPT_POST, 1L);
79 #ifdef CURL_DOES_CONVERSIONS
80 /* Convert the POST data to ASCII */
81 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
84 /* we want to use our own read function */
85 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
87 /* pointer to pass to our read function */
88 test_setopt(curl, CURLOPT_INFILE, &pooh);
90 /* get verbose debug output please */
91 test_setopt(curl, CURLOPT_VERBOSE, 1L);
93 /* include headers in the output */
94 test_setopt(curl, CURLOPT_HEADER, 1L);
96 /* enforce chunked transfer by setting the header */
97 test_setopt(curl, CURLOPT_HTTPHEADER, slist);
100 test_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
101 test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
104 /* Perform the request, res will get the return code */
105 res = curl_easy_perform(curl);
109 /* clean up the headers list */
111 curl_slist_free_all(slist);
114 curl_easy_cleanup(curl);
115 curl_global_cleanup();