|
52 | 52 | import io.netty.handler.codec.http.QueryStringDecoder; |
53 | 53 | import io.netty.handler.codec.http.cookie.Cookie; |
54 | 54 | import io.netty.handler.codec.http.cookie.ServerCookieDecoder; |
| 55 | +import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory; |
55 | 56 | import io.netty.handler.codec.http.multipart.FileUpload; |
56 | 57 | import io.netty.handler.codec.http.multipart.HttpData; |
57 | 58 | import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder; |
@@ -244,26 +245,35 @@ private Multimap<String, String> decodeParams() throws IOException { |
244 | 245 | || contentType.startsWith(MediaType.form.name())); |
245 | 246 | } |
246 | 247 | if (hasBody && formLike) { |
247 | | - HttpPostRequestDecoder form = new HttpPostRequestDecoder(req); |
248 | | - Function<HttpPostRequestDecoder, Boolean> hasNext = it -> { |
249 | | - try { |
250 | | - return it.hasNext(); |
251 | | - } catch (HttpPostRequestDecoder.EndOfDataDecoderException ex) { |
252 | | - return false; |
253 | | - } |
254 | | - }; |
255 | | - while (hasNext.apply(form)) { |
256 | | - HttpData field = (HttpData) form.next(); |
257 | | - String name = field.getName(); |
258 | | - switch (field.getHttpDataType()) { |
259 | | - case FileUpload: |
260 | | - files.put(name, new NettyUpload((FileUpload) field, tmpdir)); |
261 | | - // excludes upload from param names. |
262 | | - break; |
263 | | - default: |
264 | | - params.put(name, field.getString()); |
265 | | - break; |
| 248 | + HttpPostRequestDecoder decoder = new HttpPostRequestDecoder( |
| 249 | + new DefaultHttpDataFactory(), req); |
| 250 | + try { |
| 251 | + Function<HttpPostRequestDecoder, Boolean> hasNext = it -> { |
| 252 | + try { |
| 253 | + return it.hasNext(); |
| 254 | + } catch (HttpPostRequestDecoder.EndOfDataDecoderException ex) { |
| 255 | + return false; |
| 256 | + } |
| 257 | + }; |
| 258 | + while (hasNext.apply(decoder)) { |
| 259 | + HttpData field = (HttpData) decoder.next(); |
| 260 | + try { |
| 261 | + String name = field.getName(); |
| 262 | + switch (field.getHttpDataType()) { |
| 263 | + case FileUpload: |
| 264 | + files.put(name, new NettyUpload((FileUpload) field, tmpdir)); |
| 265 | + // excludes upload from param names. |
| 266 | + break; |
| 267 | + default: |
| 268 | + params.put(name, field.getString()); |
| 269 | + break; |
| 270 | + } |
| 271 | + } finally { |
| 272 | + field.release(); |
| 273 | + } |
266 | 274 | } |
| 275 | + } finally { |
| 276 | + decoder.destroy(); |
267 | 277 | } |
268 | 278 | } |
269 | 279 | } |
|
0 commit comments