diff --git a/gb.net.curl/src/CCurl.c b/gb.net.curl/src/CCurl.c index ebddaf236..0290c56f4 100644 --- a/gb.net.curl/src/CCurl.c +++ b/gb.net.curl/src/CCurl.c @@ -260,8 +260,20 @@ void CURL_init_stream(void *_object) void CURL_init_options(void *_object) { + curl_easy_setopt(THIS_CURL, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(THIS_CURL, CURLOPT_TIMEOUT, THIS->timeout); + curl_easy_setopt(THIS_CURL, CURLOPT_VERBOSE, (bool)THIS->debug); + curl_easy_setopt(THIS_CURL, CURLOPT_PRIVATE, (char*)_object); + + if (THIS->buffer_size) + curl_easy_setopt(THIS_CURL, CURLOPT_BUFFERSIZE, THIS->buffer_size); + curl_easy_setopt(THIS_CURL, CURLOPT_SSL_VERIFYPEER, THIS->ssl_verify_peer ? 1 : 0); curl_easy_setopt(THIS_CURL, CURLOPT_SSL_VERIFYHOST , THIS->ssl_verify_host ? 2 : 0); + + CURL_proxy_set(&THIS->proxy.proxy, THIS_CURL); + CURL_user_set(&THIS->user, THIS_CURL); + curl_easy_setopt(THIS_CURL, CURLOPT_URL, THIS_URL); } #define CHECK_PROGRESS_VAL(_var) if (THIS->_var != (int64_t)_var) { THIS->_var = (int64_t)_var; raise = TRUE; } @@ -426,6 +438,7 @@ bool CURL_copy_from(CCURL *dest, CCURL *src) dest->async = src->async; dest->timeout = src->timeout; dest->debug = src->debug; + dest->buffer_size = src->buffer_size; COPY_STRING(url); dest->user.auth = src->user.auth; @@ -497,6 +510,31 @@ BEGIN_PROPERTY(Curl_Timeout) END_PROPERTY +BEGIN_PROPERTY(Curl_BufferSize) + + if (READ_PROPERTY) + GB.ReturnInteger(THIS->buffer_size); + else + { + int buffer_size; + + if (CURL_check_active(THIS)) + return; + + buffer_size = VPROP(GB_INTEGER); + if (buffer_size <= 0) + buffer_size = 0; + else if (buffer_size < 1024) + buffer_size = 1024; + else if (buffer_size > CURL_MAX_READ_SIZE) + buffer_size = CURL_MAX_READ_SIZE; + + THIS->buffer_size = buffer_size; + } + +END_PROPERTY + + BEGIN_PROPERTY(Curl_Password) if (READ_PROPERTY) @@ -594,7 +632,7 @@ BEGIN_METHOD_VOID(Curl_new) THIS->ssl_verify_host = TRUE; THIS->proxy.parent_status = (int*)&THIS_STATUS; - + END_METHOD BEGIN_METHOD_VOID(Curl_free) @@ -745,6 +783,7 @@ GB_DESC CurlDesc[] = GB_PROPERTY_READ("Status", "i", Curl_Status), GB_PROPERTY_READ("ErrorText", "s", Curl_ErrorText), GB_PROPERTY("Debug", "b", Curl_Debug), + GB_PROPERTY("BufferSize", "i", Curl_BufferSize), GB_PROPERTY_READ("Downloaded", "l", Curl_Downloaded), GB_PROPERTY_READ("Uploaded", "l", Curl_Uploaded), diff --git a/gb.net.curl/src/CCurl.h b/gb.net.curl/src/CCurl.h index 8e50423bc..dec252faa 100644 --- a/gb.net.curl/src/CCurl.h +++ b/gb.net.curl/src/CCurl.h @@ -32,6 +32,10 @@ #include #include +#ifndef CURL_MAX_READ_SIZE +#define CURL_MAX_READ_SIZE 524288 +#endif + //#define DEBUG 1 #ifndef __CCURL_C @@ -70,6 +74,7 @@ typedef CPROXY proxy; CURL_USER user; int timeout; + int buffer_size; int method; // 0->Get, 1->Put char *data; int64_t dltotal; diff --git a/gb.net.curl/src/CFtpClient.c b/gb.net.curl/src/CFtpClient.c index 5ef8cf41e..afab7dbc3 100644 --- a/gb.net.curl/src/CFtpClient.c +++ b/gb.net.curl/src/CFtpClient.c @@ -110,21 +110,13 @@ static void ftp_initialize_curl_handle(void *_object) #endif } - curl_easy_setopt(THIS_CURL, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(THIS_CURL, CURLOPT_TIMEOUT, THIS->timeout); - curl_easy_setopt(THIS_CURL, CURLOPT_VERBOSE, (bool)THIS->debug); - curl_easy_setopt(THIS_CURL, CURLOPT_PRIVATE,(char*)_object); - - CURL_proxy_set(&THIS->proxy.proxy,THIS_CURL); - CURL_user_set(&THIS->user, THIS_CURL); - curl_easy_setopt(THIS_CURL, CURLOPT_URL,THIS_URL); + CURL_init_options(THIS); curl_easy_setopt(THIS_CURL, CURLOPT_FTP_USE_EPSV, (long)(THIS_FTP->no_epsv ? 0 : 1)); ftp_reset(THIS_FTP); THIS_STATUS = NET_CONNECTING; - CURL_init_options(THIS); CURL_init_stream(THIS); } diff --git a/gb.net.curl/src/CHttpClient.c b/gb.net.curl/src/CHttpClient.c index 8e16fb834..f9f0f72af 100644 --- a/gb.net.curl/src/CHttpClient.c +++ b/gb.net.curl/src/CHttpClient.c @@ -195,10 +195,8 @@ static void http_initialize_curl_handle(void *_object, GB_ARRAY custom_headers) THIS_CURL = curl_easy_init(); } - curl_easy_setopt(THIS_CURL, CURLOPT_NOSIGNAL,1); - curl_easy_setopt(THIS_CURL, CURLOPT_TIMEOUT,THIS->timeout); - curl_easy_setopt(THIS_CURL, CURLOPT_VERBOSE, (bool)THIS->debug); - curl_easy_setopt(THIS_CURL, CURLOPT_PRIVATE,(char*)_object); + CURL_init_options(THIS); + curl_easy_setopt(THIS_CURL, CURLOPT_USERAGENT, THIS_HTTP->sUserAgent); curl_easy_setopt(THIS_CURL, CURLOPT_ENCODING, THIS_HTTP->encoding); curl_easy_setopt(THIS_CURL, CURLOPT_HEADERFUNCTION, (curl_write_callback)http_header_curl); @@ -212,10 +210,6 @@ static void http_initialize_curl_handle(void *_object, GB_ARRAY custom_headers) else curl_easy_setopt(THIS_CURL, CURLOPT_COOKIEJAR, NULL); - CURL_proxy_set(&THIS->proxy.proxy, THIS_CURL); - CURL_user_set(&THIS->user, THIS_CURL); - curl_easy_setopt(THIS_CURL, CURLOPT_URL, THIS_URL); - THIS_HTTP->return_code = 0; GB.FreeString(&THIS_HTTP->return_string); @@ -229,7 +223,6 @@ static void http_initialize_curl_handle(void *_object, GB_ARRAY custom_headers) GB.Ref(custom_headers); } - CURL_init_options(THIS); CURL_init_stream(THIS); }