Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: ServeContent should support dynamic files/Chunked transfer #20063

themihai opened this issue Apr 21, 2017 · 1 comment

net/http: ServeContent should support dynamic files/Chunked transfer #20063

themihai opened this issue Apr 21, 2017 · 1 comment


Copy link

@themihai themihai commented Apr 21, 2017

What version of Go are you using (go version)?

go version go1.8 darwin/amd64

What did you do?

I've tried to transcode and serve/stream a video file in the same time. Below is some pseudo code.

      go func(){
            // convert the video file in a format supported by the browser
            transcode(fromFilePath, toFilePath)
        // serve the content while transcoding takes place. 
        f, _ := os.OpenFile(toFilePath, os.O_RDONLY, 0666)
	http.ServeContent(w, r, toFilePath, time.Now(), f)

What did you expect to see?

Serve the file in chunks as the file grows/is transcoded.

What did you see instead?

ServeContent writes several headers such Content-Length even we don't know the length of the file when transcoding is complete and serves/writes only the content already transcoded at the time the request is made is served.

The solution could be to use Chunked transfer encoding .

Copy link

@bradfitz bradfitz commented Apr 21, 2017

We support Chunked encoding already.

ServeContent assumes the file is not actively growing.

If it's actively growing, just set the headers and stream the content to the ResponseWriter. It works.

For questions about Go, see

@bradfitz bradfitz closed this Apr 21, 2017
@golang golang locked and limited conversation to collaborators Apr 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.