lib1514.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2014, 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.haxx.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  ***************************************************************************/
22 /*
23  * Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST
24  * size is unknown.
25  */
26 
27 #include "test.h"
28 
29 #include "memdebug.h"
30 
31 static char data[]="dummy";
32 
33 struct WriteThis {
34  char *readptr;
35  size_t sizeleft;
36 };
37 
38 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
39 {
40  struct WriteThis *pooh = (struct WriteThis *)userp;
41 
42  if(size*nmemb < 1)
43  return 0;
44 
45  if(pooh->sizeleft) {
46  *(char *)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 int test(char *URL)
56 {
57  CURL *curl;
59  int res = 0;
60  struct WriteThis pooh = { data, sizeof(data)-1 };
61 
63 
64  easy_init(curl);
65 
66  easy_setopt(curl, CURLOPT_URL, URL);
67  easy_setopt(curl, CURLOPT_POST, 1L);
68  /* Purposely omit to set CURLOPT_POSTFIELDSIZE */
69  easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
70  easy_setopt(curl, CURLOPT_READDATA, &pooh);
71 
72  result = curl_easy_perform(curl);
73 
74 test_cleanup:
75 
76  curl_easy_cleanup(curl);
78 
79  return (int)result;
80 }
size_t sizeleft
char * readptr
Definition: lib1514.c:34
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
UNITTEST_START char * ptr
Definition: unit1330.c:38
CURLcode
Definition: curl.h:454
static int res
UNITTEST_START int result
Definition: unit1304.c:49
static char data[]
Definition: lib1514.c:31
#define easy_init(A)
Definition: test.h:145
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
const char * readptr
int test(char *URL)
Definition: lib1514.c:55
void CURL
Definition: curl.h:102
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
Definition: lib1514.c:38
size_t size
Definition: unit1302.c:52
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static CURL * curl
Definition: sessioninfo.c:35
Definition: debug.c:29
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15