Skip to content

Commit b469772

Browse files
authored
MultipartFormUpload: use MemoryAttribute (#2561)
Related to #2308 When creating a simple attribute, use memory storage, regardless of the value size. Otherwise, Netty creates a temporary file when the size if above the default limit (16KB). Signed-off-by: Thomas Segismont <[email protected]>
1 parent 9de6a88 commit b469772

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

vertx-web-client/src/main/java/io/vertx/ext/web/client/impl/MultipartFormUpload.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.buffer.UnpooledByteBufAllocator;
20-
import io.netty.handler.codec.http.DefaultFullHttpRequest;
21-
import io.netty.handler.codec.http.HttpConstants;
22-
import io.netty.handler.codec.http.HttpContent;
23-
import io.netty.handler.codec.http.HttpRequest;
24-
import io.netty.handler.codec.http.HttpVersion;
25-
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
26-
import io.netty.handler.codec.http.multipart.FileUpload;
27-
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
28-
import io.netty.handler.codec.http.multipart.MemoryFileUpload;
20+
import io.netty.handler.codec.http.*;
21+
import io.netty.handler.codec.http.multipart.*;
2922
import io.vertx.core.Context;
3023
import io.vertx.core.Handler;
3124
import io.vertx.core.MultiMap;
@@ -39,6 +32,7 @@
3932
import io.vertx.ext.web.multipart.MultipartForm;
4033

4134
import java.io.File;
35+
import java.io.IOException;
4236
import java.nio.charset.Charset;
4337

4438
/**
@@ -75,6 +69,15 @@ public MultipartFormUpload(Context context,
7569
Charset charset = parts.getCharset() != null ? parts.getCharset() : HttpConstants.DEFAULT_CHARSET;
7670
this.encoder = new HttpPostRequestEncoder(
7771
new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE, charset) {
72+
@Override
73+
public Attribute createAttribute(HttpRequest request, String name, String value) {
74+
try {
75+
return new MemoryAttribute(name, value, charset);
76+
} catch (IOException e) {
77+
throw new IllegalArgumentException(e);
78+
}
79+
}
80+
7881
@Override
7982
public FileUpload createFileUpload(HttpRequest request, String name, String filename, String contentType, String contentTransferEncoding, Charset _charset, long size) {
8083
if (_charset == null) {

0 commit comments

Comments
 (0)