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
31static char data[]="dummy";
32
33struct WriteThis {
34 char *readptr;
35 size_t sizeleft;
36};
37
38static 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
55int test(char *URL)
56{
57 CURL *curl;
58 CURLcode result = CURLE_OK;
59 int res = 0;
60 struct WriteThis pooh = { data, sizeof(data)-1 };
61
62 global_init(CURL_GLOBAL_ALL);
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
74test_cleanup:
75
76 curl_easy_cleanup(curl);
77 curl_global_cleanup();
78
79 return (int)result;
80}
81