1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 13:05:56 +00:00

add 'DirOptions.PushTargets' for http/2 push on index(es) - #1562

Former-commit-id: 5a3f626ba0fbcf10be979b5a800eba51e88602cd
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-16 08:03:55 +03:00
parent 38eec57e46
commit fba8492e78
16 changed files with 275 additions and 99 deletions

View File

@@ -44,6 +44,11 @@ type DirOptions struct {
// that another handler, called index handler, is auto-registered by the framework
// if end developer does not managed to handle it by hand.
IndexName string
// PushTargets optionally absolute filenames (map's value) to be served without any
// additional client's requests (HTTP/2 Push)
// when a specific path (map's key) is requested and
// it's not a directory (it's an `IndexFile`).
PushTargets map[string][]string
// When files should served under compression.
Compress bool
@@ -472,6 +477,16 @@ func FileServer(directory string, opts ...DirOptions) context.Handler {
// // ctx.ResponseWriter().Header().Set(context.ContentEncodingHeaderKey, context.GzipHeaderValue)
// }
if indexFound && len(options.PushTargets) > 0 && !options.Attachments.Enable {
if indexAssets, ok := options.PushTargets[name]; ok {
if pusher, ok := ctx.ResponseWriter().(http.Pusher); ok {
for _, indexAsset := range indexAssets {
pusher.Push(indexAsset, nil)
}
}
}
}
// If limit is 0 then same as ServeContent.
ctx.ServeContentWithRate(f, info.Name(), info.ModTime(), options.Attachments.Limit, options.Attachments.Burst)
if serveCode := ctx.GetStatusCode(); context.StatusCodeNotSuccessful(serveCode) {