1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 11:57:02 +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

@@ -4,7 +4,11 @@
// to need for the page theyre requesting.
package main
import "github.com/kataras/iris/v12"
import (
"net/http"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
@@ -22,14 +26,17 @@ func pushHandler(ctx iris.Context) {
// If the target is a path, it will inherit the scheme and host of the
// parent request.
target := "/main.js"
err := ctx.ResponseWriter().Push(target, nil)
if err != nil {
if err == iris.ErrPushNotSupported {
ctx.StopWithText(iris.StatusHTTPVersionNotSupported, "HTTP/2 push not supported.")
} else {
ctx.StopWithError(iris.StatusInternalServerError, err)
if pusher, ok := ctx.ResponseWriter().(http.Pusher); ok {
err := pusher.Push(target, nil)
if err != nil {
if err == iris.ErrPushNotSupported {
ctx.StopWithText(iris.StatusHTTPVersionNotSupported, "HTTP/2 push not supported.")
} else {
ctx.StopWithError(iris.StatusInternalServerError, err)
}
return
}
return
}
ctx.HTML(`<html><body><script src="%s"></script></body></html>`, target)