Rudy Koento experienced problems with curl's recent habit of POSTing data in

two separate send() calls, first the headers and then the data. I've now made
a fix that for static and known content that isn't to be chunked-encoded,
everything is now sent in one single system call again. This is also better
for network performance reasons.
This commit is contained in:
Daniel Stenberg 2003-05-27 08:33:08 +00:00
parent fc872808c5
commit 5bd8d60e41
1 changed files with 27 additions and 20 deletions

View File

@ -906,13 +906,14 @@ CURLcode Curl_http(struct connectdata *conn)
} }
} }
do { {
/* Use 1.1 unless the use specificly asked for 1.0 */ /* Use 1.1 unless the use specificly asked for 1.0 */
const char *httpstring= const char *httpstring=
data->set.httpversion==CURL_HTTP_VERSION_1_0?"1.0":"1.1"; data->set.httpversion==CURL_HTTP_VERSION_1_0?"1.0":"1.1";
send_buffer *req_buffer; send_buffer *req_buffer;
struct curl_slist *headers=data->set.headers; struct curl_slist *headers=data->set.headers;
size_t postsize;
/* initialize a dynamic send-buffer */ /* initialize a dynamic send-buffer */
req_buffer = add_buffer_init(); req_buffer = add_buffer_init();
@ -1146,6 +1147,11 @@ CURLcode Curl_http(struct connectdata *conn)
case HTTPREQ_POST: case HTTPREQ_POST:
/* this is the simple POST, using x-www-form-urlencoded style */ /* this is the simple POST, using x-www-form-urlencoded style */
/* store the size of the postfields */
postsize = data->set.postfieldsize?
data->set.postfieldsize:
(data->set.postfields?strlen(data->set.postfields):0);
if(!conn->bits.upload_chunky) { if(!conn->bits.upload_chunky) {
/* We only set Content-Length and allow a custom Content-Length if /* We only set Content-Length and allow a custom Content-Length if
we don't upload data chunked, as RFC2616 forbids us to set both we don't upload data chunked, as RFC2616 forbids us to set both
@ -1154,11 +1160,7 @@ CURLcode Curl_http(struct connectdata *conn)
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", postsize);
"Content-Length: %d\r\n",
data->set.postfieldsize?
data->set.postfieldsize:
(data->set.postfields?strlen(data->set.postfields):0) );
} }
if(!checkheaders(data, "Content-Type:")) if(!checkheaders(data, "Content-Type:"))
@ -1169,10 +1171,15 @@ CURLcode Curl_http(struct connectdata *conn)
/* and here we setup the pointers to the actual data */ /* and here we setup the pointers to the actual data */
if(data->set.postfields) { if(data->set.postfields) {
if(data->set.postfieldsize)
http->postsize = data->set.postfieldsize; if(!conn->bits.upload_chunky) {
else /* We have a static chunk of data to POST, and we're not sending
http->postsize = strlen(data->set.postfields); it 'chunked', then we can just as well append it to the request
already now to reduce the number if send() calls */
add_buffer(req_buffer, data->set.postfields, postsize);
}
else {
http->postsize = postsize;
http->postdata = data->set.postfields; http->postdata = data->set.postfields;
http->sending = HTTPSEND_BODY; http->sending = HTTPSEND_BODY;
@ -1183,6 +1190,7 @@ CURLcode Curl_http(struct connectdata *conn)
/* set the upload size to the progress meter */ /* set the upload size to the progress meter */
Curl_pgrsSetUploadSize(data, http->postsize); Curl_pgrsSetUploadSize(data, http->postsize);
} }
}
else else
/* set the upload size to the progress meter */ /* set the upload size to the progress meter */
Curl_pgrsSetUploadSize(data, data->set.infilesize); Curl_pgrsSetUploadSize(data, data->set.infilesize);
@ -1197,8 +1205,8 @@ CURLcode Curl_http(struct connectdata *conn)
result = result =
Curl_Transfer(conn, conn->firstsocket, -1, TRUE, Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
&http->readbytecount, &http->readbytecount,
conn->firstsocket, http->postdata?conn->firstsocket:-1,
&http->writebytecount); http->postdata?&http->writebytecount:NULL);
break; break;
default: default:
@ -1219,8 +1227,7 @@ CURLcode Curl_http(struct connectdata *conn)
} }
if(result) if(result)
return result; return result;
} while (0); /* this is just a left-over from the multiple document download }
attempts */
return CURLE_OK; return CURLE_OK;
} }