Skip to content

Commit f49fcf8

Browse files
author
Stephane Landelle
committed
Make disposition-type configurable, close AsyncHttpClient#522
1 parent e2babac commit f49fcf8

File tree

1 file changed

+27
-1
lines changed
  • api/src/main/java/org/asynchttpclient/multipart

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ public abstract class Part {
4141
/**
4242
* Content dispostion as a byte array
4343
*/
44-
public static final byte[] CONTENT_DISPOSITION_BYTES = "Content-Disposition: form-data; name=".getBytes(StandardCharsets.US_ASCII);
44+
public static final byte[] CONTENT_DISPOSITION_BYTES = "Content-Disposition: ".getBytes(StandardCharsets.US_ASCII);
45+
46+
/**
47+
* form-data as a byte array
48+
*/
49+
public static final byte[] FORM_DATA_DISPOSITION_TYPE_BYTES = "form-data".getBytes(StandardCharsets.US_ASCII);
50+
51+
/**
52+
* name as a byte array
53+
*/
54+
public static final byte[] NAME_BYTES = "; name=".getBytes(StandardCharsets.US_ASCII);
4555

4656
/**
4757
* Content type header as a byte array
@@ -108,6 +118,20 @@ public boolean isRepeatable() {
108118
return true;
109119
}
110120

121+
private String dispositionType;
122+
/**
123+
* Gets the disposition-type to be used in Content-Disposition header
124+
*
125+
* @return the disposition-type
126+
*/
127+
public String getDispositionType() {
128+
return dispositionType;
129+
}
130+
131+
public void setDispositionType(String dispositionType) {
132+
this.dispositionType = dispositionType;
133+
}
134+
111135
protected void visitStart(PartVisitor visitor, byte[] boundary) throws IOException {
112136
visitor.withBytes(EXTRA_BYTES);
113137
visitor.withBytes(boundary);
@@ -117,6 +141,8 @@ protected void visitDispositionHeader(PartVisitor visitor) throws IOException {
117141
if (getName() != null) {
118142
visitor.withBytes(CRLF_BYTES);
119143
visitor.withBytes(CONTENT_DISPOSITION_BYTES);
144+
visitor.withBytes(dispositionType != null? dispositionType.getBytes(StandardCharsets.US_ASCII): FORM_DATA_DISPOSITION_TYPE_BYTES);
145+
visitor.withBytes(NAME_BYTES);
120146
visitor.withBytes(QUOTE_BYTES);
121147
visitor.withBytes(getName().getBytes(StandardCharsets.US_ASCII));
122148
visitor.withBytes(QUOTE_BYTES);

0 commit comments

Comments
 (0)