aboutsummaryrefslogtreecommitdiff
path: root/content/h2push/pusher.go
diff options
context:
space:
mode:
Diffstat (limited to 'content/h2push/pusher.go')
-rw-r--r--content/h2push/pusher.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/content/h2push/pusher.go b/content/h2push/pusher.go
new file mode 100644
index 0000000..366328c
--- /dev/null
+++ b/content/h2push/pusher.go
@@ -0,0 +1,39 @@
+// +build OMIT
+
+package main
+
+import (
+ "log"
+ "net/http"
+)
+
+func main() {
+ // START OMIT
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ if pusher, ok := w.(http.Pusher); ok {
+ // Push is supported.
+ if err := pusher.Push("/app.js", nil); err != nil {
+ log.Printf("Failed to push: %v", err)
+ }
+ }
+ // ...
+ })
+ // END OMIT
+
+ // START1 OMIT
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ if pusher, ok := w.(http.Pusher); ok {
+ // Push is supported.
+ options := &http.PushOptions{
+ Header: http.Header{
+ "Accept-Encoding": r.Header["Accept-Encoding"],
+ },
+ }
+ if err := pusher.Push("/app.js", options); err != nil {
+ log.Printf("Failed to push: %v", err)
+ }
+ }
+ // ...
+ })
+ // END1 OMIT
+}