Skip to content

Commit 09e88a3

Browse files
committed
添加 solon-web-servlet-jakarta SolonServletContext:assertMaxBodySize 方法
1 parent 3ab37cf commit 09e88a3

File tree

1 file changed

+20
-8
lines changed
  • solon-jakarta-projects/solon-web/solon-web-servlet-jakarta/src/main/java/org/noear/solon/web/servlet

1 file changed

+20
-8
lines changed

solon-jakarta-projects/solon-web/solon-web-servlet-jakarta/src/main/java/org/noear/solon/web/servlet/SolonServletContext.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ public String body(String charset) throws IOException {
180180

181181
@Override
182182
public InputStream bodyAsStream() throws IOException {
183-
if (_request.getContentLengthLong() > ServerProps.request_maxBodySize) {
184-
//可兼容不同框架的情况
185-
throw new StatusException("Request Entity Too Large: " + _request.getContentLengthLong(), 413);
186-
}
183+
assertMaxBodySize();
187184

188185
return _request.getInputStream();
189186
}
@@ -204,17 +201,22 @@ public MultiMap<String> paramMap() {
204201
*/
205202
private void paramsMapInit() {
206203
if (_paramMap == null) {
207-
_paramMap = new MultiMap<String>();
204+
_paramMap = new MultiMap<>();
208205

209206
try {
210-
//编码窗体预处理
207+
if (isFormUrlencoded()) {
208+
assertMaxBodySize();
209+
}
210+
211+
//x-www-form-urlencoded(for put, delete ..)
211212
DecodeUtils.decodeFormUrlencoded(this);
212213

213-
//多分段处理
214+
//try form-data
214215
if (autoMultipart()) {
215216
loadMultipartFormData();
216217
}
217218

219+
//queryString and x-www-form-urlencoded(for post)
218220
for (Map.Entry<String, String[]> kv : _request.getParameterMap().entrySet()) {
219221
String name = ServerProps.urlDecode(kv.getKey());
220222

@@ -226,6 +228,16 @@ private void paramsMapInit() {
226228
}
227229
}
228230

231+
/**
232+
* @since 3.6
233+
*/
234+
protected void assertMaxBodySize() {
235+
if (_request.getContentLengthLong() > ServerProps.request_maxBodySize) {
236+
//可兼容不同框架的情况
237+
throw new StatusException("Request Entity Too Large: " + _request.getContentLengthLong(), 413);
238+
}
239+
}
240+
229241
@Override
230242
public MultiMap<UploadedFile> fileMap() {
231243
if (isMultipartFormData()) {
@@ -415,7 +427,7 @@ private void sendHeaders() throws IOException {
415427

416428
///////////////////////
417429
// for async
418-
///////////////////////
430+
/// ////////////////////
419431

420432
protected final AsyncContextState asyncState = new AsyncContextState();
421433
private AsyncContext asyncContext;

0 commit comments

Comments
 (0)