Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: net/http: ServeContentStream #14896
I recently found myself in a situation where I had an
I think my situation probably isn't that uncommon - any time you're serving data from an underlying store or database which supports streaming data off disk, but doesn't let you seek around in it, and you want to serve that over HTTP with
The implementation should be pretty simple.
Note that the bits that require
Obviously, I'd be happy to put in the work myself to make this change! Just filing an issue first since that's what the docs say to do. =)
I think ServeContent already had too many parameters and I wouldn't have done the ReadSeeker thing again in retrospect. I don't want to repeat those mistakes with even more parameters.
I'd prefer something like:
// ConditionalHandler wraps returns an http.Handler wrapping h which // adds support for HTTP conditional requests as defined by RFC 7232. // The returned handler answers If-Modified-Since and If-None-Match // queries using the headers set on the response to HEAD requests against h. func ConditionalHandler(h http.Handler) http.Handler
Trying to fit that problem into the existing API, I'd suggest creating a function that turns any io.Reader with a
@colinmarc are you saying these DB streaming APIs and such allow you to start streaming from an arbitrary offset, but that same stream is then unseekable? If so, you can provide a ReadSeeker that doesn't actually "open" the stream until the first Read occurs (in which case you just open it from wherever the offset happens to be). AFAIK, ServeContent does not seek into the middle of the ReadSeeker more than once.
If the answer is "no, the database may only stream from the beginning", then
I'm also worried about this part:
I don't think that's something we want to be doing automatically for people. If you don't have a ReadSeeker, we shouldn't be transparently reading potentially gigabytes of data to get to your Range seek position.