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

Resumeable Static Content #471

Closed
aarondl opened this issue Apr 17, 2016 · 3 comments
Closed

Resumeable Static Content #471

aarondl opened this issue Apr 17, 2016 · 3 comments
Assignees
Milestone

Comments

@aarondl
Copy link

aarondl commented Apr 17, 2016

From the documentation at: https://golang.org/pkg/net/http/#ServeContent:

ServeContent replies to the request using the content in the provided ReadSeeker.
The main benefit of ServeContent over io.Copy is that it handles Range requests
properly, sets the MIME type, and handles If-Modified-Since requests.

Echo does not support this functionality.
We can see echo.Context.File() calls context.ServeContent:
https://github.com/labstack/echo/blob/master/context.go#L381
Which does a basic io.Copy() to send the entire file to the user:
https://github.com/labstack/echo/blob/master/context.go#L439

So in the current implementation when you call echo.Context.File there's no chance that anything will be resumed if a download had cut off previously and a browser attempts to resume it using the HTTP Range header which isn't considered by this code. It simply sends the entire file every time.

The documentation surrounding HTTP Range is here: https://tools.ietf.org/html/rfc7233

One more advantage the standard library has over this is that the Content-Size header is also set which is not the case in the echo code.

Ideally we'd be able to completely defer to the standard libraries http.ServeContent method.

@hexadecy
Copy link

hexadecy commented Aug 26, 2016

I'm trying to stream an ogg audio file.
Previously, I was using http.ServeFile and it worked really well.
Please add support or if someone have a quick workaround?

@hexadecy
Copy link

hexadecy commented Aug 26, 2016

It works, but it's ugly:

func GetAudio(rw http.ResponseWriter, req *http.Request) {
   param1 := strings.Split(req.RequestURI, "/")[2]
   http.ServeFile(rw, req, param1)
}

e := echo.New()
e.Group("/media")
func AddMediaRoutes(g *echo.Group) {
   g.Get("/:param1", standard.WrapHandler(http.HandlerFunc(GetAudio)))
}

@vishr vishr self-assigned this Sep 23, 2016
@vishr vishr added this to the v3 milestone Sep 23, 2016
@vishr vishr mentioned this issue Sep 27, 2016
16 tasks
@vishr
Copy link
Member

vishr commented Sep 27, 2016

Tracked in #665

@vishr vishr closed this as completed Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants