Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "test.h"
00028
00029 #include "memdebug.h"
00030
00031 #define POSTLEN 40960
00032
00033 static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
00034 {
00035 static size_t total=POSTLEN;
00036 static char buf[1024];
00037 (void)stream;
00038
00039 memset(buf, 'A', sizeof(buf));
00040
00041 size *= nmemb;
00042 if(size > total)
00043 size = total;
00044
00045 if(size > sizeof(buf))
00046 size = sizeof(buf);
00047
00048 memcpy(ptr, buf, size);
00049 total -= size;
00050 return size;
00051 }
00052
00053 #define NUM_HEADERS 8
00054 #define SIZE_HEADERS 5000
00055
00056 static char buf[SIZE_HEADERS + 100];
00057
00058 int test(char *URL)
00059 {
00060 CURL *curl;
00061 CURLcode res = CURLE_FAILED_INIT;
00062 int i;
00063 struct curl_slist *headerlist=NULL, *hl;
00064
00065 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00066 fprintf(stderr, "curl_global_init() failed\n");
00067 return TEST_ERR_MAJOR_BAD;
00068 }
00069
00070 curl = curl_easy_init();
00071 if(!curl) {
00072 fprintf(stderr, "curl_easy_init() failed\n");
00073 curl_global_cleanup();
00074 return TEST_ERR_MAJOR_BAD;
00075 }
00076
00077 for(i = 0; i < NUM_HEADERS; i++) {
00078 int len = snprintf(buf, sizeof(buf), "Header%d: ", i);
00079 memset(&buf[len], 'A', SIZE_HEADERS);
00080 buf[len + SIZE_HEADERS]=0;
00081 hl = curl_slist_append(headerlist, buf);
00082 if(!hl)
00083 goto test_cleanup;
00084 headerlist = hl;
00085 }
00086
00087 hl = curl_slist_append(headerlist, "Expect: ");
00088 if(!hl)
00089 goto test_cleanup;
00090 headerlist = hl;
00091
00092 test_setopt(curl, CURLOPT_URL, URL);
00093 test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
00094 test_setopt(curl, CURLOPT_POST, 1L);
00095 #ifdef CURL_DOES_CONVERSIONS
00096
00097 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00098 #endif
00099 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
00100 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00101 test_setopt(curl, CURLOPT_HEADER, 1L);
00102 test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
00103
00104 res = curl_easy_perform(curl);
00105
00106 test_cleanup:
00107
00108 curl_easy_cleanup(curl);
00109
00110 curl_slist_free_all(headerlist);
00111
00112 curl_global_cleanup();
00113
00114 return (int)res;
00115 }