Skip to content

Commit

Permalink
Add CURLOPT_UNIX_SOCKET_PATH support to http.c
Browse files Browse the repository at this point in the history
  • Loading branch information
lcfyi committed Feb 21, 2024
1 parent 3e0d3cd commit 40c6598
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions git-curl-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
#define GIT_CURL_HAVE_CURLE_SSL_PINNEDPUBKEYNOTMATCH 1
#endif

/**
* CURLOPT_UNIX_SOCKET_PATH was added in 7.40.0, released in January 2015.
*/
#if LIBCURL_VERSION_NUM >= 0x074000
#define GIT_CURL_HAVE_CURLOPT_UNIX_SOCKET_PATH 1
#endif

/**
* CURL_HTTP_VERSION_2 was added in 7.43.0, released in June 2015.
*
Expand Down
23 changes: 23 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ static const char *http_proxy_ssl_ca_info;
static struct credential proxy_cert_auth = CREDENTIAL_INIT;
static int proxy_ssl_cert_password_required;

#if defined(GIT_CURL_HAVE_CURLOPT_UNIX_SOCKET_PATH) && !defined(NO_UNIX_SOCKETS)
static const char *curl_unix_socket_path;
#endif
static struct {
const char *name;
long curlauth_param;
Expand Down Expand Up @@ -455,6 +458,20 @@ static int http_options(const char *var, const char *value,
return 0;
}

if (!strcmp("http.unixsocket", var)) {
#ifdef GIT_CURL_HAVE_CURLOPT_UNIX_SOCKET_PATH
#ifndef NO_UNIX_SOCKETS
return git_config_string(&curl_unix_socket_path, var, value);
#else
warning(_("Unix socket support unavailable in this build of Git"));
return 0;
#endif
#else
warning(_("Unix socket support is not supported with cURL < 7.40.0"));
return 0;
#endif
}

if (!strcmp("http.cookiefile", var))
return git_config_pathname(&curl_cookie_file, var, value);
if (!strcmp("http.savecookies", var)) {
Expand Down Expand Up @@ -1203,6 +1220,12 @@ static CURL *get_curl_handle(void)
}
init_curl_proxy_auth(result);

#if defined(GIT_CURL_HAVE_CURLOPT_UNIX_SOCKET_PATH) && !defined(NO_UNIX_SOCKETS)
if (curl_unix_socket_path) {
curl_easy_setopt(result, CURLOPT_UNIX_SOCKET_PATH, curl_unix_socket_path);
}
#endif

set_curl_keepalive(result);

return result;
Expand Down

0 comments on commit 40c6598

Please sign in to comment.