lib1598.c (3076B)
1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 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 25 /* 26 * This unit test PUT http data over proxy. Proxy header will be different 27 * from server http header 28 */ 29 30 #include "first.h" 31 32 #include "memdebug.h" 33 34 /* 35 * carefully not leak memory on OOM 36 */ 37 static int t1598_trailers_callback(struct curl_slist **list, void *userdata) 38 { 39 struct curl_slist *nlist = NULL; 40 struct curl_slist *nlist2 = NULL; 41 (void)userdata; 42 nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1"); 43 if(nlist) 44 nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2"); 45 if(nlist2) { 46 *list = nlist2; 47 return CURL_TRAILERFUNC_OK; 48 } 49 else { 50 curl_slist_free_all(nlist); 51 return CURL_TRAILERFUNC_ABORT; 52 } 53 } 54 55 static CURLcode test_lib1598(char *URL) 56 { 57 static const char *post_data = "xxx=yyy&aaa=bbbbb"; 58 59 CURL *curl = NULL; 60 CURLcode res = CURLE_FAILED_INIT; 61 /* http and proxy header list */ 62 struct curl_slist *hhl = NULL, *list; 63 64 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 65 curl_mfprintf(stderr, "curl_global_init() failed\n"); 66 return TEST_ERR_MAJOR_BAD; 67 } 68 69 curl = curl_easy_init(); 70 if(!curl) { 71 curl_mfprintf(stderr, "curl_easy_init() failed\n"); 72 curl_global_cleanup(); 73 return TEST_ERR_MAJOR_BAD; 74 } 75 76 hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer," 77 " my-other-awesome-trailer"); 78 if(!hhl) 79 goto test_cleanup; 80 if(hhl) { 81 list = curl_slist_append(hhl, "Transfer-Encoding: chunked"); 82 if(!list) 83 goto test_cleanup; 84 hhl = list; 85 } 86 87 test_setopt(curl, CURLOPT_URL, URL); 88 test_setopt(curl, CURLOPT_HTTPHEADER, hhl); 89 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(post_data)); 90 test_setopt(curl, CURLOPT_POSTFIELDS, post_data); 91 test_setopt(curl, CURLOPT_TRAILERFUNCTION, t1598_trailers_callback); 92 test_setopt(curl, CURLOPT_TRAILERDATA, NULL); 93 test_setopt(curl, CURLOPT_VERBOSE, 1L); 94 95 res = curl_easy_perform(curl); 96 97 test_cleanup: 98 99 curl_easy_cleanup(curl); 100 101 curl_slist_free_all(hhl); 102 103 curl_global_cleanup(); 104 105 return res; 106 }