/***************************************************************************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 "first.h"2930#include "memdebug.h"3132struct t1514_WriteThis {33char *readptr;34size_t sizeleft;35};3637static size_t t1514_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)38{39struct t1514_WriteThis *pooh = (struct t1514_WriteThis *)userp;4041if(size*nmemb < 1)42return 0;4344if(pooh->sizeleft) {45*ptr = pooh->readptr[0]; /* copy one single byte */46pooh->readptr++; /* advance pointer */47pooh->sizeleft--; /* less data left */48return 1; /* we return 1 byte at a time! */49}5051return 0; /* no more data left to deliver */52}5354static CURLcode test_lib1514(const char *URL)55{56CURL *curl;57CURLcode res = CURLE_OK;5859static char testdata[] = "dummy";6061struct t1514_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, t1514_read_cb);71easy_setopt(curl, CURLOPT_READDATA, &pooh);7273if(testnum == 1539) {74/* speak HTTP 1.0 - no chunked! */75easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);76}7778res = curl_easy_perform(curl);7980test_cleanup:8182curl_easy_cleanup(curl);83curl_global_cleanup();8485return res;86}878889