Unverified Commit 2a278fd7 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

CURLINFO_SIZE_UPLOAD: fix missing counter update

Adds test 1522 for verification.

Reported-by: cjmsoregan
Fixes #2847
Closes #2864
parent 53d211bf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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 \

tests/data/test1522

0 → 100644
+53 −0
Original line number Diff line number Diff line
<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>
+4 −1
Original line number Diff line number Diff line
@@ -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
+87 −0
Original line number Diff line number Diff line
/***************************************************************************
 *                                  _   _ ____  _
 *  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;
}