diff --git a/src/c++/library/http_client.cc b/src/c++/library/http_client.cc index 6c5c7367e..ce6067d1d 100644 --- a/src/c++/library/http_client.cc +++ b/src/c++/library/http_client.cc @@ -1013,10 +1013,20 @@ InferenceServerHttpClient::Create( InferenceServerHttpClient::InferenceServerHttpClient( const std::string& url, bool verbose, const HttpSslOptions& ssl_options) - : InferenceServerClient(verbose), url_(url), ssl_options_(ssl_options), + : InferenceServerClient(verbose), ssl_options_(ssl_options), easy_handle_(reinterpret_cast(curl_easy_init())), multi_handle_(curl_multi_init()) { + std::string unix_socket_prefix("unix://"); + + if (strncmp(url.c_str(), unix_socket_prefix.c_str(), unix_socket_prefix.length()) == 0) { + // Unix domain socket + unix_socket_ = url.substr(unix_socket_prefix.length()); + url_ = "http://localhost"; + } else { + // TCP socket + url_ = url; + } } InferenceServerHttpClient::~InferenceServerHttpClient() @@ -1796,7 +1806,12 @@ InferenceServerHttpClient::PreRunProcessing( curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(curl, CURLOPT_POST, 1L); - curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); + + if (unix_socket_.empty()) { + curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); + } else { + curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str()); + } if (options.client_timeout_ != 0) { uint64_t timeout_ms = (options.client_timeout_ / 1000); @@ -2018,7 +2033,13 @@ InferenceServerHttpClient::Get( curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); - curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); + + if (unix_socket_.empty()) { + curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); + } else { + curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str()); + } + if (verbose_) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); } @@ -2094,9 +2115,15 @@ InferenceServerHttpClient::Post( curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); - curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, request.size()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); + + if (unix_socket_.empty()) { + curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L); + } else { + curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str()); + } + if (verbose_) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); } diff --git a/src/c++/library/http_client.h b/src/c++/library/http_client.h index f5aee6519..144c1c1ca 100644 --- a/src/c++/library/http_client.h +++ b/src/c++/library/http_client.h @@ -635,7 +635,9 @@ class InferenceServerHttpClient : public InferenceServerClient { void* contents, size_t size, size_t nmemb, void* userp); // The server url - const std::string url_; + std::string url_; + // The server unix socket + std::string unix_socket_; // The options for authorizing and authenticating SSL/TLS connections HttpSslOptions ssl_options_;