From 4feda40370364dd61bf9eb45c6400c1afadf1830 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Wed, 29 Apr 2020 21:16:43 +0300 Subject: [PATCH] apply https://github.com/kataras/iris/issues/1500 --- .../basic/assets.system/css/main.css | 3 ++ .../file-server/basic/assets.system/test.txt | 1 + _examples/file-server/basic/main_test.go | 42 +++++++++++++------ core/router/fs.go | 2 - core/router/handler.go | 5 ++- mvc/controller.go | 1 + mvc/grpc.go | 2 + 7 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 _examples/file-server/basic/assets.system/css/main.css create mode 100644 _examples/file-server/basic/assets.system/test.txt diff --git a/_examples/file-server/basic/assets.system/css/main.css b/_examples/file-server/basic/assets.system/css/main.css new file mode 100644 index 000000000..7db3df1d7 --- /dev/null +++ b/_examples/file-server/basic/assets.system/css/main.css @@ -0,0 +1,3 @@ +body { + background-color: black; +} diff --git a/_examples/file-server/basic/assets.system/test.txt b/_examples/file-server/basic/assets.system/test.txt new file mode 100644 index 000000000..1ce52e769 --- /dev/null +++ b/_examples/file-server/basic/assets.system/test.txt @@ -0,0 +1 @@ +main_test.go#TestHandleDirDot \ No newline at end of file diff --git a/_examples/file-server/basic/main_test.go b/_examples/file-server/basic/main_test.go index b565fe4e5..d53b1a687 100644 --- a/_examples/file-server/basic/main_test.go +++ b/_examples/file-server/basic/main_test.go @@ -9,8 +9,6 @@ import ( "github.com/kataras/iris/v12/httptest" ) -const prefixURL = "/v1" - type resource string func (r resource) contentType() string { @@ -37,10 +35,10 @@ func (r resource) strip(strip string) string { return strings.TrimPrefix(s, strip) } -func (r resource) loadFromBase(dir string) string { +func (r resource) loadFromBase(dir string, strip string) string { filename := r.String() - filename = r.strip("/static") + filename = r.strip(strip) if filepath.Ext(filename) == "" { // root /. filename = filename + "/index.html" @@ -60,12 +58,12 @@ func (r resource) loadFromBase(dir string) string { func TestFileServerBasic(t *testing.T) { urls := []resource{ - "/static/css/main.css", - "/static/js/jquery-2.1.1.js", - "/static/favicon.ico", - "/static/app2", - "/static/app2/app2app3", - "/static", + "/v1/static/css/main.css", + "/v1/static/js/jquery-2.1.1.js", + "/v1/static/favicon.ico", + "/v1/static/app2", + "/v1/static/app2/app2app3", + "/v1/static", } app := newApp() @@ -85,9 +83,29 @@ func TestFileServerBasic(t *testing.T) { e := httptest.New(t, app) for _, u := range urls { url := u.String() - contents := u.loadFromBase("./assets") + contents := u.loadFromBase("./assets", "/v1/static") + + e.GET(url).Expect(). + Status(httptest.StatusOK). + ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()). + Body().Equal(contents) + } +} + +// Tests subdomain + request path and system directory with a name that contains a dot(.) +func TestHandleDirDot(t *testing.T) { + urls := []resource{ + "/v1/assets.system/css/main.css", + } + app := newApp() + app.Subdomain("test").Party("/v1").HandleDir("/assets.system", "./assets.system") + + e := httptest.New(t, app, httptest.URL("http://test.example.com")) + for _, u := range urls { + url := u.String() + contents := u.loadFromBase("./assets.system", "/v1/assets.system") - e.GET(prefixURL+url).Expect(). + e.GET(url).Expect(). Status(httptest.StatusOK). ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()). Body().Equal(contents) diff --git a/core/router/fs.go b/core/router/fs.go index 426c74fd7..c9010362d 100644 --- a/core/router/fs.go +++ b/core/router/fs.go @@ -499,8 +499,6 @@ func toWebPath(systemPath string) string { webpath := strings.Replace(systemPath, "\\", "/", -1) // double slashes to single webpath = strings.Replace(webpath, "//", "/", -1) - // remove all dots - webpath = strings.Replace(webpath, ".", "", -1) return webpath } diff --git a/core/router/handler.go b/core/router/handler.go index 0fb0f57eb..ec07ac25c 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -11,7 +11,6 @@ import ( macroHandler "github.com/kataras/iris/v12/macro/handler" "github.com/kataras/golog" - "github.com/kataras/pio" ) // RequestHandler the middle man between acquiring a context and releasing it. @@ -182,6 +181,8 @@ func (h *routerHandler) Build(provider RoutesProvider) error { defer golog.SetTimeFormat(bckpTimeFormat) golog.SetTimeFormat("") + newLine := []byte("\n") + for _, method := range append(AllMethods, MethodNone) { methodRoutes := collect(method) if len(methodRoutes) == 0 { @@ -192,7 +193,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error { r.Trace(golog.Default.Printer) } - golog.Default.Printer.Write(pio.NewLine) + golog.Default.Printer.Write(newLine) } } diff --git a/mvc/controller.go b/mvc/controller.go index 18fcf3203..69ae1d0a8 100644 --- a/mvc/controller.go +++ b/mvc/controller.go @@ -340,6 +340,7 @@ func (c *ControllerActivator) handleMany(method, path, funcName string, override // change the main handler's name and file:line // in order to respect the controller's and give // a proper debug/log message. + r.Description = "controller" r.MainHandlerName = fmt.Sprintf("%s.%s", c.fullName, funcName) if m, ok := c.Type.MethodByName(funcName); ok { r.SourceFileName, r.SourceLineNumber = context.HandlerFileLineRel(m.Func) diff --git a/mvc/grpc.go b/mvc/grpc.go index 6d8bce651..963811e5d 100644 --- a/mvc/grpc.go +++ b/mvc/grpc.go @@ -57,10 +57,12 @@ func (g GRPC) Apply(c *ControllerActivator) { m := c.Type.Method(i) path := path.Join(g.ServiceName, m.Name) if route := c.Handle(http.MethodPost, path, m.Name, pre); route != nil { + bckp := route.Description route.Description = "gRPC" if g.Strict { route.Description += "-only" } + route.Description += " " + bckp // e.g. "gRPC controller" } } }