go-proxy-dialer

module
v0.0.0-...-a4b748d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT

README

Go Proxy Dialers

This repo contains Dialers http connect and https for golang.org/x/net/proxy

Using HTTP Connect Dialer

import the connect package first and follow the below examples

With HTTP Client

Note: for http requests (its preferable to HTTP_PROXY and HTTPS_PROXY env vars in this case)

	uri, err := url.Parse("http://proxy_url:proxy_port")
	if err != nil {
		panic(err)
	}

	dialer, err := proxy.FromURL(uri, proxy.Direct)
	if err != nil {
		panic(err)
	}

	client := http.Client{
		Transport: &http.Transport{
			Proxy:       nil,
			DialContext: dialer.Dial,
		},
	}

With GRPC

In this case we need to make use of the grpc.WithContextDialer DialOption

grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
    uri, err := url.Parse(httpproxy.FromEnvironment().HTTPProxy)
    if err != nil {
        return nil, err
    }

    dialer, err := proxy.FromURL(uri, proxy.Direct)
    if err != nil {
        return nil, err
    }
    return dialer.Dial("tcp", addr)
}),

Using HTTPS Dialer

import the https package and follow the below example

uri, err := url.Parse(httpproxy.FromEnvironment().HTTPProxy)
    if err != nil {
        return nil, err
    }

    dialer, err := proxy.FromURL(uri, https.HTTPSDialer)
    if err != nil {
        return nil, err
    }

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL