2017-06-03 107 views
0

我開始玩去http/2推,並且這些例子不適合我。 請求是在http/2中(我可以在firefox中看到「Version:HTTP/2.0」,並且我有一個擴展來告訴服務器是否使用http/2)。 然而,這樣的:HTTP/2請求,但推不支持

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) 
     } 
    } else { 
     fmt.Println("Push not supported") 
    } 
    // ... 
}) 

始終顯示 「推不支持」。 任何提示調試?

感謝

+0

如果我忽略斷言,並嘗試反正推,我得到一個恐慌:2017-06-03_01: 05:22.85073推送CSS -------------------- 2017-06-03_01:05:22.85087 2017/06/03 01:05:22 http2:恐慌服務172.18 .0.1:43268:運行時錯誤:無效的內存地址或零指針解除引用 2017-06-03_01:05:22.85088 goroutine 86 [running]: 2017-06-03_01:05:22.85088 net/http。(* http2serverConn)。 runHandler.func1(0xc42000c038,0xc42015ffaf,0xc420133880) 2017-0 6-03_01:05:22.85090 /usr/local/Cellar/go/1.8.3/libexec/src/net/http/h2_bundle.go:4604 + 0x190 – Gravis

+0

忽略斷言保證不起作用。 – Adrian

回答