]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test447: test PUTting a file that grows
authorDaniel Stenberg <daniel@haxx.se>
Tue, 30 May 2023 12:45:47 +0000 (14:45 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 1 Jun 2023 11:43:31 +0000 (13:43 +0200)
... and have curl trim the end when it reaches the expected total amount
of bytes instead of over-sending.

Reported-by: JustAnotherArchivist on github
Closes #11223

src/tool_operate.c
tests/data/Makefile.inc
tests/data/test447 [new file with mode: 0644]

index 1c49c1e4efee9dffdb655324a56e4d060d97feea..16ad0665ee7f4485da41f456008827055f3c188e 100644 (file)
@@ -319,6 +319,17 @@ static CURLcode pre_transfer(struct GlobalConfig *global,
     if(S_ISREG(fileinfo.st_mode))
       uploadfilesize = fileinfo.st_size;
 
+#ifdef DEBUGBUILD
+    /* allow dedicated test cases to override */
+    {
+      char *ev = getenv("CURL_UPLOAD_SIZE");
+      if(ev) {
+        int sz = atoi(ev);
+        uploadfilesize = (curl_off_t)sz;
+      }
+    }
+#endif
+
     if(uploadfilesize != -1) {
       struct OperationConfig *config = per->config; /* for the macro below */
 #ifdef CURL_DISABLE_LIBCURL_OPTION
index 217ada761ea346a3a1ce1db63323e27d43098737..f054175edb50ea79e381bbd7b3ad6b9a6c0f6936 100644 (file)
@@ -72,7 +72,7 @@ test417 test418 test419 test420 test421 test422 test423 test424 test425 \
 test426 \
 test430 test431 test432 test433 test434 test435 test436 \
 \
-test440 test441 test442 test443 test444 test445 test446 \
+test440 test441 test442 test443 test444 test445 test446 test447 \
 \
 test490 test491 test492 test493 test494 test495 test496 \
 \
diff --git a/tests/data/test447 b/tests/data/test447
new file mode 100644 (file)
index 0000000..76614ba
--- /dev/null
@@ -0,0 +1,65 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP PUT
+growing file
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+<data crlf="yes">
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-39462498"
+Accept-Ranges: bytes
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Funny-head: yesyes
+
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<features>
+debug
+</features>
+<server>
+http
+</server>
+<name>
+HTTP PUT with growing file
+</name>
+<setenv>
+CURL_UPLOAD_SIZE=498
+</setenv>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -T log/%TESTNUMBER
+</command>
+<file name="log/%TESTNUMBER">
+%repeat[100 x hello]%
+</file>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="yes" nonewline="yes">
+PUT /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+Content-Length: 498
+
+%repeat[99 x hello]%hel
+</protocol>
+</verify>
+</testcase>