Skip to content

Commit

Permalink
feat: setup http2 push
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 20, 2019
1 parent 0e3179f commit d9a8b3a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion views/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var box = packr.NewBox("../templates")

func setDefaultHeaders(w http.ResponseWriter) {
// push(w, "/static/xxx.css")
push(w, "/css/calc.css")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
}

Expand All @@ -37,3 +37,13 @@ func render(w http.ResponseWriter, r *http.Request, tplPath string, data interfa
}
w.Write(buf.Bytes())
}

func push(w http.ResponseWriter, resource string) {
pusher, ok := w.(http.Pusher)
if ok {
if err := pusher.Push(resource, nil); err == nil {
zap.L().Warn("failed to push resource", zap.String("path", resource), zap.Error(err))
return
}
}
}

0 comments on commit d9a8b3a

Please sign in to comment.