blob: 8b2d23b4731d6fd67584c1cd140e188d5ffec133 [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "test.h"
25
26#include "memdebug.h"
27
28static char buffer[17000]; /* more than 16K */
29
30int test(char *URL)
31{
32 CURL *curl;
33 CURLcode res = CURLE_OK;
34 CURLFORMcode formrc;
35 struct curl_httppost *formpost = NULL;
36 struct curl_httppost *lastptr = NULL;
37
38 /* create a buffer with AAAA...BBBBB...CCCC...etc */
39 int i;
40 int size = (int)sizeof(buffer)/1000;
41
42 for(i = 0; i < size ; i++)
43 memset(&buffer[i * 1000], 65 + i, 1000);
44
45 buffer[ sizeof(buffer)-1] = 0; /* null-terminate */
46
47 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
48 fprintf(stderr, "curl_global_init() failed\n");
49 return TEST_ERR_MAJOR_BAD;
50 }
51
52 /* Check proper name and data copying. */
53 formrc = curl_formadd(&formpost, &lastptr,
54 CURLFORM_COPYNAME, "hello",
55 CURLFORM_COPYCONTENTS, buffer,
56 CURLFORM_END);
57
58 if(formrc)
59 printf("curl_formadd(1) = %d\n", (int) formrc);
60
61
62 curl = curl_easy_init();
63 if(!curl) {
64 fprintf(stderr, "curl_easy_init() failed\n");
65 curl_formfree(formpost);
66 curl_global_cleanup();
67 return TEST_ERR_MAJOR_BAD;
68 }
69
70 /* First set the URL that is about to receive our POST. */
71 test_setopt(curl, CURLOPT_URL, URL);
72
73 /* send a multi-part formpost */
74 test_setopt(curl, CURLOPT_HTTPPOST, formpost);
75
76 /* get verbose debug output please */
77 test_setopt(curl, CURLOPT_VERBOSE, 1L);
78
79 /* include headers in the output */
80 test_setopt(curl, CURLOPT_HEADER, 1L);
81
82 /* Perform the request, res will get the return code */
83 res = curl_easy_perform(curl);
84
85test_cleanup:
86
87 /* always cleanup */
88 curl_easy_cleanup(curl);
89
90 /* now cleanup the formpost chain */
91 curl_formfree(formpost);
92
93 curl_global_cleanup();
94
95 return res;
96}