-
Notifications
You must be signed in to change notification settings - Fork 487
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
handler: support range requests for GET /upload #1048
Conversation
Thank you for this PR! Do you know which stores return an |
From a cursory look that appears to be the case - though I imagine that in theory we could wrap e.g. s3store with a ReadSeeker that uses range requests. For now though this would only work for the file store, the Range header would be ignored for all the others. |
@@ -646,6 +646,7 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) | |||
} else { | |||
resp.Header["Upload-Length"] = strconv.FormatInt(info.Size, 10) | |||
resp.Header["Content-Length"] = strconv.FormatInt(info.Size, 10) | |||
resp.Header["Accept-Ranges"] = "bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to check if the underlying store returns a ReadSeeker before advertising this
Yes, that would be possible, but likely not very efficient. From briefly looking through the code behind A better approach would be to pass the range request directly to the datastore, so it can fetch the requested range from the underlying storage provider. In tusd, we enabled storages to implement such optional features through additional interfaces. For example, a storage can implement the Lines 121 to 132 in e278419
We could define a similar interface for fetching ranges. For the s3store, the implementation would then send a range request to S3. For the filestore, it could just seek to the desired position and read from there. The handler can then also detect whether the storage supports range requests at all and set the This approach would require more effort to get it working for your use case, but also allows this feature to be provided by other storages in the future. Maybe the interface could even be extended to also allow handling the What do you think? |
I like that approach - it's a lot more effort, but it'd mean that we can extend the support to the other stores (I didn't realise that that's how ServeContent operates...). Out of interest, I did some searching and found #432 where you were against implementing In any case, we should probably move this conversation to an issue to sketch out API design if you're in favour of this in principle - closing this PR for now. |
Yes, I did change my opinion here. We have recently been involved in the HTTP working group with the goal of making a IETF standard for resumable uploads. In the end, we hope that resumable uploads are one component in the HTTP toolbox that interacts well with the existing HTTP mechanism. Since then I am more interested in making sure that tusd works better with concepts, such as range requests.
Great idea, feel free to open an issue if you are still interested in working on this :) |
Where the store supports it, use
http.ServeContent
to serve the contents of the upload, thereby adding support for range requests:This helps optimise downloading large files directly from tusd.