Use of x/net/proxy and FromEnvironmentUsing(dialer) does not work

I try to send traffic via a proxy but the code does not seem to read the environment variables. I even added all_proxy which I saw in the code.

set | grep proxy

all_proxy=http://localhost:3128
https_proxy=http://localhost:3128
no_proxy=‘localhost, 127.0.0.1’

I have also http_proxy set.

I get this error and no attempt to access the proxy.

proxyDialer.Dial
panic: dial tcp 142.250.200.36:443: i/o timeout

goroutine 1 [running]:
main.main()
/src/moelma/go-test/dialertest.go:23 +0x20e

strace shows the direct connection attempt.

socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 6
connect(6, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr(“142.250.200.36”)}, 16) = -1 EINPROGRESS (Operation now in progress)

package main

import (
        "crypto/tls"
        "net"
        "time"
        "fmt"
        "golang.org/x/net/proxy"
        "os"
        "strings"
)

func main() {

        dialer := &net.Dialer{
                Timeout : 20 * time.Millisecond,
        }

        proxyDialer := proxy.FromEnvironmentUsing(dialer)
        conn, err := proxyDialer.Dial("tcp", "www.google.com:443")
        if err != nil {
                fmt.Println("proxyDialer.Dial")
                panic(err)
        }
        conn = tls.Client(conn, &tls.Config{InsecureSkipVerify: false})

        if strings.Contains(err.Error(), "timed out") {
                fmt.Println("Connection timed out")
                os.Exit(2)
        } else {
                if err == nil {
                        conn.Close()
                }
        }

}

I think I figured it out. the net/proxy library has socks as only scheme. To add a “connect” scheme it has to be defined

e.g. Using:

    "github.com/wrouesnel/go.connect-proxy-scheme"

    proxy.RegisterDialerType("http", connect_proxy_scheme.ConnectProxy)

It would be really great if the connect scheme could be included into the net/proxy library !

Markus

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.