Skip to content

Commit

Permalink
apply #1500
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Apr 29, 2020
1 parent b939405 commit 4feda40
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
3 changes: 3 additions & 0 deletions _examples/file-server/basic/assets.system/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: black;
}
1 change: 1 addition & 0 deletions _examples/file-server/basic/assets.system/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main_test.go#TestHandleDirDot
42 changes: 30 additions & 12 deletions _examples/file-server/basic/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/kataras/iris/v12/httptest"
)

const prefixURL = "/v1"

type resource string

func (r resource) contentType() string {
Expand All @@ -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"
Expand All @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions core/router/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions core/router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions mvc/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions mvc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 4feda40

Please sign in to comment.