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

compare host using lowercase #543

Merged
merged 3 commits into from
Sep 11, 2018
Merged

compare host using lowercase #543

merged 3 commits into from
Sep 11, 2018

Conversation

shantanugadgil
Copy link
Contributor

use lowercase comparison for host lookup #542

use lowercase comparison for host lookup #542
@CLAassistant
Copy link

CLAassistant commented Sep 3, 2018

CLA assistant check
All committers have signed the CLA.

@aaronhurt
Copy link
Member

Moving conversation from #542 over here. Looking a bit deeper into the code it seems a bit inconsistent. When adding a route via a service tag the host is always forced lowercase as you have observed via parseURLPrefixTag (https://github.com/fabiolb/fabio/blob/master/registry/consul/parse.go#L48)

Furthermore, incoming hosts are not always forced lower-case before searching the table. To be consistent we may want to modify the underlying addRoute (https://github.com/fabiolb/fabio/blob/master/route/table.go#L137) function to also force lowercase the host in addition to forcing a lowercase lookup.

@shantanugadgil
Copy link
Contributor Author

@leprechau my Go skills are pretty basic and I had suggested this change as it worked for me.
(I have tested the binary for my use case)

I am perfectly fine with any other changes as well.
Should I resubmit with the other changes?

@aaronhurt
Copy link
Member

aaronhurt commented Sep 11, 2018

I think we can make all lookups and adds lowercase by making two simple changes in route/table.go like this ...

diff --git a/route/table.go b/route/table.go
index bb689dc..1646e74 100644
--- a/route/table.go
+++ b/route/table.go
@@ -136,6 +136,7 @@ func NewTable(s string) (t Table, err error) {
 // addRoute adds a new route prefix -> target for the given service.
 func (t Table) addRoute(d *RouteDef) error {
        host, path := hostpath(d.Src)
+       host = strings.ToLower(host) // maintain compatibility with parseURLPrefixTag
 
        if d.Src == "" {
                return errInvalidPrefix
@@ -383,6 +384,7 @@ func (t Table) LookupHost(host string, pick picker) *Target {
 }
 
 func (t Table) lookup(host, path, trace string, pick picker, match matcher) *Target {
+       host = strings.ToLower(host) // routes are always added lowercase
        for _, r := range t[host] {
                if match(path, r) {
                        n := len(r.Targets)

This wouldn't require any changes to the lookupHostFn in main.go as that function calls Lookup which in turn calls the lookup function in table.go

@aaronhurt
Copy link
Member

Running a make test those two changes to table.go don't appear to break existing tests.

@aaronhurt aaronhurt merged commit f3f6552 into fabiolb:master Sep 11, 2018
@aaronhurt
Copy link
Member

@shantanugadgil Thank you!

@shantanugadgil
Copy link
Contributor Author

hehe @leprechau thank you !!! 👍

@magiconair magiconair added this to the 1.5.10 milestone Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants