@@ -527,8 +527,7 @@ static bool common_download_model(
527527 return true ;
528528}
529529
530- // get remote file content, returns <http_code, content>
531- std::pair<long , std::vector<char >> common_remote_get_content (const std::string & url, const std::vector<std::string> & headers) {
530+ std::pair<long , std::vector<char >> common_remote_get_content (const std::string & url, const common_remote_params & params) {
532531 curl_ptr curl (curl_easy_init (), &curl_easy_cleanup);
533532 curl_slist_ptr http_headers;
534533 std::vector<char > res_buffer;
@@ -546,23 +545,29 @@ std::pair<long, std::vector<char>> common_remote_get_content(const std::string &
546545#if defined(_WIN32)
547546 curl_easy_setopt (curl.get (), CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
548547#endif
549- // Important: the User-Agent must be "llama-cpp" to get the "ggufFile" field in the response
548+ if (params.timeout > 0 ) {
549+ curl_easy_setopt (curl.get (), CURLOPT_TIMEOUT, params.timeout );
550+ }
551+ if (params.max_size > 0 ) {
552+ curl_easy_setopt (curl.get (), CURLOPT_MAXFILESIZE, params.max_size );
553+ }
550554 http_headers.ptr = curl_slist_append (http_headers.ptr , " User-Agent: llama-cpp" );
551- for (const auto & header : headers) {
555+ for (const auto & header : params. headers ) {
552556 http_headers.ptr = curl_slist_append (http_headers.ptr , header.c_str ());
553557 }
554558 curl_easy_setopt (curl.get (), CURLOPT_HTTPHEADER, http_headers.ptr );
555559
556560 CURLcode res = curl_easy_perform (curl.get ());
557561
558562 if (res != CURLE_OK) {
559- throw std::runtime_error (" error: cannot make GET request to HF API" );
563+ std::string error_msg = curl_easy_strerror (res);
564+ throw std::runtime_error (" error: cannot make GET request : " + error_msg);
560565 }
561566
562567 long res_code;
563568 curl_easy_getinfo (curl.get (), CURLINFO_RESPONSE_CODE, &res_code);
564569
565- return { res_code, res_buffer };
570+ return { res_code, std::move ( res_buffer) };
566571}
567572
568573/* *
@@ -592,9 +597,13 @@ static struct common_hf_file_res common_get_hf_file(const std::string & hf_repo_
592597 if (!bearer_token.empty ()) {
593598 headers.push_back (" Authorization: Bearer " + bearer_token);
594599 }
600+ // Important: the User-Agent must be "llama-cpp" to get the "ggufFile" field in the response
601+ // User-Agent header is already set in common_remote_get_content, no need to set it here
595602
596603 // make the request
597- auto res = common_remote_get_content (url, headers);
604+ common_remote_params params;
605+ params.headers = headers;
606+ auto res = common_remote_get_content (url, params);
598607 long res_code = res.first ;
599608 std::string res_str (res.second .data (), res.second .size ());
600609 std::string ggufFile;
@@ -655,7 +664,7 @@ static struct common_hf_file_res common_get_hf_file(const std::string &, const s
655664 return {};
656665}
657666
658- std::pair<long , std::vector<char >> common_remote_get_content (const std::string & url, const std::vector<std::string> & headers ) {
667+ std::pair<long , std::vector<char >> common_remote_get_content (const std::string & url, const common_remote_params & params ) {
659668 throw std::runtime_error (" error: built without CURL, cannot download model from the internet" );
660669}
661670
0 commit comments