aboutsummaryrefslogtreecommitdiff
path: root/content/h2push/pusher.go
blob: 366328cf837687a97f9a7b7c0327f4a09dfa76ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
}