From c66f7a6d213f624e396af4457fdad9f2db3d6e45 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 22 Nov 2019 15:16:50 +0200 Subject: [PATCH 1/4] update middleware list Former-commit-id: 051d40a3fb553d15d9cfd55f793546e193463383 --- middleware/README.md | 7 ++++--- middleware/i18n/i18n.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/middleware/README.md b/middleware/README.md index b4402aac..46b6f3ec 100644 --- a/middleware/README.md +++ b/middleware/README.md @@ -4,13 +4,14 @@ Builtin Handlers | Middleware | Example | | -----------|-------------| | [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) | | [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) | +| [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) | -Experimental Handlers +Community made ------------ 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 ------------ -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: diff --git a/middleware/i18n/i18n.go b/middleware/i18n/i18n.go index 260ac83d..3447fbb8 100644 --- a/middleware/i18n/i18n.go +++ b/middleware/i18n/i18n.go @@ -109,7 +109,7 @@ type I18n struct { 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`). const defLangCode = "en-US" From 42dcc259e7b85ca52b9425dbbb488f4633837547 Mon Sep 17 00:00:00 2001 From: minhvh93 Date: Mon, 2 Dec 2019 20:35:15 +0700 Subject: [PATCH 2/4] #1399 [BUG]Can't set file server in subdomain with request path is "/" Former-commit-id: 2914cafeab26ae8a716138bec95ade6953ddd04b --- core/router/path.go | 5 +++++ core/router/path_test.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/core/router/path.go b/core/router/path.go index 6c32c863..6d9b687a 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -231,6 +231,11 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri return "", "/" } + splitPath := strings.Split(s, ".") + if len(splitPath) == 2 && splitPath[1] == "" { + return splitPath[0] + ".", "/" + } + slashIdx := strings.IndexByte(s, '/') if slashIdx > 0 { // has subdomain diff --git a/core/router/path_test.go b/core/router/path_test.go index 2b2c7538..bdf2d4ad 100644 --- a/core/router/path_test.go +++ b/core/router/path_test.go @@ -116,6 +116,8 @@ func TestSplitSubdomainAndPath(t *testing.T) { path string }{ {"admin./users/42", "admin.", "/users/42"}, + {"admin.", "admin.", "/"}, + {"admin./" + WildcardFileParam(), "admin.", "/" + WildcardFileParam()}, {"//api/users\\42", "", "/api/users/42"}, {"admin./users//42", "admin.", "/users/42"}, {"*./users/42/", "*.", "/users/42"}, From 6dcbbc546436095918dac48182ef348c37d65268 Mon Sep 17 00:00:00 2001 From: minhvh Date: Tue, 3 Dec 2019 10:51:00 +0700 Subject: [PATCH 3/4] #1399[FIX] file server in subdomain with request path "/" Former-commit-id: 30a86cba134b87db803aa47a277795717c694c3b --- core/router/path.go | 2 +- core/router/path_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/router/path.go b/core/router/path.go index 6d9b687a..61d7e065 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -233,7 +233,7 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri splitPath := strings.Split(s, ".") if len(splitPath) == 2 && splitPath[1] == "" { - return splitPath[0] + ".", "/" + return splitPath[0], "/" } slashIdx := strings.IndexByte(s, '/') diff --git a/core/router/path_test.go b/core/router/path_test.go index bdf2d4ad..d9b36ff6 100644 --- a/core/router/path_test.go +++ b/core/router/path_test.go @@ -116,7 +116,7 @@ func TestSplitSubdomainAndPath(t *testing.T) { path string }{ {"admin./users/42", "admin.", "/users/42"}, - {"admin.", "admin.", "/"}, + {"admin.", "admin", "/"}, {"admin./" + WildcardFileParam(), "admin.", "/" + WildcardFileParam()}, {"//api/users\\42", "", "/api/users/42"}, {"admin./users//42", "admin.", "/users/42"}, From 137fa92da52bed7f02425031f73d1a36a63cc0d3 Mon Sep 17 00:00:00 2001 From: minhvh Date: Tue, 3 Dec 2019 16:12:15 +0700 Subject: [PATCH 4/4] #1399[FIX] file server in subdomain with request path "/" Former-commit-id: de4326943640706a9a2f1418327c4a69bc5f85d9 --- core/router/api_builder.go | 6 +++++- core/router/path.go | 2 +- core/router/path_test.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/router/api_builder.go b/core/router/api_builder.go index b789bb3b..d9c244e2 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -488,7 +488,11 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio 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)...) getRoute.StaticSites = append(getRoute.StaticSites, s) } diff --git a/core/router/path.go b/core/router/path.go index 61d7e065..6d9b687a 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -233,7 +233,7 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri splitPath := strings.Split(s, ".") if len(splitPath) == 2 && splitPath[1] == "" { - return splitPath[0], "/" + return splitPath[0] + ".", "/" } slashIdx := strings.IndexByte(s, '/') diff --git a/core/router/path_test.go b/core/router/path_test.go index d9b36ff6..5e5c6abc 100644 --- a/core/router/path_test.go +++ b/core/router/path_test.go @@ -116,8 +116,8 @@ func TestSplitSubdomainAndPath(t *testing.T) { path string }{ {"admin./users/42", "admin.", "/users/42"}, - {"admin.", "admin", "/"}, - {"admin./" + WildcardFileParam(), "admin.", "/" + WildcardFileParam()}, + {"static.", "static.", "/"}, + {"static./" + WildcardFileParam(), "static.", "/" + WildcardFileParam()}, {"//api/users\\42", "", "/api/users/42"}, {"admin./users//42", "admin.", "/users/42"}, {"*./users/42/", "*.", "/users/42"},