]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test1901: verify chunked POST from callback with CURLOPT_POSTFIELDSIZE set
authorDaniel Stenberg <daniel@haxx.se>
Tue, 2 Apr 2024 13:27:54 +0000 (15:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 2 Apr 2024 21:38:35 +0000 (23:38 +0200)
Follow-up to 721941aadf4ad

Ref: #13257
Closes #13262

tests/data/Makefile.inc
tests/data/test1901 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib1901.c [new file with mode: 0644]

index c580210e78ccc9bdef7a69f24ac93424e036de19..2fc287dbcdc67acab1563f4fa401ca3d0f888e1b 100644 (file)
@@ -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 (file)
index 0000000..143a5f1
--- /dev/null
@@ -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>
index 9f7cec6027431dd1d073c6ce4a4dfeee9fe73cda..c55d528ab51409eb1fed9d189fba8e1b8d2650fe 100644 (file)
@@ -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 (file)
index 0000000..8835c6b
--- /dev/null
@@ -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;
+}