From 39d91947d9b427e43bc98018c1a28305cf4390c4 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Tue, 26 Jul 2022 23:42:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8E=A5=E6=94=B6formdata?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/web/param/HttpRequestParser.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/param/HttpRequestParser.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/param/HttpRequestParser.java index cb8d718c..122935c0 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/param/HttpRequestParser.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/param/HttpRequestParser.java @@ -21,6 +21,7 @@ */ package fun.asgc.neutrino.core.web.param; +import fun.asgc.neutrino.core.util.ArrayUtil; import fun.asgc.neutrino.core.util.Assert; import fun.asgc.neutrino.core.util.LockUtil; import fun.asgc.neutrino.core.util.StringUtil; @@ -82,8 +83,31 @@ public class HttpRequestParser { this, () -> { queryParamMap = queryStringToMap(queryString); - if ("application/x-www-form-urlencoded".equals(getContentType())) { + String contentType = getContentType(); + if (StringUtil.isEmpty(contentType)) { + return; + } + if (contentType.equals("application/x-www-form-urlencoded")) { queryParamMap.putAll(queryStringToMap(getContentAsString())); + } else if(contentType.startsWith("multipart/form-data;")) { + // TODO 暂时简单处理,只处理纯文本情况 + String boundary = contentType.split(";")[1].split("=")[1]; + String separator = "--" + boundary; + String[] arr = getContentAsString().split(separator); + if (ArrayUtil.notEmpty(arr)) { + for (String item : arr) { + if (StringUtil.isEmpty(item)) { + continue; + } + String[] lines = item.split("\r\n"); + if (lines.length < 4) { + continue; + } + String name = lines[1].split(";")[1].split("=")[1].replaceAll("\\\"", ""); + String value = lines[3]; + queryParamMap.put(name, value); + } + } } }, () -> queryParamMap