summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2018-08-10 13:57:50 +0200
committerDaniel Stenberg <daniel@haxx.se>2018-08-11 14:00:59 +0200
commit2a278fd73573d025e6d5ebde8b10d446c27d6d3f (patch)
tree19059ae179e76a0ce86d45cf8c4a4194e7a33200
parent53d211bfd1b209f62ded7e67045d584804c2309d (diff)
downloadcurl-2a278fd73573d025e6d5ebde8b10d446c27d6d3f.tar.gz
CURLINFO_SIZE_UPLOAD: fix missing counter update
Adds test 1522 for verification. Reported-by: cjmsoregan Fixes #2847 Closes #2864
-rw-r--r--lib/http.c2
-rw-r--r--tests/data/Makefile.inc2
-rw-r--r--tests/data/test152253
-rw-r--r--tests/libtest/Makefile.inc5
-rw-r--r--tests/libtest/lib1522.c87
5 files changed, 147 insertions, 2 deletions
diff --git a/lib/http.c b/lib/http.c
index bc1f85850..01ccd4ade 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2887,6 +2887,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
data->req.exp100 = EXP100_SEND_DATA; /* already sent */
Curl_expire_done(data, EXPIRE_100_TIMEOUT);
}
+ else
+ data->req.writebytecount = http->writebytecount;
}
if((conn->httpversion == 20) && data->req.upload_chunky)
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index c7769ac66..b1d9544fd 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -170,7 +170,7 @@ test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
test1516 test1517 \
\
-test1520 test1521 \
+test1520 test1521 test1522 \
\
test1525 test1526 test1527 test1528 test1529 test1530 test1531 test1532 \
test1533 test1534 test1535 test1536 test1537 test1538 \
diff --git a/tests/data/test1522 b/tests/data/test1522
new file mode 100644
index 000000000..91d6a33a2
--- /dev/null
+++ b/tests/data/test1522
@@ -0,0 +1,53 @@
+<testcase>
+<info>
+<keywords>
+CURLINFO_SIZE_UPLOAD
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 200 OK
+Date: Thu, 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>
+<server>
+http
+</server>
+<tool>
+lib1522
+</tool>
+
+<name>
+CURLINFO_SIZE_UPLOAD with small SO_SNDBUF
+</name>
+
+<command>
+http://%HOSTIP:%HTTPPORT/1522
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<stdout>
+-foo-
+uploadSize = 40960
+!!!!!!!!!! PASS
+</stdout>
+</verify>
+</testcase>
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index ecb7d1dd4..61616ba1d 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -24,7 +24,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib1156 \
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \
- lib1520 lib1521 \
+ lib1520 lib1521 lib1522 \
lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \
lib1534 lib1535 lib1536 lib1537 lib1538 \
lib1540 \
@@ -408,6 +408,9 @@ lib1520_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1520
nodist_lib1521_SOURCES = lib1521.c $(SUPPORTFILES)
lib1521_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)
+lib1522_SOURCES = lib1522.c $(SUPPORTFILES)
+lib1522_CPPFLAGS = $(AM_CPPFLAGS)
+
lib1525_SOURCES = lib1525.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1525_LDADD = $(TESTUTIL_LIBS)
lib1525_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1525
diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c
new file mode 100644
index 000000000..5a47a359c
--- /dev/null
+++ b/tests/libtest/lib1522.c
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2017, 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.haxx.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.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+/* test case and code based on https://github.com/curl/curl/issues/2847 */
+
+#include "testutil.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+static char g_Data[40 * 1024]; /* POST 40KB */
+
+static int sockopt_callback(void *clientp, curl_socket_t curlfd,
+ curlsocktype purpose)
+{
+ int sndbufsize = 4 * 1024; /* 4KB send buffer */
+ (void) clientp;
+ (void) purpose;
+#if defined(SOL_SOCKET) && defined(SO_SNDBUF)
+ setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
+ (const char *)&sndbufsize, sizeof(sndbufsize));
+#else
+ (void)curlfd;
+#endif
+ return CURL_SOCKOPT_OK;
+}
+
+int test(char *URL)
+{
+ CURLcode code;
+ struct curl_slist *pHeaderList = NULL;
+ CURL *pCurl = curl_easy_init();
+ memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
+
+ curl_easy_setopt(pCurl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+ curl_easy_setopt(pCurl, CURLOPT_URL, URL);
+ curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, g_Data);
+ curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, sizeof(g_Data));
+
+ /* Remove "Expect: 100-continue" */
+ pHeaderList = curl_slist_append(pHeaderList, "Expect:");
+
+ curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, pHeaderList);
+
+ code = curl_easy_perform(pCurl);
+
+ if(code == CURLE_OK) {
+ curl_off_t uploadSize;
+ curl_easy_getinfo(pCurl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
+
+ printf("uploadSize = %ld\n", (long)uploadSize);
+
+ if((size_t) uploadSize == sizeof(g_Data)) {
+ printf("!!!!!!!!!! PASS\n");
+ }
+ else {
+ printf("!!!!!!!!!! FAIL\n");
+ }
+ }
+ else {
+ printf("curl_easy_perform() failed. e = %d\n", code);
+ }
+
+ curl_slist_free_all(pHeaderList);
+ curl_easy_cleanup(pCurl);
+
+ return 0;
+}