【问题标题】:HTTP/2 request, but push not supportHTTP/2 请求,但不支持推送
【发布时间】:2017-11-04 11:26:01
【问题描述】:

我开始使用 go http/2 push,但这些示例对我不起作用。 请求在 http/2 中(我可以在 firefox 中看到“版本:HTTP/2.0”,并且我有一个扩展来判断服务器是否使用 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")
    }
    // ...
})

始终显示“不支持推送”。 有什么提示可以调试吗?

谢谢

【问题讨论】:

  • 如果我忽略断言并尝试推送,我会得到一个 Panic: 2017-06-03_01:05:22.85073 Pushing CSS -------------- ------ 2017-06-03_01:05:22.85087 2017/06/03 01:05:22 http2:恐慌服务 172.18.0.1:43268:运行时错误:无效的内存地址或 nil 指针取消引用 2017-06-03_01 :05:22.85088 goroutine 86 [运行]: 2017-06-03_01:05:22.85088 net/http.(*http2serverConn).runHandler.func1(0xc42000c038, 0xc42015ffaf, 0xc420133880) 2017-06-03_01:/05:2 local/Cellar/go/1.8.3/libexec/src/net/http/h2_bundle.go:4604 +0x190
  • 忽略断言保证不起作用。

标签: go http2


【解决方案1】:

没关系,我找到了,因为我用的是 negroni:https://github.com/urfave/negroni/issues/173

【讨论】:

    猜你喜欢
    • 2012-01-16
    相关资源
    最近更新 更多