golang中如何实现反向代理支持nginx渐进式下载?

How to implement reverse proxy in golang to support nginx progressive download?

我有一个 golang 网络服务器,它从 nginx 获取视频文件。 当我直接从 <video> html5 标记调用 nginx 视频时,视频播放流畅,渐进式下载。通过渐进式下载,我的意思是随机搜索在没有任何特殊播放器逻辑的情况下工作。

但是当我通过 golang 网络服务器调用它时,它又调用 nginx link 使用 golang NewSingleHostReverseProxy() class 渐进式下载不起作用。

是否可以使用 golang 反向代理启用渐进式下载?

golang 网络服务器中的反向代理代码:

url, _ := url.Parse("http://nginx-server/")
proxy := httputil.NewSingleHostReverseProxy(url)
router.PathPrefix("/video").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        proxy.ServeHTTP(w, r)
})

我相信您只需要将 FlushInterval 设置为负数即可

FlushInterval specifies the flush interval to flush to the client while copying the response body. If zero, no periodic flushing is done. A negative value means to flush immediately after each write to the client. The FlushInterval is ignored when ReverseProxy recognizes a response as a streaming response, or if its ContentLength is -1; for such responses, writes are flushed to the client immediately.

proxy := httputil.NewSingleHostReverseProxy(url)
proxy.FlushInterval = -1