Skip to content

Commit 92023da

Browse files
author
Stephane Landelle
committed
Make transferEncoding configurable, fix FilePart constructors, close AsyncHttpClient#647
1 parent e570859 commit 92023da

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ public abstract class AbstractFilePart extends PartBase {
5555
* @param charset
5656
* the charset encoding for this part
5757
*/
58-
public AbstractFilePart(String name, String contentType, String charset, String contentId) {
59-
super(name, contentType == null ? DEFAULT_CONTENT_TYPE : contentType, charset,
60-
DEFAULT_TRANSFER_ENCODING, contentId);
58+
public AbstractFilePart(String name, String contentType, String charset, String contentId, String transfertEncoding) {
59+
super(name,//
60+
contentType == null ? DEFAULT_CONTENT_TYPE : contentType,//
61+
charset,//
62+
contentId,//
63+
transfertEncoding == null ? DEFAULT_TRANSFER_ENCODING : transfertEncoding);
6164
}
6265

6366
protected void visitDispositionHeader(PartVisitor visitor) throws IOException {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ public ByteArrayPart(String name, byte[] bytes, String contentType, String chars
3737
}
3838

3939
public ByteArrayPart(String name, byte[] bytes, String contentType, String charset, String fileName, String contentId) {
40-
super(name, contentType, charset, contentId);
41-
if (bytes == null) {
40+
this(name, bytes, contentType, charset, fileName, contentId, null);
41+
}
42+
43+
public ByteArrayPart(String name, byte[] bytes, String contentType, String charset, String fileName, String contentId, String transferEncoding) {
44+
super(name, contentType, charset, contentId, transferEncoding);
45+
if (bytes == null)
4246
throw new NullPointerException("bytes");
43-
}
4447
this.bytes = bytes;
4548
setFileName(fileName);
4649
}
47-
50+
4851
@Override
4952
protected void sendData(OutputStream out) throws IOException {
5053
out.write(bytes);

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,37 @@ public class FilePart extends AbstractFilePart {
3131
private final File file;
3232

3333
public FilePart(String name, File file) {
34-
this(name, file, null, null);
34+
this(name, file, null);
3535
}
3636

3737
public FilePart(String name, File file, String contentType) {
38-
this(name, file, null, contentType, null);
38+
this(name, file, contentType, null);
3939
}
4040

4141
public FilePart(String name, File file, String contentType, String charset) {
42-
this(name, file, null, contentType, charset, null);
42+
this(name, file, contentType, charset, null);
4343
}
4444

4545
public FilePart(String name, File file, String contentType, String charset, String fileName) {
46-
this(name, file, null, contentType, charset, fileName);
46+
this(name, file, contentType, charset, fileName, null);
4747
}
4848

4949
public FilePart(String name, File file, String contentType, String charset, String fileName, String contentId) {
50-
super(name, contentType, charset, contentId);
51-
this.file = file;
52-
if (file == null) {
50+
this(name, file, contentType, charset, fileName, contentId, null);
51+
}
52+
53+
public FilePart(String name, File file, String contentType, String charset, String fileName, String contentId, String transferEncoding) {
54+
super(name, contentType, charset, contentId, transferEncoding);
55+
if (file == null)
5356
throw new NullPointerException("file");
54-
}
55-
if (!file.isFile()) {
57+
if (!file.isFile())
5658
throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath());
57-
}
58-
if (!file.canRead()) {
59+
if (!file.canRead())
5960
throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath());
60-
}
61+
this.file = file;
6162
setFileName(fileName != null ? fileName : file.getName());
6263
}
63-
64+
6465
@Override
6566
protected void sendData(OutputStream out) throws IOException {
6667
if (getDataLength() == 0) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public abstract class PartBase implements Part {
5555
* @param name The name of the part, or <code>null</code>
5656
* @param contentType The content type, or <code>null</code>
5757
* @param charSet The character encoding, or <code>null</code>
58-
* @param transferEncoding The transfer encoding, or <code>null</code>
5958
* @param contentId The content id, or <code>null</code>
59+
* @param transferEncoding The transfer encoding, or <code>null</code>
6060
*/
61-
public PartBase(String name, String contentType, String charSet, String transferEncoding, String contentId) {
61+
public PartBase(String name, String contentType, String charSet, String contentId, String transferEncoding) {
6262
this.name = name;
6363
this.contentType = contentType;
6464
this.charSet = charSet;
65-
this.transferEncoding = transferEncoding;
6665
this.contentId = contentId;
66+
this.transferEncoding = transferEncoding;
6767
}
6868

6969
protected void visitStart(PartVisitor visitor, byte[] boundary) throws IOException {

0 commit comments

Comments
 (0)