-
Notifications
You must be signed in to change notification settings - Fork 89
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
restore default port 8500 for CONSUL_HTTP_ADDR (#394) #395
restore default port 8500 for CONSUL_HTTP_ADDR (#394) #395
Conversation
@marcin-krystianc I made a tiny adjustment to default the port to 8500 if it isn’t specified in CONSUL_HTTP_ADDR. Please let me know if this makes sense. |
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.
Hi @larrytamnjong,
implementation seems legit, please add tests for following cases:
CONSUL_HTTP_ADDR=127.0.0.1 => protocol: http, host: 127.0.0.1, port: 8500
CONSUL_HTTP_ADDR=http://127.0.0.1/ => protocol: http, host: 127.0.0.1, port: 8500
CONSUL_HTTP_ADDR=http://127.0.0.1:8500/ => protocol: http, host: 127.0.0.1, port: 8500
CONSUL_HTTP_ADDR=http://127.0.0.1:80/ => protocol: http, host: 127.0.0.1, port: 80
Please also verify the test results are the same for your implementation and the version before the ef310c2.
Hi @marcin-krystianc
However, when I run this test on commit f6a8038, I encounter exceptions with certain values of CONSUL_HTTP_ADDR:
I'm not sure if this is the expected way to test it. Could you provide some guidance on how to proceed? |
This seems to not be quite right. For determining if the original string contains a port, I'd suggest either
or |
Unit tests before ef310c2 never included scheme, which was not supported properly previously. It looks like f6a8038 breaks if the client specifies a scheme It will split the address into 3 parts for
|
@larrytamnjong , we have already a parametrised test |
I've added tests for the scenarios you mentioned and adjusted the check for the default port. The tests pass in both my implementation and commit f6a8038. The main difference is that in previous versions, we can't specify an HTTP scheme when adding the address, as noted by @orange-puff. I believe it’s ready now. Let me know your thoughts! |
@marcin-krystianc thanks.. please have a look and let me know if it's okay. |
Consul/Client.cs
Outdated
else | ||
{ | ||
consulAddress.Port = 8500; | ||
} |
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.
Assigning the default 8500 here is redundant as the consulAddress
variable already has the default port pre-assigned. You can remove the else
block entirely.
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.
@marcin-krystianc thanks. Done ✅
@@ -174,8 +174,14 @@ private void ConfigureFromEnvironment(UriBuilder consulAddress) | |||
{ | |||
consulAddress.Host = uri.Host; | |||
} | |||
|
|||
consulAddress.Port = uri.Port; | |||
if (envAddr.Contains($"{uri.Host}:{uri.Port}")) |
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'm not a fan of this, but it does the job and I don't see how we can do it differently.
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.
:)
Restore default port 8500 for CONSUL_HTTP_ADDR when no port is specif…ied (#394)