-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
copyurl: Update copyurl to honor HTTP filename directive #5485
Conversation
b6de3ab
to
9aa9008
Compare
Fixed linux workflow failure and squashed the commits. |
3eb64b6
to
362ebc2
Compare
Fixed some linting issues. |
Is a new flag necessary? Maybe it should always be parsing What do you think?
:-) It looks like a sensible idea to me. I'd be interested to hear what actual use case you have for it. I'll review the code now. |
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.
See inline for code comments :-)
If we decide to drop the flag it will simplify the code considerably!
Thanks for the review:
Through an abundance of caution, I didn't want to tread on any existing behavior, even if that behavior was wrong. I'm happy, however, to aim to emulate a generic browser functionality.
I have to work with a list of temporary web available files, which look like they've been secured with a salted hash, and the filename just isn't in the path, the hash is the final segment. If I don't want to download the files as something like
Many thanks for the review. Apologies for my appauling Go code, its not exactly a language I'm best familiar with. The reason I exported this function is because I wanted to test it on its own, and I was getting complaints when trying to run tests directly calling a non-exported function. I'll take a look at your notes, remove the new flag, check out MIME parsing code, and rework this PR when I get the chance. |
I checked the docs for Reading the curl docs
Made me think that we should probably excercise a little care with the filename The mozilla docs say (emphasis mine)
So I think your flag is a good idea. I think we should also sanitise the filename... I'd do this by converting
Thanks for the explanation.
That is fine - very happy to help newcomers to Go with the syntax!
What you want to do is stick the test in
Great! Give me a ping when you are read for another review. |
|
Unfortunately rclone is short on resources to finish all PRs unfinished by authors. |
1dc8ade
to
e91e681
Compare
Implemented --header-filename for use with copyurl. For specifically setting preferred download filenames for HTTP requests, RFC 6226 specifies a 'filename' directive, available within 'Content-Disposition' header. We can handle with 'mime.ParseMediaType'. See below for details: https://httpwg.org/specs/rfc6266.html#disposition.parameter.filename https://httpwg.org/specs/rfc6266.html#advice.generating Co-authored-by: buengese <buengese@protonmail.com>
e91e681
to
01014d0
Compare
So cleaned up and switched to mime.ParseMediaType. I've kept a separate flag for using the content-disposition header that has to be set in addition to |
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.
Code looks good :-)
Needs a test - luckily there is a framework for them already so it should be easy!
I've added some test now. |
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.
What is the purpose of this change?
Adding
--auto-filename-header
To set preferred download filenames for HTTP requests, RFC 6226
specifies a 'filename' directive, available within 'Content-Disposition'
header, and suggests both token and quoted string syntaxes should be allowable
for the filename directive. i.e.: either
filename=name.txt
orfilename="name.txt"
should be acceptable.See below for details:
https://httpwg.org/specs/rfc6266.html#disposition.parameter.filename
https://httpwg.org/specs/rfc6266.html#advice.generating
--auto-filename-header
is designed to work in conjunction with--auto-filename
, honoring the filename directive when retrieving files from a server.Directives contained within the
Content-Disposition
header are semicolon delimited, and can vary in length and order. Consideration had to be given to parsing entries likeinline; filename="file.txt";
as well as the more straightforward examples above.Was the change discussed in an issue or in the forum before?
I raised it on the forum, got no response, and thought it was an clear enough issue to tackle myself without altering existing functionality. Maybe that was good enough. If not, maybe a rogue PR is enough to get a response. 😉
https://forum.rclone.org/t/copyurl-auto-filename-could-be-cleverer-and-respect-the-http-content-disposition-optional-directive-filename/25553
Checklist