diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index c580210e78..2fc287dbcd 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -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 \
\
diff --git a/tests/data/test1901 b/tests/data/test1901
new file mode 100644
index 0000000000..143a5f165a
--- /dev/null
+++ b/tests/data/test1901
@@ -0,0 +1,60 @@
+
+
+
+HTTP
+HTTP POST
+CURLOPT_READFUNCTION
+
+
+
+# Server-side
+
+
+HTTP/1.1 200 OK
+Content-Length: 6
+Content-Type: text/html
+
+-foo-
+
+
+
+# Client-side
+
+
+http
+
+
+
+Chunked HTTP POST from callback with CURLOPT_POSTFIELDSIZE set
+
+
+lib%TESTNUMBER
+
+
+
+http://%HOSTIP:%HTTPPORT/boom
+
+
+
+# Verify data after the test has been "shot"
+
+
+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
+
+
+
+
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 9f7cec6027..c55d528ab5 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -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)
diff --git a/tests/libtest/lib1901.c b/tests/libtest/lib1901.c
new file mode 100644
index 0000000000..8835c6b869
--- /dev/null
+++ b/tests/libtest/lib1901.c
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, , 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;
+}