0

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)
})
Saurabh Saxena
  • 1,327
  • 2
  • 13
  • 26
  • When seeking to a not already loaded part of the video, your browser should send a request with the [`Range`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range) header. Does your server respond with status code `206` or is it something else? Because if it doesn't the browser will continue the full file download (which means you can't seek). So you might need to find out where the header gets lost (seems like the proxy includes it in requests though) – xarantolus Apr 02 '21 at 06:01

1 Answers1

1

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
dave
  • 62,300
  • 5
  • 72
  • 93