mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
add 'DirOptions.PushTargets' for http/2 push on index(es) - #1562
Former-commit-id: 5a3f626ba0fbcf10be979b5a800eba51e88602cd
This commit is contained in:
35
_examples/file-server/http2push/main.go
Normal file
35
_examples/file-server/http2push/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
var opts = iris.DirOptions{
|
||||
IndexName: "/index.html",
|
||||
// Optionally register files (map's absolute values) to be served
|
||||
// when a specific path (map's key WITHOUT prefix) is requested
|
||||
// is fired before client asks (HTTP/2 Push).
|
||||
// E.g. "/" (which serves the `IndexName` if not empty).
|
||||
//
|
||||
// Note: Requires running server under TLS,
|
||||
// that's why we use ListenAndServeTLS below.
|
||||
PushTargets: map[string][]string{
|
||||
"/": {
|
||||
"/public/favicon.ico",
|
||||
"/public/js/main.js",
|
||||
"/public/css/main.css",
|
||||
},
|
||||
},
|
||||
Compress: true,
|
||||
ShowList: true,
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.HandleDir("/public", "./assets", opts)
|
||||
|
||||
// Open your browser's Network tools,
|
||||
// navigate to https://127.0.0.1/public.
|
||||
// you should see `Initiator` tab: "Push / public".
|
||||
app.Run(iris.TLS(":443", "mycert.crt", "mykey.key"))
|
||||
}
|
||||
Reference in New Issue
Block a user