When downloading a file with HttpClient, I\'m downloading first the headers and then the content. When headers are downloaded, I can see Headers collection on the Content pr
The problem is with the trailing ; in the content-disposition header
[Fact]
public void ParseContentDispositionHeader()
{
var value = ContentDispositionHeaderValue.Parse("attachment; filename=GeoIP2-City_20140107.tar.gz");
Assert.Equal("GeoIP2-City_20140107.tar.gz",value.FileName);
}
If I add the semi-colon the parsing will fail. If you look at the RFC6266 grammar, the semi-colon is only supposed to precede the parameter.
Thank you - finding this definitely helped me. For the benefit of others, here is my workaround (as apparently this is still a thing today???)
I am in a somewhat controlled environment, so the following code assumes:
inline; "filename";
This will reset the response's ContentDisposition header, so subsequent code works seamlessly:
<!-- language: c# -->
if (response.Content.Headers.ContentDisposition == null)
{
IEnumerable<string> contentDisposition;
if (response.Content.Headers.TryGetValues("Content-Disposition", out contentDisposition))
{
response.Content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(contentDisposition.ToArray()[0].TrimEnd(';').Replace("\"",""));
}
}