Merge pull request #1400 from minhvh93/master

#1399 [BUG]Can't set file server in subdomain with request path is "/"

Former-commit-id: 3710e0f3a01a8d297de7161e4793c258ab8f05ba
This commit is contained in:
Gerasimos (Makis) Maropoulos 2019-12-13 23:11:25 +02:00 committed by GitHub
commit 0c4038964c
5 changed files with 17 additions and 5 deletions

View File

@ -488,7 +488,11 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio
continue continue
} }
requestPath := s.RequestPath[strings.Index(s.RequestPath, api.relativePath)+len(api.relativePath):] slashIdx := strings.IndexByte(s.RequestPath, '/')
if slashIdx == -1 {
slashIdx = 0
}
requestPath = s.RequestPath[slashIdx:]
routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...) routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...)
getRoute.StaticSites = append(getRoute.StaticSites, s) getRoute.StaticSites = append(getRoute.StaticSites, s)
} }

View File

@ -231,6 +231,11 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri
return "", "/" return "", "/"
} }
splitPath := strings.Split(s, ".")
if len(splitPath) == 2 && splitPath[1] == "" {
return splitPath[0] + ".", "/"
}
slashIdx := strings.IndexByte(s, '/') slashIdx := strings.IndexByte(s, '/')
if slashIdx > 0 { if slashIdx > 0 {
// has subdomain // has subdomain

View File

@ -116,6 +116,8 @@ func TestSplitSubdomainAndPath(t *testing.T) {
path string path string
}{ }{
{"admin./users/42", "admin.", "/users/42"}, {"admin./users/42", "admin.", "/users/42"},
{"static.", "static.", "/"},
{"static./" + WildcardFileParam(), "static.", "/" + WildcardFileParam()},
{"//api/users\\42", "", "/api/users/42"}, {"//api/users\\42", "", "/api/users/42"},
{"admin./users//42", "admin.", "/users/42"}, {"admin./users//42", "admin.", "/users/42"},
{"*./users/42/", "*.", "/users/42"}, {"*./users/42/", "*.", "/users/42"},

View File

@ -4,13 +4,14 @@ Builtin Handlers
| Middleware | Example | | Middleware | Example |
| -----------|-------------| | -----------|-------------|
| [basic authentication](basicauth) | [iris/_examples/authentication/basicauth](https://github.com/kataras/iris/tree/master/_examples/authentication/basicauth) | | [basic authentication](basicauth) | [iris/_examples/authentication/basicauth](https://github.com/kataras/iris/tree/master/_examples/authentication/basicauth) |
| [Google reCAPTCHA](recaptcha) | [iris/_examples/miscellaneous/recaptcha](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recaptcha) |
| [localization and internationalization](i18n) | [iris/_examples/miscellaneous/i81n](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n) | | [localization and internationalization](i18n) | [iris/_examples/miscellaneous/i81n](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n) |
| [request logger](logger) | [iris/_examples/http_request/request-logger](https://github.com/kataras/iris/tree/master/_examples/http_request/request-logger) | | [request logger](logger) | [iris/_examples/http_request/request-logger](https://github.com/kataras/iris/tree/master/_examples/http_request/request-logger) |
| [HTTP method override](methodoverride) | [iris/middleware/methodoverride/methodoverride_test.go](https://github.com/kataras/iris/blob/master/middleware/methodoverride/methodoverride_test.go) |
| [profiling (pprof)](pprof) | [iris/_examples/miscellaneous/pprof](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/pprof) | | [profiling (pprof)](pprof) | [iris/_examples/miscellaneous/pprof](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/pprof) |
| [Google reCAPTCHA](recaptcha) | [iris/_examples/miscellaneous/recaptcha](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recaptcha) |
| [recovery](recover) | [iris/_examples/miscellaneous/recover](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recover) | | [recovery](recover) | [iris/_examples/miscellaneous/recover](https://github.com/kataras/iris/tree/master/_examples/miscellaneous/recover) |
Experimental Handlers Community made
------------ ------------
Most of the experimental handlers are ported to work with _iris_'s handler form, from third-party sources. Most of the experimental handlers are ported to work with _iris_'s handler form, from third-party sources.
@ -30,7 +31,7 @@ Most of the experimental handlers are ported to work with _iris_'s handler form,
Third-Party Handlers Third-Party Handlers
------------ ------------
iris has its own middleware form of `func(ctx context.Context)` but it's also compatible with all `net/http` middleware forms. See [here](https://github.com/kataras/iris/tree/master/_examples/convert-handlers). Iris has its own middleware form of `func(ctx context.Context)` but it's also compatible with all `net/http` middleware forms. See [here](https://github.com/kataras/iris/tree/master/_examples/convert-handlers).
Here's a small list of useful third-party handlers: Here's a small list of useful third-party handlers:

View File

@ -109,7 +109,7 @@ type I18n struct {
locales map[string][]*ini.File locales map[string][]*ini.File
} }
// If `Config.Default` is missing and `Config.Languages` or `Config.Map` contains this key then it will set as the default locale, // If `Config.Default` is missing and `Config.Languages` or `Config.LanguagesMap` contains this key then it will set as the default locale,
// no need to be exported(see `Config.Default`). // no need to be exported(see `Config.Default`).
const defLangCode = "en-US" const defLangCode = "en-US"