Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / libtest / lib553.c
blob5030accb3b00a5308fa3b7010630c70d7d0c5894
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib553.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
10 * This test case and code is based on the bug recipe Joe Malicki provided for
11 * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
14 #include "test.h"
16 #define POSTLEN 40960
18 static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
20 static size_t total=POSTLEN;
21 static char buf[1024];
22 (void)stream;
24 memset(buf, 'A', sizeof(buf));
26 size *= nmemb;
27 if (size > total)
28 size = total;
30 if(size > sizeof(buf))
31 size = sizeof(buf);
33 memcpy(ptr, buf, size);
34 total -= size;
35 return size;
38 #define NUM_HEADERS 8
39 #define SIZE_HEADERS 5000
41 static char buf[SIZE_HEADERS + 100];
43 int test(char *URL)
45 CURL *curl;
46 CURLcode res;
47 int i;
48 struct curl_slist *headerlist=NULL, *hl;
50 curl_global_init(CURL_GLOBAL_ALL);
51 curl = curl_easy_init();
53 if(curl) {
54 for (i = 0; i < NUM_HEADERS; i++) {
55 int len = sprintf(buf, "Header%d: ", i);
56 memset(&buf[len], 'A', SIZE_HEADERS);
57 buf[len + SIZE_HEADERS]=0; /* zero terminate */
58 hl = curl_slist_append(headerlist, buf);
59 if (!hl)
60 goto errout;
61 headerlist = hl;
63 hl = curl_slist_append(headerlist, "Expect: ");
64 if (!hl)
65 goto errout;
66 headerlist = hl;
68 curl_easy_setopt(curl, CURLOPT_URL, URL);
69 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
70 curl_easy_setopt(curl, CURLOPT_POST, 1L);
71 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
72 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
73 curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
74 curl_easy_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
75 res = curl_easy_perform(curl);
77 errout:
78 curl_easy_cleanup(curl);
80 curl_slist_free_all(headerlist);
82 curl_global_cleanup();
84 return (int)res;