common : add common_remote_get_content (#13123)

* common : add common_remote_get_content

* support max size and timeout

* add tests
This commit is contained in:
Xuan-Son Nguyen 2025-04-26 22:58:12 +02:00 committed by GitHub
parent 4753791e70
commit 2d451c8059
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 126 additions and 33 deletions

View file

@ -78,3 +78,12 @@ bool common_params_parse(int argc, char ** argv, common_params & params, llama_e
// function to be used by test-arg-parser
common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
bool common_has_curl();
struct common_remote_params {
std::vector<std::string> headers;
long timeout = 0; // CURLOPT_TIMEOUT, in seconds ; 0 means no timeout
long max_size = 0; // max size of the response ; unlimited if 0 ; max is 2GB
};
// get remote file content, returns <http_code, raw_response_body>
std::pair<long, std::vector<char>> common_remote_get_content(const std::string & url, const common_remote_params & params);