Closed aetos382 closed 3 years ago
This is by design, the quotes are not part of the boundary, they're part of the header formatting and need to be removed before calling this API.
How are you getting the boundary from the request? There are a few helper apis for that.
I understand. If so, I would like a note to that effect to be added to the MultipartReader constructor documentation page.
That content comes from here: https://github.com/dotnet/aspnetcore/blob/81936a792c1ad3d063121061452e8e8f76b170d0/src/Http/WebUtilities/src/MultipartReader.cs#L35-L50 Feel free to send a clarifying PR.
Describe the bug
When using MultipartReader to read a request, the ReadNextSectionAsync method will throw an exception if the
boundary
parameter value in theContent-Type
header is enclosed in double-quotes.This is probably because
MultipartReader
strictly compares the boundary in the request body with the value of theboundary
parameter. Since they do not match, it fails to detect the boundary in the body.If you use the MultipartContent class to construct a multipart request, it will always enclose the
boundary
parameter value in double-quotes. So, theMultipartReader
will not be able to process requests generated byMultipartContent
.RFC 2045 §5.1 specifies that the value of the
boundary
parameter is the same regardless of the enclosing quotation marks.To Reproduce
You can get the reproduction code in this repository.
Exceptions
Workarounds
When creating an instance of
MultipartReader
, remove the double-quotes from the value pass to its constructor'sboundary
parameter, and it will work.For example:
Further technical details
ASP.NET Core version 5.0
Include the output of
dotnet --info
Runtime Environment: OS Name: Windows OS Version: 10.0.21354 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.202\
Host (useful for support): Version: 5.0.5 Commit: 2f740adc14
.NET SDKs installed: 5.0.201 [C:\Program Files\dotnet\sdk] 5.0.202 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download