Skip to content

Commit 230b1c7

Browse files
committed
fix(Core): align multipart headers with browser-standard behavior
Manual override of Content-Disposition to eliminate RFC 5987 FileNameStar parameter. Strictly following RFC 7578 for multipart/form-data as modern parsers like Bun/Zig fail when extended filename* metadata is present. Enforced explicit double-quoting of name and filename parameters. Ensured raw UTF-8 persistence in the standard filename field to mimic User Agent behavior and prevent .NET from fallback MIME encoding (e.g. =?utf-8?B?...?=), which typically results in mangled strings on strict backends. Finally, this fixes uploads for img.fish.
1 parent 5059ac9 commit 230b1c7

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

SnapX.Core/Upload/BaseUploaders/Uploader.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Specialized;
66
using System.Net;
77
using System.Net.Http.Handlers;
8+
using System.Net.Http.Headers;
89
using System.Text;
910
using SnapX.Core.Upload.OAuth;
1011
using SnapX.Core.Upload.Utils;
@@ -161,7 +162,18 @@ protected MultipartFormDataContent GetMultipartFormDataContent(Dictionary<string
161162
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(
162163
mimeType
163164
);
164-
multipartContent.Add(fileContent, fileFormName, fileName);
165+
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
166+
{
167+
Name = $"\"{fileFormName}\"",
168+
FileName = $"\"{fileName}\"",
169+
// @see https://github.com/dotnet/runtime/issues/121484
170+
// This filename*= star violates the RFC and makes Bun parsers upset as they're strict.
171+
// Example: img.fish
172+
FileNameStar = null,
173+
};
174+
// Intent: Ensuring browser-like behavior.
175+
fileContent.Headers.ContentDisposition.Parameters.First(p => p.Name == "filename").Value = $"\"{fileName}\"";
176+
multipartContent.Add(fileContent);
165177
}
166178
return multipartContent;
167179
}

0 commit comments

Comments
 (0)