test1901: verify chunked POST from callback with CURLOPT_POSTFIELDSIZE set
Follow-up to 721941aadf
Ref: #13257
Closes #13262
This commit is contained in:
parent
721941aadf
commit
308cc482ef
@ -221,7 +221,7 @@ test1700 test1701 test1702 test1703 test1704 \
|
||||
\
|
||||
test1800 test1801 \
|
||||
\
|
||||
test1900 test1903 test1904 test1905 test1906 test1907 \
|
||||
test1900 test1901 test1903 test1904 test1905 test1906 test1907 \
|
||||
test1908 test1909 test1910 test1911 test1912 test1913 test1914 test1915 \
|
||||
test1916 test1917 test1918 test1919 \
|
||||
\
|
||||
|
||||
60
tests/data/test1901
Normal file
60
tests/data/test1901
Normal file
@ -0,0 +1,60 @@
|
||||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
HTTP
|
||||
HTTP POST
|
||||
CURLOPT_READFUNCTION
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
# Server-side
|
||||
<reply>
|
||||
<data crlf="yes" nocheck="yes">
|
||||
HTTP/1.1 200 OK
|
||||
Content-Length: 6
|
||||
Content-Type: text/html
|
||||
|
||||
-foo-
|
||||
</data>
|
||||
</reply>
|
||||
|
||||
# Client-side
|
||||
<client>
|
||||
<server>
|
||||
http
|
||||
</server>
|
||||
|
||||
<name>
|
||||
Chunked HTTP POST from callback with CURLOPT_POSTFIELDSIZE set
|
||||
</name>
|
||||
<tool>
|
||||
lib%TESTNUMBER
|
||||
</tool>
|
||||
|
||||
<command>
|
||||
http://%HOSTIP:%HTTPPORT/boom
|
||||
</command>
|
||||
</client>
|
||||
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
<protocol crlf="yes">
|
||||
POST /boom HTTP/1.1
|
||||
Host: %HOSTIP:%HTTPPORT
|
||||
Accept: */*
|
||||
Transfer-Encoding: chunked
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
3
|
||||
one
|
||||
3
|
||||
two
|
||||
5
|
||||
three
|
||||
4
|
||||
four
|
||||
0
|
||||
|
||||
</protocol>
|
||||
</verify>
|
||||
</testcase>
|
||||
@ -66,7 +66,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect libprereq \
|
||||
\
|
||||
lib1662 \
|
||||
\
|
||||
lib1900 \
|
||||
lib1900 lib1901 \
|
||||
lib1903 lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \
|
||||
lib1915 lib1916 lib1917 lib1918 lib1919 \
|
||||
lib1933 lib1934 lib1935 lib1936 lib1937 lib1938 lib1939 lib1940 \
|
||||
@ -545,6 +545,8 @@ lib1662_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib1900_SOURCES = lib1900.c $(SUPPORTFILES)
|
||||
|
||||
lib1901_SOURCES = lib1901.c $(SUPPORTFILES)
|
||||
|
||||
lib1903_SOURCES = lib1903.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib1903_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
|
||||
95
tests/libtest/lib1901.c
Normal file
95
tests/libtest/lib1901.c
Normal file
@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "test.h"
|
||||
|
||||
#include "testutil.h"
|
||||
#include "warnless.h"
|
||||
#include "memdebug.h"
|
||||
|
||||
|
||||
|
||||
static const char *chunks[]={
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"four",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
static int ix = 0;
|
||||
(void)size;
|
||||
(void)nmemb;
|
||||
(void)stream;
|
||||
if(chunks[ix]) {
|
||||
size_t len = strlen(chunks[ix]);
|
||||
strcpy(ptr, chunks[ix]);
|
||||
ix++;
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test(char *URL)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
struct curl_slist *chunk = NULL;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* deliberately setting the size - to a wrong value to make sure libcurl
|
||||
ignores it */
|
||||
easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 4L);
|
||||
easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
|
||||
easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
||||
easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_1_1);
|
||||
easy_setopt(curl, CURLOPT_URL, URL);
|
||||
easy_setopt(curl, CURLOPT_READDATA, NULL);
|
||||
|
||||
chunk = curl_slist_append(chunk, "Expect:");
|
||||
if(chunk) {
|
||||
struct curl_slist *n =
|
||||
curl_slist_append(chunk, "Transfer-Encoding: chunked");
|
||||
if(n)
|
||||
chunk = n;
|
||||
if(n)
|
||||
easy_setopt(curl, CURLOPT_HTTPHEADER, n);
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
}
|
||||
test_cleanup:
|
||||
curl_easy_cleanup(curl);
|
||||
curl_slist_free_all(chunk);
|
||||
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user