From 80c213072ce709394b1e1cfdf57002a9384dcde5 Mon Sep 17 00:00:00 2001 From: CaIon Date: Mon, 23 Feb 2026 16:59:46 +0800 Subject: [PATCH] fix: improve multipart form data handling in gin context - Added caching for the original Content-Type header in the parseMultipartFormData function. - This change ensures that the Content-Type is retrieved from the context if previously set, enhancing performance and consistency. --- common/gin.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/gin.go b/common/gin.go index 009e39080..5cad6e5c9 100644 --- a/common/gin.go +++ b/common/gin.go @@ -303,7 +303,13 @@ func parseFormData(data []byte, v any) error { } func parseMultipartFormData(c *gin.Context, data []byte, v any) error { - contentType := c.Request.Header.Get("Content-Type") + var contentType string + if saved, ok := c.Get("_original_multipart_ct"); ok { + contentType = saved.(string) + } else { + contentType = c.Request.Header.Get("Content-Type") + c.Set("_original_multipart_ct", contentType) + } boundary, err := parseBoundary(contentType) if err != nil { if errors.Is(err, errBoundaryNotFound) {