Skip to content

Commit 3dcb179

Browse files
author
Stephane Landelle
committed
Multipart name should be optional, close AsyncHttpClient#523
1 parent 4bd4824 commit 3dcb179

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

api/src/main/java/org/asynchttpclient/multipart/Part.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,11 @@ protected void visitStart(PartVisitor visitor, byte[] boundary) throws IOExcepti
128128
}
129129

130130
protected void visitDispositionHeader(PartVisitor visitor) throws IOException {
131-
131+
visitor.withBytes(CRLF_BYTES);
132+
visitor.withBytes(CONTENT_DISPOSITION_BYTES);
133+
visitor.withBytes(getDispositionType() != null ? getDispositionType().getBytes(StandardCharsets.US_ASCII)
134+
: FORM_DATA_DISPOSITION_TYPE_BYTES);
132135
if (getName() != null) {
133-
visitor.withBytes(CRLF_BYTES);
134-
visitor.withBytes(CONTENT_DISPOSITION_BYTES);
135-
visitor.withBytes(getDispositionType() != null ? getDispositionType().getBytes(StandardCharsets.US_ASCII)
136-
: FORM_DATA_DISPOSITION_TYPE_BYTES);
137136
visitor.withBytes(NAME_BYTES);
138137
visitor.withBytes(QUOTE_BYTES);
139138
visitor.withBytes(getName().getBytes(StandardCharsets.US_ASCII));
@@ -239,14 +238,15 @@ public long length(byte[] boundary) {
239238
}
240239
}
241240

242-
/**
243-
* Return a string representation of this object.
244-
*
245-
* @return A string representation of this object.
246-
* @see java.lang.Object#toString()
247-
*/
248241
public String toString() {
249-
return this.getName();
242+
return new StringBuilder()//
243+
.append("name=").append(getName())//
244+
.append(" contentType=").append(getContentType())//
245+
.append(" charset=").append(getCharSet())//
246+
.append(" tranferEncoding=").append(getTransferEncoding())//
247+
.append(" contentId=").append(getContentId())//
248+
.append(" dispositionType=").append(getDispositionType())//
249+
.toString();
250250
}
251251

252252
public abstract long write(WritableByteChannel target, byte[] boundary) throws IOException;

api/src/main/java/org/asynchttpclient/multipart/PartBase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,13 @@ public abstract class PartBase extends Part {
4747
/**
4848
* Constructor.
4949
*
50-
* @param name The name of the part
50+
* @param name The name of the part, or <code>null</code>
5151
* @param contentType The content type, or <code>null</code>
5252
* @param charSet The character encoding, or <code>null</code>
5353
* @param transferEncoding The transfer encoding, or <code>null</code>
5454
* @param contentId The content id, or <code>null</code>
5555
*/
5656
public PartBase(String name, String contentType, String charSet, String transferEncoding, String contentId) {
57-
58-
if (name == null) {
59-
throw new NullPointerException("name");
60-
}
6157
this.name = name;
6258
this.contentType = contentType;
6359
this.charSet = charSet;

0 commit comments

Comments
 (0)