Fix behaviour when passing NULL to CURLOPT_POSTFIELDS and CURLOPT_HTTPPOST.

This commit is contained in:
Daniel Stenberg 2004-11-11 23:11:04 +00:00
parent 8c16696f47
commit 59c063dfd3
11 changed files with 209 additions and 19 deletions

View file

@ -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 */

View file

@ -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,

View file

@ -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: