diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-03-14 14:39:23 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-03-14 14:39:23 +0000 |
commit | 468b7872725237d538a219273532150e86ce239f (patch) | |
tree | 7c03be6ec97ccb446622f3a832504f74e35924df | |
parent | cfdb6f851ca6eb5a7979cda9b88e9fbd327cda79 (diff) |
if CURLOPT_POSTFIELDS isn't set, but CURLOPT_POST is, we will assume that
we should read the POST-data from the read callback
-rw-r--r-- | lib/http.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/lib/http.c b/lib/http.c index c4d44b47c..a7d8098fe 100644 --- a/lib/http.c +++ b/lib/http.c @@ -814,7 +814,9 @@ CURLcode Curl_http(struct connectdata *conn) 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)) { failf(data, "Internal 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 */ return result; } - } - else if(HTTPREQ_PUT == data->set.httpreq) { - /* Let's PUT the data to the server! */ + break; + + case HTTPREQ_PUT: /* Let's PUT the data to the server! */ if(data->set.infilesize>0) { add_bufferf(req_buffer, @@ -911,51 +913,51 @@ CURLcode Curl_http(struct connectdata *conn) &http->writebytecount); if(result) return result; - - } - else { - if(HTTPREQ_POST == data->set.httpreq) { - /* this is the simple POST, using x-www-form-urlencoded style */ - - if(!data->set.postfields) { - /* - * 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! */ - } + break; - if(!checkheaders(data, "Content-Length:")) - /* we allow replacing this header, although it isn't very wise to - actually set your own */ - add_bufferf(req_buffer, - "Content-Length: %d\r\n", - (data->set.postfieldsize?data->set.postfieldsize: - strlen(data->set.postfields)) ); + case HTTPREQ_POST: + /* this is the simple POST, using x-www-form-urlencoded style */ - if(!checkheaders(data, "Content-Type:")) - add_bufferf(req_buffer, - "Content-Type: application/x-www-form-urlencoded\r\n"); + if(!checkheaders(data, "Content-Length:")) + /* we allow replacing this header, although it isn't very wise to + actually set your own */ + add_bufferf(req_buffer, + "Content-Length: %d\r\n", + (data->set.postfieldsize?data->set.postfieldsize: + strlen(data->set.postfields)) ); - /* and here comes the actual data */ - if(data->set.postfieldsize) { - add_buffer(req_buffer, "\r\n", 2); - add_buffer(req_buffer, data->set.postfields, - data->set.postfieldsize); - } - else { - add_bufferf(req_buffer, - "\r\n" - "%s", - data->set.postfields ); - } + if(!checkheaders(data, "Content-Type:")) + add_bufferf(req_buffer, + "Content-Type: application/x-www-form-urlencoded\r\n"); + + add_buffer(req_buffer, "\r\n", 2); + + /* and here comes the actual data */ + if(data->set.postfieldsize && data->set.postfields) { + add_buffer(req_buffer, data->set.postfields, + data->set.postfieldsize); } + else if(data->set.postfields) + 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 - add_buffer(req_buffer, "\r\n", 2); + 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 */ result = add_buffer_send(conn->firstsocket, conn, req_buffer, &data->info.request_size); |