-
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
Add callback to UnroutedHandler to remove restriction on upload URIs. #341
Conversation
53dc5b9
to
01d15b6
Compare
01d15b6
to
382abb9
Compare
Interesting approach, thanks for opening this PR. I understand the need for this feature but I disagree with the API design. Instead of the GetID and GetURL functions, I would advocate for this design: DeserializeUploadURL func(url string) (uploadId string, err error)
SerializeUploadURL func(uploadId string) (url string, err error) In particular, I am not a fan of:
What do you think? |
I am ok with whatever name you want, although deserialize is not the best word to use given my response to the next point.
tus does not specify how the ID is transmitted and could be influenced by extra header information (possibly added by a proxy). It is better to provide to the library user the entire request so as to not be unnecessarily restrictive.
URLs should be managed by the appropriate type, only converting to strings when strings are needed. You will see most implementations do something along the lines of u := url.Parse(request.url)
paths := u.Path.split("/")
paths = append(paths, id)
u.Path = paths.join("/")
return u // Why discard information here by converting back to a string? This is more for the sake of the interface, why make it restrictive? I should also add that the current implementation, building urls via string concatenation, needs to be reworked to use the appropriate url.URL type. |
Good points! The names GetID and GetUpload are too broad, so they must be changed to express their purpose more explicitly. A bit different topic: Can you provide an example of what your URLs look like which cannot be used with the current tusd version? |
How about RequestToID and IDToURL or BuildID and BuildURL or MapID and MapURL.
My application lets the end user define the url path hierarchy so I can't provide a real example. Automatically routed based on user credential: A url scheme for concatenated uploads: A 1:1 filesystem to url mapping that handles many many uploads: |
@Acconut Do you mind providing some more feedback on the proposed method names? |
Thanks for reminding me about this PR, @innovate-invent!
I am a fan of descriptive method name and don't shy away from long names if necessary ;) What about ExtractID and GenerateUploadURL?
Thanks for the example. However, in that case wouldn't it be better to add a middleware in front of the tusd handler tor rewrite URL? This has the benefit that you could possibly extract user information etc from the URL. With your proposed configurations, it would not be possible to forward this information to the end application, would it? |
The end user provides the ExtractID and GenerateUploadURL callbacks, giving them full control over the urls. Using middleware could be a solution, although I feel it is a good idea to retain these callbacks. Hardcoded paths (or path schemes) are never a good idea, even if they are internal. I will try and update the function names this weekend. |
Since this PR was opened, a few things have changed which might make this PR not needed anymore:
Combining these changes should allow users to freely modify the upload URL however they like without the need for callback to translate between the URL and upload IDs. Let me know if there is still a need for this. |
@Acconut with the current state of tusd, how can one implement relative upload URLs? It seems like you can change the upload ID in hooks, so one could go EDIT: In fact not even sure that would work correctly, as I believe the storage will also interpret this path and escape the upload directory. |
Fixes #340