aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/easy.c1
-rw-r--r--lib/http.c32
-rw-r--r--lib/url.c9
3 files changed, 31 insertions, 11 deletions
diff --git a/lib/easy.c b/lib/easy.c
index 7a8278dd8..34d76caab 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -555,6 +555,7 @@ void curl_easy_reset(CURL *curl)
data->set.fread = (curl_read_callback)fread;
data->set.infilesize = -1; /* we don't know any size */
+ data->set.postfieldsize = -1;
data->state.current_speed = -1; /* init to negative == impossible */
diff --git a/lib/http.c b/lib/http.c
index 9b51cc7d6..cdc3e1d8c 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1767,6 +1767,24 @@ CURLcode Curl_http(struct connectdata *conn)
switch(httpreq) {
case HTTPREQ_POST_FORM:
+ if(!http->sendit) {
+ /* nothing to post! */
+ result = add_bufferf(req_buffer, "Content-Length: 0\r\n\r\n");
+ if(result)
+ return result;
+
+ result = add_buffer_send(req_buffer, conn,
+ &data->info.request_size);
+ if(result)
+ failf(data, "Failed sending POST request");
+ else
+ /* setup variables for the upcoming transfer */
+ result = Curl_Transfer(conn, FIRSTSOCKET, -1, TRUE,
+ &http->readbytecount,
+ -1, NULL);
+ break;
+ }
+
if(Curl_FormInit(&http->form, http->sendit)) {
failf(data, "Internal HTTP POST error!");
return CURLE_HTTP_POST_ERROR;
@@ -1895,7 +1913,7 @@ CURLcode Curl_http(struct connectdata *conn)
/* this is the simple POST, using x-www-form-urlencoded style */
/* store the size of the postfields */
- postsize = data->set.postfieldsize?
+ postsize = (data->set.postfieldsize != -1)?
data->set.postfieldsize:
(data->set.postfields?(curl_off_t)strlen(data->set.postfields):0);
@@ -1989,12 +2007,14 @@ CURLcode Curl_http(struct connectdata *conn)
else {
add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
- /* set the upload size to the progress meter */
- Curl_pgrsSetUploadSize(data, data->set.infilesize);
+ if(data->set.postfieldsize) {
+ /* set the upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, postsize?postsize:-1);
- /* set the pointer to mark that we will send the post body using
- the read callback */
- http->postdata = (char *)&http->postdata;
+ /* set the pointer to mark that we will send the post body using
+ the read callback */
+ http->postdata = (char *)&http->postdata;
+ }
}
/* issue the request */
result = add_buffer_send(req_buffer, conn,
diff --git a/lib/url.c b/lib/url.c
index c474bdcab..5d0e801b5 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -317,6 +317,7 @@ CURLcode Curl_open(struct SessionHandle **curl)
data->set.fread = (curl_read_callback)fread;
data->set.infilesize = -1; /* we don't know any size */
+ data->set.postfieldsize = -1;
data->state.current_speed = -1; /* init to negative == impossible */
@@ -657,11 +658,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...)
case CURLOPT_POSTFIELDS:
/*
- * A string with POST data. Makes curl HTTP POST.
+ * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
*/
data->set.postfields = va_arg(param, char *);
- if(data->set.postfields)
- data->set.httpreq = HTTPREQ_POST;
+ data->set.httpreq = HTTPREQ_POST;
break;
case CURLOPT_POSTFIELDSIZE:
@@ -685,8 +685,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...)
* Set to make us do HTTP POST
*/
data->set.httppost = va_arg(param, struct curl_httppost *);
- if(data->set.httppost)
- data->set.httpreq = HTTPREQ_POST_FORM;
+ data->set.httpreq = HTTPREQ_POST_FORM;
break;
case CURLOPT_REFERER: