|
29 | 29 |
|
30 | 30 | import java.io.File;
|
31 | 31 | import java.io.InputStream;
|
32 |
| -import java.nio.CharBuffer; |
33 | 32 | import java.nio.charset.Charset;
|
34 | 33 | import java.nio.charset.StandardCharsets;
|
35 | 34 | import java.util.ArrayList;
|
36 | 35 | import java.util.Collections;
|
37 | 36 | import java.util.List;
|
38 |
| -import java.util.concurrent.ThreadLocalRandom; |
| 37 | +import java.util.UUID; |
39 | 38 |
|
40 | 39 | import org.apache.hc.core5.http.ContentType;
|
41 | 40 | import org.apache.hc.core5.http.HttpEntity;
|
|
46 | 45 | /**
|
47 | 46 | * Builder for multipart {@link HttpEntity}s.
|
48 | 47 | * <p>
|
49 |
| - * IMPORTANT: it is responsibility of the caller to validate / sanitize content of body |
50 |
| - * parts, for instance, to ensure they do not contain the boundary value that can prevent |
51 |
| - * the consumer of the entity from correctly parsing / processing the body parts. |
| 48 | +* IMPORTANT: it is responsibility of the caller to validate / sanitize content of body |
| 49 | +* parts. For instance, when using an explicit boundary, it's the caller's responsibility to |
| 50 | +* ensure the body parts do not contain the boundary value, which can prevent the consumer of |
| 51 | +* the entity from correctly parsing / processing the body parts. |
52 | 52 | * </p>
|
53 | 53 | *
|
54 | 54 | * @since 5.0
|
55 | 55 | */
|
56 | 56 | public class MultipartEntityBuilder {
|
57 | 57 |
|
58 |
| - /** |
59 |
| - * The pool of ASCII chars to be used for generating a multipart boundary. |
60 |
| - */ |
61 |
| - private final static char[] MULTIPART_CHARS = |
62 |
| - "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |
63 |
| - .toCharArray(); |
64 |
| - |
65 | 58 | private ContentType contentType;
|
66 | 59 | private HttpMultipartMode mode = HttpMultipartMode.STRICT;
|
67 | 60 | private String boundary;
|
@@ -237,14 +230,7 @@ public MultipartEntityBuilder addEpilogue(final String epilogue) {
|
237 | 230 | }
|
238 | 231 |
|
239 | 232 | private String generateBoundary() {
|
240 |
| - final ThreadLocalRandom rand = ThreadLocalRandom.current(); |
241 |
| - final int count = rand.nextInt(30, 41); // a random size from 30 to 40 |
242 |
| - final CharBuffer buffer = CharBuffer.allocate(count); |
243 |
| - while (buffer.hasRemaining()) { |
244 |
| - buffer.put(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]); |
245 |
| - } |
246 |
| - buffer.flip(); |
247 |
| - return buffer.toString(); |
| 233 | + return "httpclient_boundary_" + UUID.randomUUID(); |
248 | 234 | }
|
249 | 235 |
|
250 | 236 | MultipartFormEntity buildEntity() {
|
|
0 commit comments