Open dozed opened 4 years ago
To clarify, there are three types for Content-Disposition:
var contentDispositionHeader = new System.Net.Mime.ContentDisposition()
{
FileName = "foo bar.pdf",
DispositionType = "attachment"
};
string result = contentDispositionHeader.ToString();
var parsed = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(result);
Assert.Equal("foo bar.pdf", parsed.FileName); // Pass
var parsed0 = System.Net.Http.Headers.ContentDispositionHeaderValue.Parse(result);
Assert.Equal("foo bar.pdf", parsed0.FileName); // Fails
Your issue is with the one in System.Net.Http.Headers, which is used by HttpClient. I'm going to transfer this issue to runtime
where HttpClient lives.
Same behavior of System.Net.Http.Headers.ContentDispositionHeaderValue.Parse
on .NET Framework - also returns quoted text.
the current specification says that it should always with quotes
https://tools.ietf.org/html/rfc2616#section-2.2
19.5.1 Content-Disposition -> Content-Disposition: attachment; filename="fname.ext"
I think the goal here is to remove the quotes from the property, not from the header which goes over the wire ...
(Until this issue is fixed) If your server returns filename*
you can rely on the FileNameStar
property, instead of the bugged FileName
.
Example (dotnet Version: 5.0.101, Commit: d05174dc5a):
var response = await httpClient.GetAsync($"files/{id}");
// Response has a header:
// Content-Disposition: attachment; filename="foo bar.pdf"; filename*=UTF-8''foo%20bar.pdf
Console.WriteLine(response.Content.Headers.ContentDisposition.FileName); // "foo bar.pdf"
Console.WriteLine(response.Content.Headers.ContentDisposition.FileNameStar); // foo bar.pdf
When is the bug going to be fixed?
@flibustier7seas no plans yet, there are bugs and features which need our attention more and we didn't get to the medium-upvoted issues yet. That said, we would be happy to take a contribution if anyone is interested.
Describe the bug
When creating a
Content-Disposition
header:response.Content.Headers.ContentDisposition.FileName
contains quotes:Evaluates to:
I would expect that the quotes would be removed.
To Reproduce
Further technical details
dotnet --info