ssl - 从 Go 服务器发送分块的 HTTPS 响应
问题描述
以下示例非常适用于HTTP:从 Go 服务器发送分块的 HTTP 响应
添加 TLS 后,我看到响应不再分块:
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
flusher, ok := w.(http.Flusher)
if !ok {
panic("expected http.ResponseWriter to be an http.Flusher")
}
w.Header().Set("X-Content-Type-Options", "nosniff")
for i := 1; i <= 10; i++ {
fmt.Fprintf(w, "Chunk #%d\n", i)
flusher.Flush() // Trigger "chunked" encoding and send a chunk...
time.Sleep(500 * time.Millisecond)
}
})
log.Print("Listening on localhost:8080")
log.Fatal(http.ListenAndServeTLS(":8080", "<CERT_FILE>", "<KEY_FILE>", nil))
}
任何想法为什么会这样?
解决方案
log.Infof("Protocol Version: %s", request.Proto)
确认其使用 HTTP/2.0
谢谢 Vorsprung
推荐阅读
- docker - 在 Kubernetes 中部署无 bluespice
- sql-server - SQLServer2019-SSEI-Dev.exe 的安装失败并显示“无法下载所需的文件。不再支持安装程序的版本”
- combinatorics - 在 Sage 中生成给定 groundset 上的所有拟阵
- javascript - 如何在 Js 中进行大量输出的计算?
- redis - Redis 中的生产者和多个消费者问题
- solr - solr 8.4.1 中的 Solr 连接查询问题
- c# - Azure devops API - 获取两个分支之间的差异
- mongodb - 是否可以将 MongoDB 社区连接到 PowerBI?
- html - 移动模式我没有获得带有关闭按钮的全宽菜单
- python - 如何根据元素的值拆分列表