| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
|  | 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 | /* | 
|  | 25 | * Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST | 
|  | 26 | * size is unknown. | 
|  | 27 | */ | 
|  | 28 |  | 
|  | 29 | #include "test.h" | 
|  | 30 |  | 
|  | 31 | #include "memdebug.h" | 
|  | 32 |  | 
|  | 33 | static char data[]="dummy"; | 
|  | 34 |  | 
|  | 35 | struct WriteThis { | 
|  | 36 | char *readptr; | 
|  | 37 | size_t sizeleft; | 
|  | 38 | }; | 
|  | 39 |  | 
|  | 40 | static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) | 
|  | 41 | { | 
|  | 42 | struct WriteThis *pooh = (struct WriteThis *)userp; | 
|  | 43 |  | 
|  | 44 | if(size*nmemb < 1) | 
|  | 45 | return 0; | 
|  | 46 |  | 
|  | 47 | if(pooh->sizeleft) { | 
|  | 48 | *ptr = pooh->readptr[0]; /* copy one single byte */ | 
|  | 49 | pooh->readptr++;                 /* advance pointer */ | 
|  | 50 | pooh->sizeleft--;                /* less data left */ | 
|  | 51 | return 1;                        /* we return 1 byte at a time! */ | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | return 0;                         /* no more data left to deliver */ | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | int test(char *URL) | 
|  | 58 | { | 
|  | 59 | CURL *curl; | 
|  | 60 | CURLcode result = CURLE_OK; | 
|  | 61 | int res = 0; | 
|  | 62 | struct WriteThis pooh = { data, sizeof(data)-1 }; | 
|  | 63 |  | 
|  | 64 | global_init(CURL_GLOBAL_ALL); | 
|  | 65 |  | 
|  | 66 | easy_init(curl); | 
|  | 67 |  | 
|  | 68 | easy_setopt(curl, CURLOPT_URL, URL); | 
|  | 69 | easy_setopt(curl, CURLOPT_POST, 1L); | 
|  | 70 | /* Purposely omit to set CURLOPT_POSTFIELDSIZE */ | 
|  | 71 | easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); | 
|  | 72 | easy_setopt(curl, CURLOPT_READDATA, &pooh); | 
|  | 73 | #ifdef LIB1539 | 
|  | 74 | /* speak HTTP 1.0 - no chunked! */ | 
|  | 75 | easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | 
|  | 76 | #endif | 
|  | 77 |  | 
|  | 78 | result = curl_easy_perform(curl); | 
|  | 79 |  | 
|  | 80 | test_cleanup: | 
|  | 81 |  | 
|  | 82 | curl_easy_cleanup(curl); | 
|  | 83 | curl_global_cleanup(); | 
|  | 84 |  | 
|  | 85 | return (int)result; | 
|  | 86 | } |