http: properly reset all values of curl connection

This commit is contained in:
josch
2014-12-05 13:09:56 +01:00
parent 972b47f449
commit f5b09193f9

View File

@@ -59,6 +59,21 @@ struct mfhttp {
* keep-alive anyways. * keep-alive anyways.
*/ */
static void http_curl_reset(mfhttp * conn)
{
curl_easy_reset(conn->curl_handle);
curl_easy_setopt(conn->curl_handle, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(conn->curl_handle, CURLOPT_PROGRESSFUNCTION,
http_progress_cb);
curl_easy_setopt(conn->curl_handle, CURLOPT_PROGRESSDATA, (void *)conn);
curl_easy_setopt(conn->curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(conn->curl_handle, CURLOPT_SSLENGINE, NULL);
curl_easy_setopt(conn->curl_handle, CURLOPT_SSLENGINE_DEFAULT, 1L);
curl_easy_setopt(conn->curl_handle, CURLOPT_ERRORBUFFER, conn->error_buf);
curl_easy_setopt(conn->curl_handle, CURLOPT_PROXY, getenv("http_proxy"));
curl_easy_setopt(conn->curl_handle, CURLOPT_VERBOSE, 0L);
}
mfhttp *http_create(void) mfhttp *http_create(void)
{ {
mfhttp *conn; mfhttp *conn;
@@ -72,20 +87,6 @@ mfhttp *http_create(void)
conn->curl_handle = curl_handle; conn->curl_handle = curl_handle;
conn->show_progress = false; conn->show_progress = false;
curl_easy_setopt(conn->curl_handle, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(conn->curl_handle, CURLOPT_PROGRESSFUNCTION,
http_progress_cb);
curl_easy_setopt(conn->curl_handle, CURLOPT_PROGRESSDATA, (void *)conn);
curl_easy_setopt(conn->curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(conn->curl_handle, CURLOPT_SSLENGINE, NULL);
curl_easy_setopt(conn->curl_handle, CURLOPT_SSLENGINE_DEFAULT, 1L);
curl_easy_setopt(conn->curl_handle, CURLOPT_ERRORBUFFER, conn->error_buf);
/*curl_easy_setopt(conn->curl_handle, CURLOPT_VERBOSE, 1L); */
return conn; return conn;
} }
@@ -128,7 +129,7 @@ http_get_buf(mfhttp * conn, const char *url,
{ {
int retval; int retval;
curl_easy_reset(conn->curl_handle); http_curl_reset(conn);
conn->write_buf_len = 0; conn->write_buf_len = 0;
curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url); curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url);
curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION, curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION,
@@ -196,7 +197,7 @@ http_post_buf(mfhttp * conn, const char *url, const char *post_args,
{ {
int retval; int retval;
curl_easy_reset(conn->curl_handle); http_curl_reset(conn);
conn->write_buf_len = 0; conn->write_buf_len = 0;
curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url); curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url);
curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION, curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION,
@@ -222,7 +223,7 @@ int http_get_file(mfhttp * conn, const char *url, const char *path)
{ {
int retval; int retval;
curl_easy_reset(conn->curl_handle); http_curl_reset(conn);
curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url); curl_easy_setopt(conn->curl_handle, CURLOPT_URL, url);
curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION, curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION,
http_read_buf_cb); http_read_buf_cb);
@@ -285,7 +286,7 @@ http_post_file(mfhttp * conn, const char *url, FILE * fh,
char *tmpheader; char *tmpheader;
int retval; int retval;
curl_easy_reset(conn->curl_handle); http_curl_reset(conn);
conn->write_buf_len = 0; conn->write_buf_len = 0;
// the following three pseudo headers are interpreted by the mediafire // the following three pseudo headers are interpreted by the mediafire