gonginxvideo-streamingprogressive-download

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


I have a golang webserver which fetches video files from nginx. When I call nginx video directly from <video> html5 tag the video plays smoothly with progressive download. By progressive download I mean the random seek works without any special player logic.

But when I call it through golang webserver which inturn calls nginx link using golang NewSingleHostReverseProxy() class the progressive download does not work.

Is it possible to enable progressive download using golang reverse proxy ?

Code for reverse proxy in golang webserver:

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)
})

Solution

  • I believe you just need to set the FlushInterval to a negative number

    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