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
rpc: fix RPC client doesn't handle url's without ports #6507
Changes from all commits
bd8ba9e
dc26fe6
fa4366e
30608d0
ce351d9
d34845d
9036c5e
a6a777b
c896d70
554f472
44c00ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,31 @@ func Test_parsedURL(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestMakeHTTPDialerURL(t *testing.T) { | ||
remotes := []string{"https://foo-bar.com", "http://foo-bar.com"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to add other kinds of protocols and/or test error cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tychoish what other kinds of protocols we will use in the HTTP client? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add some error cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added 2 error test cases. |
||
|
||
for _, remote := range remotes { | ||
u, err := newParsedURL(remote) | ||
require.NoError(t, err) | ||
dialFn, err := makeHTTPDialer(remote) | ||
require.Nil(t, err) | ||
|
||
addr, err := dialFn(u.Scheme, u.GetHostWithPath()) | ||
require.NoError(t, err) | ||
require.NotNil(t, addr) | ||
} | ||
|
||
errorURLs := []string{"tcp://foo-bar.com", "ftp://foo-bar.com"} | ||
|
||
for _, errorURL := range errorURLs { | ||
u, err := newParsedURL(errorURL) | ||
require.NoError(t, err) | ||
dialFn, err := makeHTTPDialer(errorURL) | ||
require.Nil(t, err) | ||
|
||
addr, err := dialFn(u.Scheme, u.GetHostWithPath()) | ||
require.Error(t, err) | ||
require.Nil(t, addr) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of input here and resulting output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://foo-bar.com
->foo-bar.com:https
http://foo-bar.com
->foo-bar.com:http
unix:///tmp/test
-> 'unix:///tmp/test' (because it's UnixSocket)ref: https://cs.opensource.google/go/go/+/refs/tags/go1.16.4:src/net/ipsock.go;drc=193d5141318d65cea310d995258288bd000d734c;l=248
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And why do we need to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fixes just try to tackle the issue @marbar3778 posted. We can just close it if we think the current error message is good enough. But the user needs to aware they need to input the URL address with port info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in
newParsedURL
function.if we dourl.Parse
withhttps://foo-bar.com
.We will get
url.Scheme
= "https",url.Host
= "foo-bar.com"So under this input case, It's not able to connect to the remote due to a missing port.
Therefore I am padding the protocol at the end of the Host, and then the socket will look up the default port for the protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will let @marbar3778 approve this one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes things a bit easier for when a user is connecting to a URL. What is the norm here? Should the application handle this instead?