Skip to content

Commit 8e10943

Browse files
author
Stephane Landelle
committed
Make disposition-type configurable, close #522
1 parent 0f49b39 commit 8e10943

File tree

1 file changed

+62
-18
lines changed
  • src/main/java/com/ning/http/multipart

1 file changed

+62
-18
lines changed

src/main/java/com/ning/http/multipart/Part.java

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,82 +33,102 @@ public abstract class Part implements com.ning.http.client.Part {
3333
/**
3434
* Carriage return/linefeed
3535
*/
36-
protected static final String CRLF = "\r\n";
36+
public static final String CRLF = "\r\n";
3737

3838
/**
3939
* Carriage return/linefeed as a byte array
4040
*/
41-
static final byte[] CRLF_BYTES = MultipartEncodingUtil.getAsciiBytes(CRLF);
41+
public static final byte[] CRLF_BYTES = MultipartEncodingUtil.getAsciiBytes(CRLF);
4242

4343
/**
4444
* Content dispostion characters
4545
*/
46-
protected static final String QUOTE = "\"";
46+
public static final String QUOTE = "\"";
4747

4848
/**
4949
* Content dispostion as a byte array
5050
*/
51-
static final byte[] QUOTE_BYTES = MultipartEncodingUtil.getAsciiBytes(QUOTE);
51+
public static final byte[] QUOTE_BYTES = MultipartEncodingUtil.getAsciiBytes(QUOTE);
5252

5353
/**
5454
* Extra characters
5555
*/
56-
protected static final String EXTRA = "--";
56+
public static final String EXTRA = "--";
5757

5858
/**
5959
* Extra characters as a byte array
6060
*/
61-
static final byte[] EXTRA_BYTES = MultipartEncodingUtil.getAsciiBytes(EXTRA);
61+
public static final byte[] EXTRA_BYTES = MultipartEncodingUtil.getAsciiBytes(EXTRA);
6262

6363
/**
64-
* Content dispostion characters
64+
* Content disposition characters
6565
*/
66-
protected static final String CONTENT_DISPOSITION = "Content-Disposition: form-data; name=";
66+
public static final String CONTENT_DISPOSITION = "Content-Disposition: ";
6767

6868
/**
69-
* Content dispostion as a byte array
69+
* Content disposition as a byte array
70+
*/
71+
public static final byte[] CONTENT_DISPOSITION_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_DISPOSITION);
72+
73+
/**
74+
* form-data characters
75+
*/
76+
public static final String FORM_DATA_DISPOSITION_TYPE = "form-data";
77+
78+
/**
79+
* form-data as a byte array
80+
*/
81+
public static final byte[] FORM_DATA_DISPOSITION_TYPE_BYTES = MultipartEncodingUtil.getAsciiBytes(FORM_DATA_DISPOSITION_TYPE);
82+
83+
/**
84+
* name characters
7085
*/
71-
static final byte[] CONTENT_DISPOSITION_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_DISPOSITION);
86+
public static final String NAME = "; name=";
87+
88+
/**
89+
* name as a byte array
90+
*/
91+
public static final byte[] NAME_BYTES = MultipartEncodingUtil.getAsciiBytes(NAME);
7292

7393
/**
7494
* Content type header
7595
*/
76-
protected static final String CONTENT_TYPE = "Content-Type: ";
96+
public static final String CONTENT_TYPE = "Content-Type: ";
7797

7898
/**
7999
* Content type header as a byte array
80100
*/
81-
static final byte[] CONTENT_TYPE_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_TYPE);
101+
public static final byte[] CONTENT_TYPE_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_TYPE);
82102

83103
/**
84104
* Content charset
85105
*/
86-
protected static final String CHARSET = "; charset=";
106+
public static final String CHARSET = "; charset=";
87107

88108
/**
89109
* Content charset as a byte array
90110
*/
91-
static final byte[] CHARSET_BYTES = MultipartEncodingUtil.getAsciiBytes(CHARSET);
111+
public static final byte[] CHARSET_BYTES = MultipartEncodingUtil.getAsciiBytes(CHARSET);
92112

93113
/**
94114
* Content type header
95115
*/
96-
protected static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding: ";
116+
public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding: ";
97117

98118
/**
99119
* Content type header as a byte array
100120
*/
101-
static final byte[] CONTENT_TRANSFER_ENCODING_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_TRANSFER_ENCODING);
121+
public static final byte[] CONTENT_TRANSFER_ENCODING_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_TRANSFER_ENCODING);
102122

103123
/**
104124
* Content type header
105125
*/
106-
protected static final String CONTENT_ID = "Content-ID: ";
126+
public static final String CONTENT_ID = "Content-ID: ";
107127

108128
/**
109129
* Content type header as a byte array
110130
*/
111-
static final byte[] CONTENT_ID_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_ID);
131+
public static final byte[] CONTENT_ID_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_ID);
112132

113133
/**
114134
* Return the name of this part.
@@ -155,6 +175,20 @@ public boolean isRepeatable() {
155175
return true;
156176
}
157177

178+
private String dispositionType;
179+
/**
180+
* Gets the disposition-type to be used in Content-Disposition header
181+
*
182+
* @return the disposition-type
183+
*/
184+
public String getDispositionType() {
185+
return dispositionType;
186+
}
187+
188+
public void setDispositionType(String dispositionType) {
189+
this.dispositionType = dispositionType;
190+
}
191+
158192
/**
159193
* Write the start to the specified output stream
160194
*
@@ -181,6 +215,11 @@ protected void sendDispositionHeader(OutputStream out) throws IOException {
181215
if (getName() != null) {
182216
out.write(CRLF_BYTES);
183217
out.write(CONTENT_DISPOSITION_BYTES);
218+
if (dispositionType != null)
219+
out.write(MultipartEncodingUtil.getAsciiBytes(dispositionType));
220+
else
221+
out.write(FORM_DATA_DISPOSITION_TYPE_BYTES);
222+
out.write(NAME_BYTES);
184223
out.write(QUOTE_BYTES);
185224
out.write(MultipartEncodingUtil.getAsciiBytes(getName()));
186225
out.write(QUOTE_BYTES);
@@ -192,6 +231,11 @@ protected long dispositionHeaderLength() {
192231
if (getName() != null) {
193232
length += CRLF_BYTES.length;
194233
length += CONTENT_DISPOSITION_BYTES.length;
234+
if (dispositionType != null)
235+
length += MultipartEncodingUtil.getAsciiBytes(dispositionType).length;
236+
else
237+
length += FORM_DATA_DISPOSITION_TYPE_BYTES.length;
238+
length += NAME_BYTES.length;
195239
length += QUOTE_BYTES.length;
196240
length += MultipartEncodingUtil.getAsciiBytes(getName()).length;
197241
length += QUOTE_BYTES.length;

0 commit comments

Comments
 (0)