Using a socks proxy with git for the http transport

前端 未结 7 1859
臣服心动
臣服心动 2020-11-28 00:48

How to make git use a socks proxy for HTTP transport?

I succeed in configuring git with GIT_PROXY_COMMAND to use a socks proxy for GIT transport.

Also, I hav

相关标签:
7条回答
  • 2020-11-28 01:35

    Note: the patch here was applied to git in 2015 for version 2.4.11. Since that time you can just use socks:// urls with the http.proxy configuration settings.

    For the git:// protocol we have Using Git with a SOCKS proxy. However, it appears that git does not properly support socks proxies. git itself is linked to libcurl. So the .curlrc file is not used (that is just for the curl command line client). However, the following patch provides the necessary support. With this patch applied to git we can simply set the ALL_PROXY environment variable or HTTP_PROXY or HTTPS_PROXY to socks://hostname:portnum (or socks4/socks5) or indeed the http.proxy git config setting and libcurl will now actually use the socks protocol when using the proxy.

    For example, an active trace:

    $ GIT_CURL_VERBOSE=1 bin-wrappers/git -c "http.proxy=socks://localhost:1080" ls-remote http://github.com/patthoyts/tclftd2xx.git
    * Couldn't find host github.com in the _netrc file; using defaults
    * About to connect() to proxy localhost port 1080 (#0)
    *   Trying 127.0.0.1...
    * connected
    * SOCKS4 request granted.
    * Connected to localhost (127.0.0.1) port 1080 (#0)
    > GET /patthoyts/tclftd2xx.git/info/refs?service=git-upload-pack HTTP/1.1
    User-Agent: git/1.8.1.msysgit.1.dirty
    ... and on to a successful request ...
    

    The necessary patch:

    diff --git a/http.c b/http.c
    index 3b312a8..f34cc75 100644
    --- a/http.c
    +++ b/http.c
    @@ -322,6 +322,14 @@ static CURL *get_curl_handle(void)
            if (curl_http_proxy) {
                    curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
                    curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
    +#if LIBCURL_VERSION_NUM >= 0x071800
    +               if (!strncmp("socks5", curl_http_proxy, 6))
    +                       curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    +               else if (!strncmp("socks4a", curl_http_proxy, 7))
    +                       curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
    +               else if (!strncmp("socks", curl_http_proxy, 5))
    +                       curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
    +#endif
            }
    
            return result;
    
    0 讨论(0)
提交回复
热议问题