Git init
[external/curl.git] / tests / libtest / lib553.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  *
9  * This test case and code is based on the bug recipe Joe Malicki provided for
10  * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
11  */
12
13 #include "test.h"
14
15 #include "memdebug.h"
16
17 #define POSTLEN 40960
18
19 static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
20 {
21   static size_t total=POSTLEN;
22   static char buf[1024];
23   (void)stream;
24
25   memset(buf, 'A', sizeof(buf));
26
27   size *= nmemb;
28   if (size > total)
29     size = total;
30
31   if(size > sizeof(buf))
32     size = sizeof(buf);
33
34   memcpy(ptr, buf, size);
35   total -= size;
36   return size;
37 }
38
39 #define NUM_HEADERS 8
40 #define SIZE_HEADERS 5000
41
42 static char buf[SIZE_HEADERS + 100];
43
44 int test(char *URL)
45 {
46   CURL *curl;
47   CURLcode res = CURLE_FAILED_INIT;
48   int i;
49   struct curl_slist *headerlist=NULL, *hl;
50
51   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
52     fprintf(stderr, "curl_global_init() failed\n");
53     return TEST_ERR_MAJOR_BAD;
54   }
55
56   if((curl = curl_easy_init()) == NULL) {
57     fprintf(stderr, "curl_easy_init() failed\n");
58     curl_global_cleanup();
59     return TEST_ERR_MAJOR_BAD;
60   }
61
62   for (i = 0; i < NUM_HEADERS; i++) {
63     int len = sprintf(buf, "Header%d: ", i);
64     memset(&buf[len], 'A', SIZE_HEADERS);
65     buf[len + SIZE_HEADERS]=0; /* zero terminate */
66     hl = curl_slist_append(headerlist,  buf);
67     if (!hl)
68       goto test_cleanup;
69     headerlist = hl;
70   }
71
72   hl = curl_slist_append(headerlist, "Expect: ");
73   if (!hl)
74     goto test_cleanup;
75   headerlist = hl;
76
77   test_setopt(curl, CURLOPT_URL, URL);
78   test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
79   test_setopt(curl, CURLOPT_POST, 1L);
80 #ifdef CURL_DOES_CONVERSIONS
81   /* Convert the POST data to ASCII */
82   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
83 #endif
84   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
85   test_setopt(curl, CURLOPT_VERBOSE, 1L);
86   test_setopt(curl, CURLOPT_HEADER, 1L);
87   test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
88
89   res = curl_easy_perform(curl);
90
91 test_cleanup:
92
93   curl_easy_cleanup(curl);
94
95   curl_slist_free_all(headerlist);
96
97   curl_global_cleanup();
98
99   return (int)res;
100 }