<commit_before>package httpclient

import (
	"net"
	"net/url"
	"os"

	goproxy "golang.org/x/net/proxy"
)

type DialFunc func(network, address string) (net.Conn, error)

func (f DialFunc) Dial(network, address string) (net.Conn, error) { return f(network, address) }

func SOCKS5DialFuncFromEnvironment(origDialer DialFunc) DialFunc {
	allProxy := os.Getenv("BOSH_ALL_PROXY")
	if len(allProxy) == 0 {
		return origDialer
	}

	proxyURL, err := url.Parse(allProxy)
	if err != nil {
		return origDialer
	}

	proxy, err := goproxy.FromURL(proxyURL, origDialer)
	if err != nil {
		return origDialer
	}

	noProxy := os.Getenv("no_proxy")
	if len(noProxy) == 0 {
		return proxy.Dial
	}

	perHost := goproxy.NewPerHost(proxy, origDialer)
	perHost.AddFromString(noProxy)

	return perHost.Dial
}
<commit_msg>Use socks5-proxy dialer when BOSH_ALL_PROXY has ssh+socks5:// schema.<commit_after>package httpclient

import (
	"io/ioutil"
	"net"
	"net/url"
	"os"
	"strings"

	proxy "github.com/cloudfoundry/socks5-proxy"

	goproxy "golang.org/x/net/proxy"
)

type DialFunc func(network, address string) (net.Conn, error)

func (f DialFunc) Dial(network, address string) (net.Conn, error) { return f(network, address) }

func SOCKS5DialFuncFromEnvironment(origDialer DialFunc) DialFunc {
	allProxy := os.Getenv("BOSH_ALL_PROXY")
	if len(allProxy) == 0 {
		return origDialer
	}

	if strings.HasPrefix(allProxy, "ssh+") && strings.Contains(allProxy, "?private-key=") {
		allProxy = strings.TrimPrefix(allProxy, "ssh+socks5://")

		proxyBaseURL := strings.Split(allProxy, "?")[0]
		proxySSHKeyPath := strings.Split(allProxy, "=")[1]

		proxySSHKey, err := ioutil.ReadFile(proxySSHKeyPath)
		if err != nil {
			return origDialer
		}

		socks5Proxy := proxy.NewSocks5Proxy(proxy.NewHostKeyGetter())
		dialer, err := socks5Proxy.Dialer(string(proxySSHKey), proxyBaseURL)
		if err != nil {
			return origDialer
		}

		return func(network, address string) (net.Conn, error) {
			return dialer(network, address)
		}
	}

	proxyURL, err := url.Parse(allProxy)
	if err != nil {
		return origDialer
	}

	proxy, err := goproxy.FromURL(proxyURL, origDialer)
	if err != nil {
		return origDialer
	}

	noProxy := os.Getenv("no_proxy")
	if len(noProxy) == 0 {
		return proxy.Dial
	}

	perHost := goproxy.NewPerHost(proxy, origDialer)
	perHost.AddFromString(noProxy)

	return perHost.Dial
}

{'fraction_non_alphanumeric': 0.13381478334749364, 'fraction_numerical': 0.006372132540356839, 'mean_word_length': 4.593824228028503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5179548', 'n_tokens_mistral': 977, 'n_tokens_neox': 915, 'n_words': 187}