Skip to content

Commit

Permalink
feat: add support for HTTPS_PROXY
Browse files Browse the repository at this point in the history
This commit adds support for the HTTPS_PROXY environment variable.
At the moment the NO_PROXY environment variable is ignored, please
be aware of that!

This should close fullstorydev#166
  • Loading branch information
Denys Vitali committed May 3, 2022
1 parent b953ea1 commit ea55023
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2
github.com/jhump/protoreflect v1.10.3
github.com/mwitkow/go-http-dialer v0.0.0-20161116154839-378f744fb2b8 // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202
golang.org/x/text v0.3.7 // indirect
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mwitkow/go-http-dialer v0.0.0-20161116154839-378f744fb2b8 h1:BhQQWYKJwXPtAhm12d4gQU4LKS9Yov22yOrDc2QA7ho=
github.com/mwitkow/go-http-dialer v0.0.0-20161116154839-378f744fb2b8/go.mod h1:ntWhh7pzdiiRKBMxUB5iG+Q2gmZBxGxpX1KyK6N8kX8=
github.com/nishanths/predeclared v0.0.0-20200524104333-86fad755b4d3/go.mod h1:nt3d53pc1VYcphSCIaYAJtnPYnr3Zyn8fMq2wvPGPso=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
21 changes: 20 additions & 1 deletion grpcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
"encoding/base64"
"errors"
"fmt"
http_dialer "github.com/mwitkow/go-http-dialer"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
"net/url"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -638,7 +641,23 @@ func BlockingDial(ctx context.Context, network, address string, creds credential
// handshake). And that would mean that the library would send the
// wrong ":scheme" metaheader to servers: it would send "http" instead
// of "https" because it is unaware that TLS is actually in use.
conn, err := (&net.Dialer{}).DialContext(ctx, network, address)

// Use HTTPS_PROXY if it's set up:
if os.Getenv("HTTPS_PROXY") != "" {
proxyUrl, err := url.Parse(os.Getenv("HTTPS_PROXY"))
if err != nil {
panic("Invalid HTTPS_PROXY environment variable")
}

httpTunnel := http_dialer.New(proxyUrl)
conn, err := httpTunnel.Dial(network, address)
if err != nil {
writeResult(err)
}
return conn, err
}

conn, err := proxy.Dial(ctx, network, address)

This comment has been minimized.

Copy link
@denysvitali

denysvitali May 3, 2022

Collaborator

This also adds support for SOCKS proxies

if err != nil {
writeResult(err)
}
Expand Down

0 comments on commit ea55023

Please sign in to comment.