|
27 | 27 | import com.blade.server.netty.HttpConst; |
28 | 28 | import com.blade.server.netty.HttpServerHandler; |
29 | 29 | import io.netty.buffer.ByteBuf; |
30 | | -import io.netty.buffer.ByteBufAllocator; |
31 | | -import io.netty.buffer.CompositeByteBuf; |
32 | 30 | import io.netty.buffer.Unpooled; |
33 | 31 | import io.netty.handler.codec.http.*; |
34 | 32 | import io.netty.handler.codec.http.cookie.ServerCookieDecoder; |
|
56 | 54 | @NoArgsConstructor |
57 | 55 | public class HttpRequest implements Request { |
58 | 56 |
|
59 | | - private static final HttpDataFactory factory = |
60 | | - new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); // Disk if size exceed |
| 57 | + private static final HttpDataFactory HTTP_DATA_FACTORY = |
| 58 | + new DefaultHttpDataFactory(true); // Disk if size exceed |
61 | 59 |
|
62 | 60 | private static final ByteBuf EMPTY_BUF = Unpooled.copiedBuffer("", CharsetUtil.UTF_8); |
63 | 61 |
|
@@ -348,22 +346,22 @@ public void init(String remoteAddress) { |
348 | 346 | } |
349 | 347 |
|
350 | 348 | try { |
351 | | - HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(factory, nettyRequest); |
| 349 | + HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(HTTP_DATA_FACTORY, nettyRequest); |
352 | 350 | this.isMultipart = decoder.isMultipart(); |
353 | 351 |
|
354 | | - List<ByteBuf> byteBufs = new ArrayList<>(this.contents.size()); |
| 352 | + List<ByteBuf> byteBuffs = new ArrayList<>(this.contents.size()); |
355 | 353 |
|
356 | 354 | for (HttpContent content : this.contents) { |
357 | 355 | if (!isMultipart) { |
358 | | - byteBufs.add(content.content().copy()); |
| 356 | + byteBuffs.add(content.content().copy()); |
359 | 357 | } |
360 | 358 |
|
361 | 359 | decoder.offer(content); |
362 | 360 | this.readHttpDataChunkByChunk(decoder); |
363 | 361 | content.release(); |
364 | 362 | } |
365 | | - if (!byteBufs.isEmpty()) { |
366 | | - this.body = Unpooled.copiedBuffer(byteBufs.stream().toArray(ByteBuf[]::new)); |
| 363 | + if (!byteBuffs.isEmpty()) { |
| 364 | + this.body = Unpooled.copiedBuffer(byteBuffs.toArray(new ByteBuf[0])); |
367 | 365 | } |
368 | 366 | } catch (Exception e) { |
369 | 367 | throw new HttpParseException("build decoder fail", e); |
|
0 commit comments