/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/23/*24* Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST25* size is unknown.26*/2728#include "test.h"2930#include "memdebug.h"3132static char testdata[]="dummy";3334struct WriteThis {35char *readptr;36size_t sizeleft;37};3839static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp)40{41struct WriteThis *pooh = (struct WriteThis *)userp;4243if(size*nmemb < 1)44return 0;4546if(pooh->sizeleft) {47*ptr = pooh->readptr[0]; /* copy one single byte */48pooh->readptr++; /* advance pointer */49pooh->sizeleft--; /* less data left */50return 1; /* we return 1 byte at a time! */51}5253return 0; /* no more data left to deliver */54}5556CURLcode test(char *URL)57{58CURL *curl;59CURLcode result = CURLE_OK;60CURLcode res = CURLE_OK;61struct WriteThis pooh = { testdata, sizeof(testdata)-1 };6263global_init(CURL_GLOBAL_ALL);6465easy_init(curl);6667easy_setopt(curl, CURLOPT_URL, URL);68easy_setopt(curl, CURLOPT_POST, 1L);69/* Purposely omit to set CURLOPT_POSTFIELDSIZE */70easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);71easy_setopt(curl, CURLOPT_READDATA, &pooh);72#ifdef LIB153973/* speak HTTP 1.0 - no chunked! */74easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);75#endif7677result = curl_easy_perform(curl);7879test_cleanup:8081curl_easy_cleanup(curl);82curl_global_cleanup();8384return result;85}868788