Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cpp/include/lemon/utils/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ class HttpClient {
static HttpResponse post(const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers = {},
long timeout_seconds = 300);
long timeout_seconds = -1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add a configuration option per, with global as a default if not set and then a global default of 300s?

Also, under what conditions do we really even want timeouts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeouts are configurable for safety and efficiency.


// Multipart form data POST request
static HttpResponse post_multipart(const std::string& url,
const std::vector<MultipartField>& fields,
long timeout_seconds = 300);
long timeout_seconds = -1);

// Streaming POST request (calls callback for each chunk as it arrives)
static HttpResponse post_stream(const std::string& url,
const std::string& body,
StreamCallback stream_callback,
const std::map<std::string, std::string>& headers = {},
long timeout_seconds = 300);
long timeout_seconds = -1);

// Download file to disk with automatic retry and resume support
static DownloadResult download_file(const std::string& url,
Expand Down
11 changes: 10 additions & 1 deletion src/cpp/server/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ static void add_serve_options(CLI::App* serve, ServerConfig& config) {
"Global timeout for HTTP requests, inference, and readiness checks in seconds")
->envname("LEMONADE_GLOBAL_TIMEOUT")
->type_name("SECONDS")
->default_val(config.global_timeout);
->default_val(config.global_timeout)
->transform([](std::string val) {
try {
long t = std::stol(val);
if (t > 0 && t < 300) return std::string("300");
} catch (...) {
// Ignore invalid values, let CLI11 handle them
}
return val;
});

// Multi-model support: Max loaded models per type slot
serve->add_option("--max-loaded-models", config.max_loaded_models,
Expand Down
12 changes: 6 additions & 6 deletions src/cpp/server/utils/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ HttpResponse HttpClient::post(const std::string& url,
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_body);
// Use provided timeout, or fallback to global default (set via --http-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds > 0 ? timeout_seconds : default_timeout_seconds_);
// Use provided timeout (0 = infinite), or fallback to global default (set via --global-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds >= 0 ? timeout_seconds : default_timeout_seconds_);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "lemon.cpp/1.0");

// Add custom headers
Expand Down Expand Up @@ -182,8 +182,8 @@ HttpResponse HttpClient::post_multipart(const std::string& url,
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_body);
// Use provided timeout, or fallback to global default (set via --http-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds > 0 ? timeout_seconds : default_timeout_seconds_);
// Use provided timeout (0 = infinite), or fallback to global default (set via --global-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds >= 0 ? timeout_seconds : default_timeout_seconds_);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "lemon.cpp/1.0");

CURLcode res = curl_easy_perform(curl);
Expand Down Expand Up @@ -258,8 +258,8 @@ HttpResponse HttpClient::post_stream(const std::string& url,
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, stream_write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &callback_data);
// Use provided timeout, or fallback to global default (set via --http-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds > 0 ? timeout_seconds : default_timeout_seconds_);
// Use provided timeout (0 = infinite), or fallback to global default (set via --global-timeout)
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout_seconds >= 0 ? timeout_seconds : default_timeout_seconds_);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "lemon.cpp/1.0");

// Add custom headers
Expand Down