Skip to content

Commit

Permalink
add unix-abstract support in http util
Browse files Browse the repository at this point in the history
  • Loading branch information
Edmond Luo committed Dec 4, 2020
1 parent 4fe4fa4 commit 65dae86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/transport/http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,14 @@ func newFramer(conn net.Conn, writeBufferSize, readBufferSize int, maxHeaderList
// parseDialTarget returns the network and address to pass to dialer.
func parseDialTarget(target string) (string, string) {
net := "tcp"
if strings.HasPrefix(target, "unix-abstract:") {
// handle unix-abstract:addr which will fail with url.Parse
// and need prepend "\x00" to the parsed address
return "unix", "\x00" + strings.SplitN(target, ":",2)[1]
}
m1 := strings.Index(target, ":")
m2 := strings.Index(target, ":/")
// handle unix:addr which will fail with url.Parse
// handle unix:addr which will fail with url.Parse
if m1 >= 0 && m2 < 0 {
if n := target[0:m1]; n == "unix" {
return n, target[m1+1:]
Expand Down
4 changes: 4 additions & 0 deletions internal/transport/http_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func (s) TestParseDialTarget(t *testing.T) {
{"unix://domain", "unix", "domain"},
{"unix://etcd:0", "unix", "etcd:0"},
{"unix:///etcd:0", "unix", "/etcd:0"},
{"unix-abstract:abc", "unix", "\x00abc"},
{"unix-abstract:abc edf", "unix", "\x00abc edf"},
{"unix-abstract:///abc", "unix", "\x00///abc"},
{"unix-abstract:unix:abc", "unix", "\x00unix:abc"},
{"passthrough://unix://domain", "tcp", "passthrough://unix://domain"},
{"https://google.com:443", "tcp", "https://google.com:443"},
{"dns:///google.com", "tcp", "dns:///google.com"},
Expand Down

0 comments on commit 65dae86

Please sign in to comment.