Add support for Range HTTP Header and 206 partial content response.#29
Add support for Range HTTP Header and 206 partial content response.#29jwmay2012 wants to merge 2 commits intodaichirata:masterfrom
Range HTTP Header and 206 partial content response.#29Conversation
|
@jwmay2012 thanks so much for this PR, I have run into the same issue. It would be amazing to get this merged, but in the meantime, if I may ask, have you been using this implementation? Any recommendations or input if others were to use it? |
|
@ravwojdyla we have been using it in non-prod with the intent to use in prod. Haven't run into any issues or complications. No special deployment considerations as well. 🙂 |
|
@daichirata could this be merged? |
|
This would be fantastic functionality to have merged. |
|
Thank you all for the comments. The reason I’ve been hesitant to merge this PR is that I wasn’t fully confident that copying the entire range implementation into this repository and using it was the right approach. If possible, I’d prefer to address this issue without copying code, so I’m going to take another look and see whether there’s a better solution. |
What and Why?
To support
RangeHTTP header and206 partial contentresponses.This is most useful for streaming large files like videos without blocking page loads.
Previous behavior
Before this PR, a frontend would make multiple
Rangerequests expecting partials but resulting in the entire file being downloaded multiple times, all while blocking page load completion.New behavior
After this PR, the large file gets loaded progressively, as needed by the page, and the
Rangerequests gets a206response until the content is completed.Implementation details
I yanked and adapted the code from
http.ServeContent(). It would be preferable to usehttp.ServeContent()directly, butServeContentexpects aReadSeeker.Might be worth it to create an adapter.
ServeContentusesReadSeekerto determine file size and to verify if ranges become out of bounds. However, there's no default code that communicates how many bytes are intended to be read for the current partial content, meaning we'd always have to callobjHandler.NewRangeReader(context.Background(), ra.start, attrs.Size)which I suspect pulls the full object from the bucket.The ServeContent function I pulled from has it's own error response handling which now usurps your
handleError(). I left it in, but we can modify it to be consistent.Thanks for the cool project. We're finding it super useful. :)