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

if CURLOPT_POSTFIELDS isn't set, but CURLOPT_POST is, we will assume that

we should read the POST-data from the read callback
This commit is contained in:
Daniel Stenberg 2002-03-14 14:39:23 +00:00
parent cfdb6f851c
commit 468b787272

View File

@ -814,7 +814,9 @@ CURLcode Curl_http(struct connectdata *conn)
headers = headers->next; headers = headers->next;
} }
if(HTTPREQ_POST_FORM == data->set.httpreq) { switch(data->set.httpreq) {
case HTTPREQ_POST_FORM:
if(Curl_FormInit(&http->form, http->sendit)) { if(Curl_FormInit(&http->form, http->sendit)) {
failf(data, "Internal HTTP POST error!"); failf(data, "Internal HTTP POST error!");
return CURLE_HTTP_POST_ERROR; return CURLE_HTTP_POST_ERROR;
@ -883,9 +885,9 @@ CURLcode Curl_http(struct connectdata *conn)
Curl_formclean(http->sendit); /* free that whole lot */ Curl_formclean(http->sendit); /* free that whole lot */
return result; return result;
} }
} break;
else if(HTTPREQ_PUT == data->set.httpreq) {
/* Let's PUT the data to the server! */ case HTTPREQ_PUT: /* Let's PUT the data to the server! */
if(data->set.infilesize>0) { if(data->set.infilesize>0) {
add_bufferf(req_buffer, add_bufferf(req_buffer,
@ -911,51 +913,51 @@ CURLcode Curl_http(struct connectdata *conn)
&http->writebytecount); &http->writebytecount);
if(result) if(result)
return result; return result;
break;
}
else {
if(HTTPREQ_POST == data->set.httpreq) {
/* this is the simple POST, using x-www-form-urlencoded style */
if(!data->set.postfields) { case HTTPREQ_POST:
/* /* this is the simple POST, using x-www-form-urlencoded style */
* This is an attempt to do a POST without having anything to
* actually send. Let's make a NULL pointer equal "" here. Good/bad
* ?
*/
data->set.postfields = (char *)"";
data->set.postfieldsize = 0; /* it might been set to something illegal,
anything > 0 would be! */
}
if(!checkheaders(data, "Content-Length:")) if(!checkheaders(data, "Content-Length:"))
/* we allow replacing this header, although it isn't very wise to /* we allow replacing this header, although it isn't very wise to
actually set your own */ actually set your own */
add_bufferf(req_buffer, add_bufferf(req_buffer,
"Content-Length: %d\r\n", "Content-Length: %d\r\n",
(data->set.postfieldsize?data->set.postfieldsize: (data->set.postfieldsize?data->set.postfieldsize:
strlen(data->set.postfields)) ); strlen(data->set.postfields)) );
if(!checkheaders(data, "Content-Type:")) if(!checkheaders(data, "Content-Type:"))
add_bufferf(req_buffer, add_bufferf(req_buffer,
"Content-Type: application/x-www-form-urlencoded\r\n"); "Content-Type: application/x-www-form-urlencoded\r\n");
/* and here comes the actual data */ add_buffer(req_buffer, "\r\n", 2);
if(data->set.postfieldsize) {
add_buffer(req_buffer, "\r\n", 2); /* and here comes the actual data */
add_buffer(req_buffer, data->set.postfields, if(data->set.postfieldsize && data->set.postfields) {
data->set.postfieldsize); add_buffer(req_buffer, data->set.postfields,
} data->set.postfieldsize);
else {
add_bufferf(req_buffer,
"\r\n"
"%s",
data->set.postfields );
}
} }
else else if(data->set.postfields)
add_buffer(req_buffer, "\r\n", 2); add_bufferf(req_buffer,
"%s",
data->set.postfields );
/* issue the request */
result = add_buffer_send(conn->firstsocket, conn, req_buffer,
&data->info.request_size);
if(result)
failf(data, "Failed sending HTTP POST request");
else
result =
Curl_Transfer(conn, conn->firstsocket, -1, TRUE, bytecount,
data->set.postfields?-1:conn->firstsocket,
data->set.postfields?NULL:&http->writebytecount);
break;
default:
add_buffer(req_buffer, "\r\n", 2);
/* issue the request */ /* issue the request */
result = add_buffer_send(conn->firstsocket, conn, req_buffer, result = add_buffer_send(conn->firstsocket, conn, req_buffer,
&data->info.request_size); &data->info.request_size);