mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Former-commit-id: 2b5ae1857a5815977507b6b8fc72dd0040d470ca
This commit is contained in:
parent
ac08f53ba0
commit
714e84b597
3
_examples/file-server/basic/assets.system/css/main.css
Normal file
3
_examples/file-server/basic/assets.system/css/main.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
}
|
1
_examples/file-server/basic/assets.system/test.txt
Normal file
1
_examples/file-server/basic/assets.system/test.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
main_test.go#TestHandleDirDot
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"github.com/kataras/iris/v12/httptest"
|
"github.com/kataras/iris/v12/httptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const prefixURL = "/v1"
|
|
||||||
|
|
||||||
type resource string
|
type resource string
|
||||||
|
|
||||||
func (r resource) contentType() string {
|
func (r resource) contentType() string {
|
||||||
|
@ -37,10 +35,10 @@ func (r resource) strip(strip string) string {
|
||||||
return strings.TrimPrefix(s, strip)
|
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.String()
|
||||||
|
|
||||||
filename = r.strip("/static")
|
filename = r.strip(strip)
|
||||||
if filepath.Ext(filename) == "" {
|
if filepath.Ext(filename) == "" {
|
||||||
// root /.
|
// root /.
|
||||||
filename = filename + "/index.html"
|
filename = filename + "/index.html"
|
||||||
|
@ -60,12 +58,12 @@ func (r resource) loadFromBase(dir string) string {
|
||||||
|
|
||||||
func TestFileServerBasic(t *testing.T) {
|
func TestFileServerBasic(t *testing.T) {
|
||||||
urls := []resource{
|
urls := []resource{
|
||||||
"/static/css/main.css",
|
"/v1/static/css/main.css",
|
||||||
"/static/js/jquery-2.1.1.js",
|
"/v1/static/js/jquery-2.1.1.js",
|
||||||
"/static/favicon.ico",
|
"/v1/static/favicon.ico",
|
||||||
"/static/app2",
|
"/v1/static/app2",
|
||||||
"/static/app2/app2app3",
|
"/v1/static/app2/app2app3",
|
||||||
"/static",
|
"/v1/static",
|
||||||
}
|
}
|
||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
@ -85,9 +83,29 @@ func TestFileServerBasic(t *testing.T) {
|
||||||
e := httptest.New(t, app)
|
e := httptest.New(t, app)
|
||||||
for _, u := range urls {
|
for _, u := range urls {
|
||||||
url := u.String()
|
url := u.String()
|
||||||
contents := u.loadFromBase("./assets")
|
contents := u.loadFromBase("./assets", "/v1/static")
|
||||||
|
|
||||||
e.GET(prefixURL+url).Expect().
|
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(url).Expect().
|
||||||
Status(httptest.StatusOK).
|
Status(httptest.StatusOK).
|
||||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||||
Body().Equal(contents)
|
Body().Equal(contents)
|
||||||
|
|
|
@ -499,8 +499,6 @@ func toWebPath(systemPath string) string {
|
||||||
webpath := strings.Replace(systemPath, "\\", "/", -1)
|
webpath := strings.Replace(systemPath, "\\", "/", -1)
|
||||||
// double slashes to single
|
// double slashes to single
|
||||||
webpath = strings.Replace(webpath, "//", "/", -1)
|
webpath = strings.Replace(webpath, "//", "/", -1)
|
||||||
// remove all dots
|
|
||||||
webpath = strings.Replace(webpath, ".", "", -1)
|
|
||||||
return webpath
|
return webpath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
macroHandler "github.com/kataras/iris/v12/macro/handler"
|
macroHandler "github.com/kataras/iris/v12/macro/handler"
|
||||||
|
|
||||||
"github.com/kataras/golog"
|
"github.com/kataras/golog"
|
||||||
"github.com/kataras/pio"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RequestHandler the middle man between acquiring a context and releasing it.
|
// 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)
|
defer golog.SetTimeFormat(bckpTimeFormat)
|
||||||
golog.SetTimeFormat("")
|
golog.SetTimeFormat("")
|
||||||
|
|
||||||
|
newLine := []byte("\n")
|
||||||
|
|
||||||
for _, method := range append(AllMethods, MethodNone) {
|
for _, method := range append(AllMethods, MethodNone) {
|
||||||
methodRoutes := collect(method)
|
methodRoutes := collect(method)
|
||||||
if len(methodRoutes) == 0 {
|
if len(methodRoutes) == 0 {
|
||||||
|
@ -192,7 +193,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
|
||||||
r.Trace(golog.Default.Printer)
|
r.Trace(golog.Default.Printer)
|
||||||
}
|
}
|
||||||
|
|
||||||
golog.Default.Printer.Write(pio.NewLine)
|
golog.Default.Printer.Write(newLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,6 +340,7 @@ func (c *ControllerActivator) handleMany(method, path, funcName string, override
|
||||||
// change the main handler's name and file:line
|
// change the main handler's name and file:line
|
||||||
// in order to respect the controller's and give
|
// in order to respect the controller's and give
|
||||||
// a proper debug/log message.
|
// a proper debug/log message.
|
||||||
|
r.Description = "controller"
|
||||||
r.MainHandlerName = fmt.Sprintf("%s.%s", c.fullName, funcName)
|
r.MainHandlerName = fmt.Sprintf("%s.%s", c.fullName, funcName)
|
||||||
if m, ok := c.Type.MethodByName(funcName); ok {
|
if m, ok := c.Type.MethodByName(funcName); ok {
|
||||||
r.SourceFileName, r.SourceLineNumber = context.HandlerFileLineRel(m.Func)
|
r.SourceFileName, r.SourceLineNumber = context.HandlerFileLineRel(m.Func)
|
||||||
|
|
|
@ -57,10 +57,12 @@ func (g GRPC) Apply(c *ControllerActivator) {
|
||||||
m := c.Type.Method(i)
|
m := c.Type.Method(i)
|
||||||
path := path.Join(g.ServiceName, m.Name)
|
path := path.Join(g.ServiceName, m.Name)
|
||||||
if route := c.Handle(http.MethodPost, path, m.Name, pre); route != nil {
|
if route := c.Handle(http.MethodPost, path, m.Name, pre); route != nil {
|
||||||
|
bckp := route.Description
|
||||||
route.Description = "gRPC"
|
route.Description = "gRPC"
|
||||||
if g.Strict {
|
if g.Strict {
|
||||||
route.Description += "-only"
|
route.Description += "-only"
|
||||||
}
|
}
|
||||||
|
route.Description += " " + bckp // e.g. "gRPC controller"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user