1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 12:31:58 +00:00

examples: use ctx.ResponseWriter().Naive().(http.Pusher) instead

Former-commit-id: 7802f4eadf2b1c0a0d2a42ed5ebac3e5c77f88cc
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-24 22:36:46 +03:00
parent a4efb222cc
commit 2f8b29cb3d
6 changed files with 18 additions and 82 deletions

View File

@@ -302,18 +302,18 @@ func FileServer(fs http.FileSystem, options DirOptions) context.Handler {
if indexFound && !options.Attachments.Enable {
if indexAssets, ok := options.PushTargets[name]; ok {
if pusher, ok := ctx.ResponseWriter().(http.Pusher); ok {
if pusher, ok := ctx.ResponseWriter().Naive().(http.Pusher); ok {
var pushOpts *http.PushOptions
if encoding != "" {
pushOpts = &http.PushOptions{Header: r.Header}
}
for _, indexAsset := range indexAssets {
if indexAsset[0] != '/' {
// it's relative path.
indexAsset = path.Join(r.RequestURI, indexAsset)
}
var pushOpts *http.PushOptions
if encoding != "" {
pushOpts = &http.PushOptions{Header: r.Header}
}
if err = pusher.Push(indexAsset, pushOpts); err != nil {
break
}
@@ -322,7 +322,12 @@ func FileServer(fs http.FileSystem, options DirOptions) context.Handler {
}
if regex, ok := options.PushTargetsRegexp[r.URL.Path]; ok {
if pusher, ok := ctx.ResponseWriter().(http.Pusher); ok {
if pusher, ok := ctx.ResponseWriter().Naive().(http.Pusher); ok {
var pushOpts *http.PushOptions
if encoding != "" {
pushOpts = &http.PushOptions{Header: r.Header}
}
prefixURL := strings.TrimSuffix(r.RequestURI, name)
names, err := findNames(fs, name)
if err == nil {
@@ -335,10 +340,6 @@ func FileServer(fs http.FileSystem, options DirOptions) context.Handler {
// match using relative path (without the first '/' slash)
// to keep consistency between the `PushTargets` behavior
if regex.MatchString(indexAsset) {
var pushOpts *http.PushOptions
if encoding != "" {
pushOpts = &http.PushOptions{Header: r.Header}
}
// println("Regex Matched: " + indexAsset)
if err = pusher.Push(path.Join(prefixURL, indexAsset), pushOpts); err != nil {