1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

progress: callback for POSTs less than MAX_INITIAL_POST_SIZE

Add a call to Curl_pgrsSetUploadSize in this case valided by a test
case.

Reported by: Никита Дорохин.
Bug: http://curl.haxx.se/mail/lib-2010-04/0173.html
This commit is contained in:
Julien Chaffraix 2010-08-16 22:54:19 +02:00 committed by Daniel Stenberg
parent 4d703ee100
commit 6b490ed33c
5 changed files with 148 additions and 2 deletions

View File

@ -2894,6 +2894,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
if(result)
return result;
/* Make sure the progress information is accurate */
Curl_pgrsSetUploadSize(data, postsize);
}
else {
/* A huge POST coming up, do data separate from the request */

View File

@ -67,7 +67,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \
test312 test1105 test565 test800 test1106 test801 test566 test802 test803 \
test1107 test1108 test1109 test1110 test1111 test1112 test129 test567 \
test568 test569 test570 test571 test572 test804 test805 test806 test807 \
test573 test313 test1115
test573 test313 test1115 test578
filecheck:
@mkdir test-place; \

52
tests/data/test578 Normal file
View File

@ -0,0 +1,52 @@
<testcase>
<info>
<keywords>
HTTP
HTTP POST
</keywords>
</info>
#
# Server-side
<reply name="1">
<data mode="text">
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 is what to use instead of 'curl'
<tool>
lib578
</tool>
<name>
HTTP POST lower than MAX_INITIAL_POST_SIZE with progress callback
</name>
<command>
http://%HOSTIP:%HTTPPORT/500 log/ip578
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
<file name="log/ip578" mode="text">
PASSED, UL data matched data size
</file>
</verify>
</testcase>

View File

@ -8,7 +8,7 @@ SUPPORTFILES = first.c test.h
noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \
lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516 \
lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527 \
lib574 lib575 lib576 lib577 \
lib574 lib575 lib576 lib577 lib578 \
lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \
lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \
lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \
@ -160,3 +160,5 @@ lib571_SOURCES = lib571.c $(SUPPORTFILES)
lib572_SOURCES = lib572.c $(SUPPORTFILES)
lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL)
lib578_SOURCES = lib578.c $(SUPPORTFILES)

90
tests/libtest/lib578.c Normal file
View File

@ -0,0 +1,90 @@
/*****************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
*/
#include "test.h"
#include "memdebug.h"
/* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
static char data[]="this is a short string.\n";
static size_t data_size = sizeof(data) / sizeof(char);
static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
FILE *moo = fopen(libtest_arg2, "wb");
(void)clientp; /* UNUSED */
(void)dltotal; /* UNUSED */
(void)dlnow; /* UNUSED */
if(moo) {
if ((size_t)ultotal == data_size && (size_t)ulnow == data_size)
fprintf(moo, "PASSED, UL data matched data size\n");
else
fprintf(moo, "Progress callback called with UL %f out of %f\n", ulnow, ultotal);
fclose(moo);
}
return 0;
}
int test(char *URL)
{
CURL *curl;
CURLcode res=CURLE_OK;
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
if ((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
/* First set the URL that is about to receive our POST. */
test_setopt(curl, CURLOPT_URL, URL);
/* Now specify we want to POST data */
test_setopt(curl, CURLOPT_POST, 1L);
#ifdef CURL_DOES_CONVERSIONS
/* Convert the POST data to ASCII */
test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
#endif
/* Set the expected POST size */
test_setopt(curl, CURLOPT_POSTFIELDSIZE, data_size);
test_setopt(curl, CURLOPT_POSTFIELDS, data);
/* we want to use our own progress function */
test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
/* pointer to pass to our read function */
/* get verbose debug output please */
test_setopt(curl, CURLOPT_VERBOSE, 1L);
/* include headers in the output */
test_setopt(curl, CURLOPT_HEADER, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}