A normal POST now provides data to the main transfer loop via the usual

read callback, and thus won't put a lot of stress on the request sending
code (which currently does an ugly loop).
This commit is contained in:
Daniel Stenberg 2002-12-09 16:05:57 +00:00
parent 4bcc866c52
commit 49f75ee8ce
2 changed files with 46 additions and 16 deletions

View File

@ -515,14 +515,14 @@ CURLcode Curl_http_done(struct connectdata *conn)
data=conn->data; data=conn->data;
http=conn->proto.http; http=conn->proto.http;
/* set the proper values (possibly modified on POST) */
conn->fread = data->set.fread; /* restore */
conn->fread_in = data->set.in; /* restore */
if(HTTPREQ_POST_FORM == data->set.httpreq) { if(HTTPREQ_POST_FORM == data->set.httpreq) {
conn->bytecount = http->readbytecount + http->writebytecount; conn->bytecount = http->readbytecount + http->writebytecount;
Curl_formclean(http->sendit); /* Now free that whole lot */ Curl_formclean(http->sendit); /* Now free that whole lot */
/* set the proper values */
conn->fread = data->set.fread; /* restore */
conn->fread_in = data->set.in; /* restore */
} }
else if(HTTPREQ_PUT == data->set.httpreq) else if(HTTPREQ_PUT == data->set.httpreq)
conn->bytecount = http->readbytecount + http->writebytecount; conn->bytecount = http->readbytecount + http->writebytecount;
@ -537,6 +537,32 @@ CURLcode Curl_http_done(struct connectdata *conn)
return CURLE_OK; return CURLE_OK;
} }
/* fread() emulation to provide POST data */
static int POSTReader(char *buffer,
size_t size,
size_t nitems,
void *userp)
{
struct HTTP *http = (struct HTTP *)userp;
int fullsize = size * nitems;
if(0 == http->postsize)
/* nothing to return */
return 0;
if(http->postsize <= fullsize) {
memcpy(buffer, http->postdata, http->postsize);
fullsize = http->postsize;
http->postsize = 0;
return fullsize;
}
memcpy(buffer, http->postdata, fullsize);
http->postdata += fullsize;
http->postsize -= fullsize;
return fullsize;
}
CURLcode Curl_http(struct connectdata *conn) CURLcode Curl_http(struct connectdata *conn)
{ {
@ -1042,17 +1068,19 @@ CURLcode Curl_http(struct connectdata *conn)
add_buffer(req_buffer, "\r\n", 2); add_buffer(req_buffer, "\r\n", 2);
/* and here comes the actual data */ /* and here we setup the pointers to the actual data */
if(data->set.postfieldsize && data->set.postfields) { if(data->set.postfields) {
add_buffer(req_buffer, data->set.postfields, if(data->set.postfieldsize)
data->set.postfieldsize); http->postsize = data->set.postfieldsize;
} else
else if(data->set.postfields) http->postsize = strlen(data->set.postfields);
add_bufferf(req_buffer, http->postdata = data->set.postfields;
"%s",
data->set.postfields );
/* issue the request */ conn->fread = (curl_read_callback)POSTReader;
conn->fread_in = (void *)http;
}
/* issue the request, headers-only */
result = add_buffer_send(req_buffer, conn->firstsocket, conn, result = add_buffer_send(req_buffer, conn->firstsocket, conn,
&data->info.request_size); &data->info.request_size);
@ -1062,8 +1090,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,
data->set.postfields?-1:conn->firstsocket, conn->firstsocket,
data->set.postfields?NULL:&http->writebytecount); &http->writebytecount);
break; break;
default: default:

View File

@ -165,6 +165,8 @@ struct HTTP {
/* For FORM posting */ /* For FORM posting */
struct Form form; struct Form form;
struct Curl_chunker chunk; struct Curl_chunker chunk;
char *postdata; /* for regular POSTs */
}; };
/**************************************************************************** /****************************************************************************