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

client: implement support for "unix" resolver scheme #3890

Merged
merged 18 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved comments
  • Loading branch information
GarrettGutierrez1 committed Oct 16, 2020
commit 5ddbc72708d363159d09783b9bba8400ecd1b58f
8 changes: 5 additions & 3 deletions internal/grpcutil/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ func split2(s, sep string) (string, string, bool) {
}

// ParseTarget splits target into a resolver.Target struct containing scheme,
// authority and endpoint.
// authority and endpoint. skipUnixColonParsing indicates that the parse should
// not parse "unix:[path]" cases. This should be true in cases where a custom
// dialer is present, to prevent a behavior change.
//
// If target is not a valid scheme:https://authority/endpoint, it returns {Endpoint:
// target}.
func ParseTarget(target string, hasDialer bool) (ret resolver.Target) {
func ParseTarget(target string, skipUnixColonParsing bool) (ret resolver.Target) {
var ok bool
ret.Scheme, ret.Endpoint, ok = split2(target, ":https://")
if !ok {
if strings.HasPrefix(target, "unix:") && !hasDialer {
if strings.HasPrefix(target, "unix:") && !skipUnixColonParsing {
// Handle the "unix:[path]" case, because splitting on :https:// only
// handles the "unix:https://[/absolute/path]" case. Only handle if the
// dialer is nil, to avoid a behavior change with custom dialers.
Expand Down
9 changes: 5 additions & 4 deletions internal/grpcutil/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ func TestParseTargetString(t *testing.T) {
if got != test.want {
t.Errorf("ParseTarget(%q, false) = %+v, want %+v", test.targetStr, got, test.want)
}
if test.wantWithDialer == (resolver.Target{}) {
test.wantWithDialer = test.want
wantWithDialer := test.wantWithDialer
if wantWithDialer == (resolver.Target{}) {
wantWithDialer = test.want
}
got = ParseTarget(test.targetStr, true)
if got != test.wantWithDialer {
t.Errorf("ParseTarget(%q, true) = %+v, want %+v", test.targetStr, got, test.wantWithDialer)
if got != wantWithDialer {
t.Errorf("ParseTarget(%q, true) = %+v, want %+v", test.targetStr, got, wantWithDialer)
}
}
}
4 changes: 2 additions & 2 deletions internal/transport/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, backendAddr stri
}

// proxyDial dials, connecting to a proxy first if necessary. Checks if a proxy
// is necessary, dial to the proxy with using proxyDialer, does HTTP CONNECT
// handshake, and returns the connection.
// is necessary, dials, does the HTTP CONNECT handshake, and returns the
// connection.
func proxyDial(ctx context.Context, addr string, grpcUA string) (conn net.Conn, err error) {
newAddr := addr
proxyURL, err := mapAddress(ctx, addr)
Expand Down