Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OnDial option which allows overriding dialing #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wangjia184
Copy link

This change allows to override dial.

For example, run http proxy over socks proxy

var (
	socksDialer proxy.Dialer = nil
)

func runHttpProxy(sock5Port, httpPort uint) error {

	var err error

	// create a socks5 dialer
	addr := fmt.Sprintf("127.0.0.1:%d", sock5Port)
	socksDialer, err = proxy.SOCKS5("tcp", addr, nil, proxy.Direct)
	if err != nil {
		return err
	}

	prx, _ := httpproxy.NewProxy()
	prx.OnDial = onHttpProxyDial

	addr = fmt.Sprintf(":%d", httpPort)
	return http.ListenAndServe(addr, prx)
}

func onHttpProxyDial(network, addr string) (conn net.Conn, err error) {
	return socksDialer.Dial(network, addr)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant