gpt4 book ai didi

ssl - 从 Go 服务器发送分块的 HTTPS 响应

转载 作者:IT王子 更新时间:2023-10-29 01:44:00 25 4
gpt4 key购买 nike

下面的示例非常适用于 HTTP:Send a chunked HTTP response from a Go server

添加 TLS 后,我发现响应不再分 block :

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

感谢启蒙

关于ssl - 从 Go 服务器发送分块的 HTTPS 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53258539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com