Skip to content
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

DownloadFileAsync => GetFileNameFromPath does not respect redirects #830

Open
dmdymov opened this issue Jul 9, 2024 · 1 comment
Open
Labels

Comments

@dmdymov
Copy link

dmdymov commented Jul 9, 2024

I tried to download a file via Flurl and noticed that file had a gibberish name, but Chrome downloaded the same file with a readable name.

var client = new FlurlClient(baseUrl);
var request = client.Request(link)
    .WithAutoRedirect(true)
    .WithCookie(cookieKey, cookieValue);
var fileName = await request.DownloadFileAsync(".");
// nothing special

After some investigation my suspicion is that DownloadFileAsync (in case of Content-Disposition absence) does not respect redirects and tries to parse file name from the initial request url. But file name can be parsed only from redirected request url in my case and Chrome does exactly that.

I don't know if this behavior is governed by any RFC or something else, so I don't know if it is a bug or not.

Screenshot of the debug values from the breakpoint at DownloadFileAsync:
Screenshot 2024-07-10 002928

Versions

<PackageReference Include="Flurl" Version="4.0.0" />
<PackageReference Include="Flurl.Http" Version="4.0.2" />
@dmdymov dmdymov added the bug label Jul 9, 2024
@tmenier
Copy link
Owner

tmenier commented Jul 22, 2024

Thanks for reporting. The combination of redirect + DownloadFileAsync is probably not well covered by tests so I could see this being a legitimate bug. I'll dig deeper when I have some time, but in the mean time you could probably come up with a reasonable work-around that avoids using DownloadFileAsync directly. That implementation might help as a starting point though:

https://github.com/tmenier/Flurl/blob/dev/src/Flurl.Http/DownloadExtensions.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

No branches or pull requests

2 participants