Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1514.c
2653 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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 "first.h"
30
31
#include "memdebug.h"
32
33
struct t1514_WriteThis {
34
char *readptr;
35
size_t sizeleft;
36
};
37
38
static size_t t1514_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
39
{
40
struct t1514_WriteThis *pooh = (struct t1514_WriteThis *)userp;
41
42
if(size*nmemb < 1)
43
return 0;
44
45
if(pooh->sizeleft) {
46
*ptr = pooh->readptr[0]; /* copy one single byte */
47
pooh->readptr++; /* advance pointer */
48
pooh->sizeleft--; /* less data left */
49
return 1; /* we return 1 byte at a time! */
50
}
51
52
return 0; /* no more data left to deliver */
53
}
54
55
static CURLcode test_lib1514(const char *URL)
56
{
57
CURL *curl;
58
CURLcode res = CURLE_OK;
59
60
static char testdata[] = "dummy";
61
62
struct t1514_WriteThis pooh = { testdata, sizeof(testdata)-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, t1514_read_cb);
72
easy_setopt(curl, CURLOPT_READDATA, &pooh);
73
74
if(testnum == 1539) {
75
/* speak HTTP 1.0 - no chunked! */
76
easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
77
}
78
79
res = curl_easy_perform(curl);
80
81
test_cleanup:
82
83
curl_easy_cleanup(curl);
84
curl_global_cleanup();
85
86
return res;
87
}
88
89