mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
add vscode extension link and badge | Some internal improvements (not completed yet)
Former-commit-id: 9bc94e90a2780ee81f8188509d98063fb3f2924b
This commit is contained in:
@@ -629,7 +629,6 @@ func (api *APIBuilder) Favicon(favPath string, requestPath ...string) *Route {
|
||||
return api.Favicon(path.Join(favPath, "favicon.ico"))
|
||||
}
|
||||
|
||||
cType := TypeByFilename(favPath)
|
||||
// copy the bytes here in order to cache and not read the ico on each request.
|
||||
cacheFav := make([]byte, fi.Size())
|
||||
if _, err = f.Read(cacheFav); err != nil {
|
||||
@@ -641,25 +640,14 @@ func (api *APIBuilder) Favicon(favPath string, requestPath ...string) *Route {
|
||||
Format(favPath, "favicon: couldn't read the data bytes for file: "+err.Error()))
|
||||
return nil
|
||||
}
|
||||
modtime := ""
|
||||
|
||||
modtime := time.Now()
|
||||
cType := TypeByFilename(favPath)
|
||||
h := func(ctx context.Context) {
|
||||
if modtime == "" {
|
||||
modtime = fi.ModTime().UTC().Format(ctx.Application().ConfigurationReadOnly().GetTimeFormat())
|
||||
}
|
||||
if t, err := time.Parse(ctx.Application().ConfigurationReadOnly().GetTimeFormat(), ctx.GetHeader(ifModifiedSinceHeaderKey)); err == nil && fi.ModTime().Before(t.Add(StaticCacheDuration)) {
|
||||
|
||||
ctx.ResponseWriter().Header().Del(contentTypeHeaderKey)
|
||||
ctx.ResponseWriter().Header().Del(contentLengthHeaderKey)
|
||||
ctx.StatusCode(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.ResponseWriter().Header().Set(contentTypeHeaderKey, cType)
|
||||
ctx.ResponseWriter().Header().Set(lastModifiedHeaderKey, modtime)
|
||||
ctx.StatusCode(http.StatusOK)
|
||||
if _, err := ctx.Write(cacheFav); err != nil {
|
||||
// ctx.Application().Logger().Infof("error while trying to serve the favicon: %s", err.Error())
|
||||
ctx.ContentType(cType)
|
||||
if _, err := ctx.WriteWithExpiration(cacheFav, modtime); err != nil {
|
||||
ctx.StatusCode(http.StatusInternalServerError)
|
||||
ctx.Application().Logger().Debugf("while trying to serve the favicon: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,16 +686,16 @@ func (api *APIBuilder) StaticWeb(requestPath string, systemPath string) *Route {
|
||||
|
||||
handler := func(ctx context.Context) {
|
||||
h(ctx)
|
||||
if ctx.GetStatusCode() >= 200 && ctx.GetStatusCode() < 400 {
|
||||
// re-check the content type here for any case,
|
||||
// although the new code does it automatically but it's good to have it here.
|
||||
if _, exists := ctx.ResponseWriter().Header()["Content-Type"]; !exists {
|
||||
if fname := ctx.Params().Get(paramName); fname != "" {
|
||||
cType := TypeByFilename(fname)
|
||||
ctx.ContentType(cType)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if ctx.GetStatusCode() >= 200 && ctx.GetStatusCode() < 400 {
|
||||
// // re-check the content type here for any case,
|
||||
// // although the new code does it automatically but it's good to have it here.
|
||||
// if _, exists := ctx.ResponseWriter().Header()["Content-Type"]; !exists {
|
||||
// if fname := ctx.Params().Get(paramName); fname != "" {
|
||||
// cType := TypeByFilename(fname)
|
||||
// ctx.ContentType(cType)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
requestPath = joinPath(requestPath, WildcardParam(paramName))
|
||||
@@ -791,16 +779,20 @@ func (api *APIBuilder) FireErrorCode(ctx context.Context) {
|
||||
api.errorCodeHandlers.Fire(ctx)
|
||||
}
|
||||
|
||||
// Layout oerrides the parent template layout with a more specific layout for this Party
|
||||
// returns this Party, to continue as normal
|
||||
// Layout overrides the parent template layout with a more specific layout for this Party.
|
||||
// It returns the current Party.
|
||||
//
|
||||
// The "tmplLayoutFile" should be a relative path to the templates dir.
|
||||
// Usage:
|
||||
//
|
||||
// app := iris.New()
|
||||
// app.RegisterView(iris.$VIEW_ENGINE("./views", ".$extension"))
|
||||
// my := app.Party("/my").Layout("layouts/mylayout.html")
|
||||
// {
|
||||
// my.Get("/", func(ctx context.Context) {
|
||||
// ctx.MustRender("page1.html", nil)
|
||||
// })
|
||||
// }
|
||||
// my.Get("/", func(ctx iris.Context) {
|
||||
// ctx.View("page1.html")
|
||||
// })
|
||||
//
|
||||
// Examples: https://github.com/kataras/iris/tree/master/_examples/view
|
||||
func (api *APIBuilder) Layout(tmplLayoutFile string) Party {
|
||||
api.Use(func(ctx context.Context) {
|
||||
ctx.ViewLayout(tmplLayoutFile)
|
||||
@@ -811,14 +803,14 @@ func (api *APIBuilder) Layout(tmplLayoutFile string) Party {
|
||||
}
|
||||
|
||||
// joinHandlers uses to create a copy of all Handlers and return them in order to use inside the node
|
||||
func joinHandlers(Handlers1 context.Handlers, Handlers2 context.Handlers) context.Handlers {
|
||||
nowLen := len(Handlers1)
|
||||
totalLen := nowLen + len(Handlers2)
|
||||
// create a new slice of Handlers in order to store all handlers, the already handlers(Handlers) and the new
|
||||
func joinHandlers(h1 context.Handlers, h2 context.Handlers) context.Handlers {
|
||||
nowLen := len(h1)
|
||||
totalLen := nowLen + len(h2)
|
||||
// create a new slice of Handlers in order to merge the "h1" and "h2"
|
||||
newHandlers := make(context.Handlers, totalLen)
|
||||
//copy the already Handlers to the just created
|
||||
copy(newHandlers, Handlers1)
|
||||
//start from there we finish, and store the new Handlers too
|
||||
copy(newHandlers[nowLen:], Handlers2)
|
||||
// copy the already Handlers to the just created
|
||||
copy(newHandlers, h1)
|
||||
// start from there we finish, and store the new Handlers too
|
||||
copy(newHandlers[nowLen:], h2)
|
||||
return newHandlers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user