Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLINFO_SIZE_UPLOAD may not measure correctly when Expect header removed #2847

Closed
bagder opened this issue Aug 8, 2018 · 0 comments
Closed
Assignees
Labels

Comments

@bagder
Copy link
Member

bagder commented Aug 8, 2018

I did this

Reposted bug report from the mailing list by cjmsoregan.

Reproducing example:

#include <curl/curl.h>

char g_Data[40 * 1024]; // POST 40KB

int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose)
{
    int sndbufsize = 4 * 1024; // 4KB send buffer
    setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
           (const char *)&sndbufsize, sizeof(sndbufsize));

    return CURL_SOCKOPT_OK;
}

int main(int argc, char *argv[])
{
    curl_slist* pHeaderList = NULL;
    CURL* pCurl = curl_easy_init();

    curl_easy_setopt(pCurl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);

    curl_easy_setopt(pCurl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_easy_setopt(pCurl, CURLOPT_URL, "http://example.com");

    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);

    CURLcode code = curl_easy_perform(pCurl);

    if (code == CURLE_OK)
    {
        double uploadSize = 0.0;
        curl_easy_getinfo(pCurl, CURLINFO_SIZE_UPLOAD, &uploadSize);

        printf("uploadSize = %f\n", uploadSize);

        if (static_cast<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;
}

Suggested patch:

  // http.c ~L2879
  if(http->writebytecount >= postsize) {
    /* already sent the entire request body, mark the "upload" as
       complete */
    infof(data, "upload completely sent off: %" CURL_FORMAT_CURL_OFF_T
          " out of %" CURL_FORMAT_CURL_OFF_T " bytes\n",
          http->writebytecount, postsize);
    data->req.upload_done = TRUE;
    data->req.keepon &= ~KEEP_SEND; /* we're done writing */
    data->req.exp100 = EXP100_SEND_DATA; /* already sent */
    Curl_expire_done(data, EXPIRE_100_TIMEOUT);
  }
+ else {
+   data->req.writebytecount = http->writebytecount;
+ }
@bagder bagder added the HTTP label Aug 8, 2018
@bagder bagder self-assigned this Aug 8, 2018
bagder added a commit that referenced this issue Aug 10, 2018
@bagder bagder closed this as completed in 2a278fd Aug 11, 2018
xquery pushed a commit to xquery/curl that referenced this issue Sep 3, 2018
Adds test 1522 for verification.

Reported-by: cjmsoregan
Fixes curl#2847
Closes curl#2864
falconindy pushed a commit to falconindy/curl that referenced this issue Sep 10, 2018
Adds test 1522 for verification.

Reported-by: cjmsoregan
Fixes curl#2847
Closes curl#2864
@lock lock bot locked as resolved and limited conversation to collaborators Nov 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

1 participant