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

feat: wildcard support #259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
Expand Down
21 changes: 21 additions & 0 deletions httpmuxer/httpmuxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ func Start(state *utils.State) {

if currentListener == nil {
state.HTTPListeners.Range(func(key string, locationListener *utils.HTTPHolder) bool {
checkHost := locationListener.HTTPUrl.Host
wildcard := false
if strings.HasPrefix(locationListener.HTTPUrl.Host, "*.") {
checkHost = checkHost[1:]
wildcard = true
}
if wildcard && strings.HasSuffix(hostname, checkHost) {
currentListener = locationListener
authNeeded = false
return false
}
if hostname == locationListener.HTTPUrl.Host && strings.HasPrefix(c.Request.URL.Path, locationListener.HTTPUrl.Path) {
currentListener = locationListener
authNeeded = false
Expand Down Expand Up @@ -339,6 +350,16 @@ func Start(state *utils.State) {
ok := false

state.HTTPListeners.Range(func(key string, locationListener *utils.HTTPHolder) bool {
checkHost := locationListener.HTTPUrl.Host
wildcard := false
if strings.HasPrefix(locationListener.HTTPUrl.Host, "*.") {
checkHost = checkHost[1:]
wildcard = true
}
if wildcard && strings.HasSuffix(name, checkHost) {
ok = true
return false
}
if name == locationListener.HTTPUrl.Host {
ok = true
return false
Expand Down