You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/01/01 12:50:27 UTC
[httpcomponents-client] 01/02: MIME code cleanup and class renaming
(no functional changes)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 56463de35d9b8848c081482539ae904a7e47f25d
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Dec 30 11:24:27 2019 +0100
MIME code cleanup and class renaming (no functional changes)
---
.../http/entity/mime/AbstractMultipartFormat.java | 8 +--
.../http/entity/mime/FormBodyPartBuilder.java | 24 +++----
.../apache/hc/client5/http/entity/mime/Header.java | 34 +++++-----
.../mime/HttpBrowserCompatibleMultipart.java | 4 +-
.../http/entity/mime/HttpRFC6532Multipart.java | 9 +--
.../http/entity/mime/HttpRFC7578Multipart.java | 78 ++++++++++------------
.../http/entity/mime/HttpStrictMultipart.java | 9 +--
.../entity/mime/{MIME.java => MimeConsts.java} | 6 +-
.../mime/{MinimalField.java => MimeField.java} | 8 +--
.../hc/client5/http/entity/mime/MultipartPart.java | 4 +-
.../http/entity/mime/MultipartPartBuilder.java | 16 ++---
.../http/entity/mime/TestFormBodyPartBuilder.java | 52 +++++++--------
.../entity/mime/TestMultipartEntityBuilder.java | 8 +--
.../http/entity/mime/TestMultipartPartBuilder.java | 42 ++++++------
14 files changed, 139 insertions(+), 163 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/AbstractMultipartFormat.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/AbstractMultipartFormat.java
index 416bccb..9e903bc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/AbstractMultipartFormat.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/AbstractMultipartFormat.java
@@ -40,9 +40,7 @@ import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
/**
- * HttpMultipart represents a collection of MIME multipart encoded content bodies. This class is
- * capable of operating either in the strict (RFC 822, RFC 2045, RFC 2046 compliant) or
- * the browser compatible modes.
+ * HttpMultipart represents a collection of MIME multipart encoded content bodies.
*
* @since 4.3
*/
@@ -74,7 +72,7 @@ abstract class AbstractMultipartFormat {
}
static void writeField(
- final MinimalField field, final OutputStream out) throws IOException {
+ final MimeField field, final OutputStream out) throws IOException {
writeBytes(field.getName(), out);
writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), out);
@@ -82,7 +80,7 @@ abstract class AbstractMultipartFormat {
}
static void writeField(
- final MinimalField field, final Charset charset, final OutputStream out) throws IOException {
+ final MimeField field, final Charset charset, final OutputStream out) throws IOException {
writeBytes(field.getName(), charset, out);
writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), charset, out);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPartBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPartBuilder.java
index 234c991..72405cf 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPartBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/FormBodyPartBuilder.java
@@ -80,19 +80,19 @@ public class FormBodyPartBuilder {
*/
public FormBodyPartBuilder addField(final String name, final String value, final List<NameValuePair> parameters) {
Args.notNull(name, "Field name");
- this.header.addField(new MinimalField(name, value, parameters));
+ this.header.addField(new MimeField(name, value, parameters));
return this;
}
public FormBodyPartBuilder addField(final String name, final String value) {
Args.notNull(name, "Field name");
- this.header.addField(new MinimalField(name, value));
+ this.header.addField(new MimeField(name, value));
return this;
}
public FormBodyPartBuilder setField(final String name, final String value) {
Args.notNull(name, "Field name");
- this.header.setField(new MinimalField(name, value));
+ this.header.setField(new MimeField(name, value));
return this;
}
@@ -106,19 +106,19 @@ public class FormBodyPartBuilder {
Asserts.notBlank(this.name, "Name");
Asserts.notNull(this.body, "Content body");
final Header headerCopy = new Header();
- final List<MinimalField> fields = this.header.getFields();
- for (final MinimalField field: fields) {
+ final List<MimeField> fields = this.header.getFields();
+ for (final MimeField field: fields) {
headerCopy.addField(field);
}
- if (headerCopy.getField(MIME.CONTENT_DISPOSITION) == null) {
+ if (headerCopy.getField(MimeConsts.CONTENT_DISPOSITION) == null) {
final List<NameValuePair> fieldParameters = new ArrayList<>();
- fieldParameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_NAME, this.name));
+ fieldParameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_NAME, this.name));
if (this.body.getFilename() != null) {
- fieldParameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_FILENAME, this.body.getFilename()));
+ fieldParameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_FILENAME, this.body.getFilename()));
}
- headerCopy.addField(new MinimalField(MIME.CONTENT_DISPOSITION, "form-data", fieldParameters));
+ headerCopy.addField(new MimeField(MimeConsts.CONTENT_DISPOSITION, "form-data", fieldParameters));
}
- if (headerCopy.getField(MIME.CONTENT_TYPE) == null) {
+ if (headerCopy.getField(MimeConsts.CONTENT_TYPE) == null) {
final ContentType contentType;
if (body instanceof AbstractContentBody) {
contentType = ((AbstractContentBody) body).getContentType();
@@ -126,7 +126,7 @@ public class FormBodyPartBuilder {
contentType = null;
}
if (contentType != null) {
- headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, contentType.toString()));
+ headerCopy.addField(new MimeField(MimeConsts.CONTENT_TYPE, contentType.toString()));
} else {
final StringBuilder buffer = new StringBuilder();
buffer.append(this.body.getMimeType()); // MimeType cannot be null
@@ -134,7 +134,7 @@ public class FormBodyPartBuilder {
buffer.append("; charset=");
buffer.append(this.body.getCharset());
}
- headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, buffer.toString()));
+ headerCopy.addField(new MimeField(MimeConsts.CONTENT_TYPE, buffer.toString()));
}
}
return new FormBodyPart(this.name, this.body, headerCopy);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/Header.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/Header.java
index b134f86..3b737cf 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/Header.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/Header.java
@@ -37,12 +37,12 @@ import java.util.Locale;
import java.util.Map;
/**
- * The header of an entity (see RFC 2045).
+ * The header of a MIME entity.
*/
-public class Header implements Iterable<MinimalField> {
+public class Header implements Iterable<MimeField> {
- private final List<MinimalField> fields;
- private final Map<String, List<MinimalField>> fieldMap;
+ private final List<MimeField> fields;
+ private final Map<String, List<MimeField>> fieldMap;
public Header() {
super();
@@ -50,12 +50,12 @@ public class Header implements Iterable<MinimalField> {
this.fieldMap = new HashMap<>();
}
- public void addField(final MinimalField field) {
+ public void addField(final MimeField field) {
if (field == null) {
return;
}
final String key = field.getName().toLowerCase(Locale.ROOT);
- List<MinimalField> values = this.fieldMap.get(key);
+ List<MimeField> values = this.fieldMap.get(key);
if (values == null) {
values = new LinkedList<>();
this.fieldMap.put(key, values);
@@ -64,28 +64,28 @@ public class Header implements Iterable<MinimalField> {
this.fields.add(field);
}
- public List<MinimalField> getFields() {
+ public List<MimeField> getFields() {
return new ArrayList<>(this.fields);
}
- public MinimalField getField(final String name) {
+ public MimeField getField(final String name) {
if (name == null) {
return null;
}
final String key = name.toLowerCase(Locale.ROOT);
- final List<MinimalField> list = this.fieldMap.get(key);
+ final List<MimeField> list = this.fieldMap.get(key);
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
}
- public List<MinimalField> getFields(final String name) {
+ public List<MimeField> getFields(final String name) {
if (name == null) {
return null;
}
final String key = name.toLowerCase(Locale.ROOT);
- final List<MinimalField> list = this.fieldMap.get(key);
+ final List<MimeField> list = this.fieldMap.get(key);
if (list == null || list.isEmpty()) {
return Collections.emptyList();
}
@@ -97,7 +97,7 @@ public class Header implements Iterable<MinimalField> {
return 0;
}
final String key = name.toLowerCase(Locale.ROOT);
- final List<MinimalField> removed = fieldMap.remove(key);
+ final List<MimeField> removed = fieldMap.remove(key);
if (removed == null || removed.isEmpty()) {
return 0;
}
@@ -105,12 +105,12 @@ public class Header implements Iterable<MinimalField> {
return removed.size();
}
- public void setField(final MinimalField field) {
+ public void setField(final MimeField field) {
if (field == null) {
return;
}
final String key = field.getName().toLowerCase(Locale.ROOT);
- final List<MinimalField> list = fieldMap.get(key);
+ final List<MimeField> list = fieldMap.get(key);
if (list == null || list.isEmpty()) {
addField(field);
return;
@@ -119,8 +119,8 @@ public class Header implements Iterable<MinimalField> {
list.add(field);
int firstOccurrence = -1;
int index = 0;
- for (final Iterator<MinimalField> it = this.fields.iterator(); it.hasNext(); index++) {
- final MinimalField f = it.next();
+ for (final Iterator<MimeField> it = this.fields.iterator(); it.hasNext(); index++) {
+ final MimeField f = it.next();
if (f.getName().equalsIgnoreCase(field.getName())) {
it.remove();
if (firstOccurrence == -1) {
@@ -132,7 +132,7 @@ public class Header implements Iterable<MinimalField> {
}
@Override
- public Iterator<MinimalField> iterator() {
+ public Iterator<MimeField> iterator() {
return Collections.unmodifiableList(fields).iterator();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpBrowserCompatibleMultipart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpBrowserCompatibleMultipart.java
index f16d593..e431091 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpBrowserCompatibleMultipart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpBrowserCompatibleMultipart.java
@@ -65,13 +65,13 @@ class HttpBrowserCompatibleMultipart extends AbstractMultipartFormat {
// For browser-compatible, only write Content-Disposition
// Use content charset
final Header header = part.getHeader();
- final MinimalField cd = header.getField(MIME.CONTENT_DISPOSITION);
+ final MimeField cd = header.getField(MimeConsts.CONTENT_DISPOSITION);
if (cd != null) {
writeField(cd, this.charset, out);
}
final String filename = part.getBody().getFilename();
if (filename != null) {
- final MinimalField ct = header.getField(MIME.CONTENT_TYPE);
+ final MimeField ct = header.getField(MimeConsts.CONTENT_TYPE);
writeField(ct, this.charset, out);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC6532Multipart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC6532Multipart.java
index 40dc156..50cdf7e 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC6532Multipart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC6532Multipart.java
@@ -33,13 +33,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
-/**
- * HttpRFC6532Multipart represents a collection of MIME multipart encoded content bodies,
- * implementing the strict (RFC 822, RFC 2045, RFC 2046 compliant) interpretation
- * of the spec, with the exception of allowing UTF-8 headers, as per RFC6532.
- *
- * @since 4.3
- */
class HttpRFC6532Multipart extends AbstractMultipartFormat {
private final List<MultipartPart> parts;
@@ -64,7 +57,7 @@ class HttpRFC6532Multipart extends AbstractMultipartFormat {
// For RFC6532, we output all fields with UTF-8 encoding.
final Header header = part.getHeader();
- for (final MinimalField field: header) {
+ for (final MimeField field: header) {
writeField(field, StandardCharsets.UTF_8, out);
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
index 8249575..056b667 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
@@ -40,7 +40,7 @@ import org.apache.commons.codec.DecoderException;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.util.ByteArrayBuffer;
-public class HttpRFC7578Multipart extends AbstractMultipartFormat {
+class HttpRFC7578Multipart extends AbstractMultipartFormat {
private static final PercentCodec PERCENT_CODEC = new PercentCodec();
@@ -61,8 +61,8 @@ public class HttpRFC7578Multipart extends AbstractMultipartFormat {
@Override
protected void formatMultipartHeader(final MultipartPart part, final OutputStream out) throws IOException {
- for (final MinimalField field: part.getHeader()) {
- if (MIME.CONTENT_DISPOSITION.equalsIgnoreCase(field.getName())) {
+ for (final MimeField field: part.getHeader()) {
+ if (MimeConsts.CONTENT_DISPOSITION.equalsIgnoreCase(field.getName())) {
writeBytes(field.getName(), charset, out);
writeBytes(FIELD_SEP, out);
writeBytes(field.getValue(), out);
@@ -75,7 +75,7 @@ public class HttpRFC7578Multipart extends AbstractMultipartFormat {
writeBytes(name, out);
writeBytes("=\"", out);
if (value != null) {
- if (name.equalsIgnoreCase(MIME.FIELD_PARAM_FILENAME)) {
+ if (name.equalsIgnoreCase(MimeConsts.FIELD_PARAM_FILENAME)) {
out.write(PERCENT_CODEC.encode(value.getBytes(charset)));
} else {
writeBytes(value, out);
@@ -120,8 +120,8 @@ public class HttpRFC7578Multipart extends AbstractMultipartFormat {
buffer.write(b);
} else {
buffer.write(ESCAPE_CHAR);
- final char hex1 = Utils.hexDigit(b >> 4);
- final char hex2 = Utils.hexDigit(b);
+ final char hex1 = hexDigit(b >> 4);
+ final char hex2 = hexDigit(b);
buffer.write(hex1);
buffer.write(hex2);
}
@@ -138,8 +138,8 @@ public class HttpRFC7578Multipart extends AbstractMultipartFormat {
final int b = bytes[i];
if (b == ESCAPE_CHAR) {
try {
- final int u = Utils.digit16(bytes[++i]);
- final int l = Utils.digit16(bytes[++i]);
+ final int u = digit16(bytes[++i]);
+ final int l = digit16(bytes[++i]);
buffer.append((char) ((u << 4) + l));
} catch (final ArrayIndexOutOfBoundsException e) {
throw new DecoderException("Invalid URL encoding: ", e);
@@ -152,41 +152,37 @@ public class HttpRFC7578Multipart extends AbstractMultipartFormat {
}
}
- static class Utils {
-
- /**
- * Radix used in encoding and decoding.
- */
- private static final int RADIX = 16;
-
- /**
- * Returns the numeric value of the character <code>b</code> in radix 16.
- *
- * @param b
- * The byte to be converted.
- * @return The numeric value represented by the character in radix 16.
- *
- * @throws DecoderException
- * Thrown when the byte is not valid per {@link Character#digit(char,int)}
- */
- static int digit16(final byte b) throws DecoderException {
- final int i = Character.digit((char) b, RADIX);
- if (i == -1) {
- throw new DecoderException("Invalid URL encoding: not a valid digit (radix " + RADIX + "): " + b);
- }
- return i;
- }
-
- /**
- * Returns the upper case hex digit of the lower 4 bits of the int.
- *
- * @param b the input int
- * @return the upper case hex digit of the lower 4 bits of the int.
- */
- static char hexDigit(final int b) {
- return Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
+ /**
+ * Radix used in encoding and decoding.
+ */
+ private static final int RADIX = 16;
+
+ /**
+ * Returns the numeric value of the character <code>b</code> in radix 16.
+ *
+ * @param b
+ * The byte to be converted.
+ * @return The numeric value represented by the character in radix 16.
+ *
+ * @throws DecoderException
+ * Thrown when the byte is not valid per {@link Character#digit(char,int)}
+ */
+ static int digit16(final byte b) throws DecoderException {
+ final int i = Character.digit((char) b, RADIX);
+ if (i == -1) {
+ throw new DecoderException("Invalid URL encoding: not a valid digit (radix " + RADIX + "): " + b);
}
+ return i;
+ }
+ /**
+ * Returns the upper case hex digit of the lower 4 bits of the int.
+ *
+ * @param b the input int
+ * @return the upper case hex digit of the lower 4 bits of the int.
+ */
+ static char hexDigit(final int b) {
+ return Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpStrictMultipart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpStrictMultipart.java
index 1c7a017..a78cfbc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpStrictMultipart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpStrictMultipart.java
@@ -32,13 +32,6 @@ import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;
-/**
- * HttpStrictMultipart represents a collection of MIME multipart encoded content bodies,
- * implementing the strict (RFC 822, RFC 2045, RFC 2046 compliant) interpretation
- * of the spec.
- *
- * @since 4.3
- */
class HttpStrictMultipart extends AbstractMultipartFormat {
private final List<MultipartPart> parts;
@@ -63,7 +56,7 @@ class HttpStrictMultipart extends AbstractMultipartFormat {
// For strict, we output all fields with MIME-standard encoding.
final Header header = part.getHeader();
- for (final MinimalField field: header) {
+ for (final MimeField field: header) {
writeField(field, out);
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MIME.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeConsts.java
similarity index 96%
rename from httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MIME.java
rename to httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeConsts.java
index ac6fc1c..a6c018a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MIME.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeConsts.java
@@ -27,11 +27,7 @@
package org.apache.hc.client5.http.entity.mime;
-/**
- *
- * @since 4.0
- */
-public final class MIME {
+final class MimeConsts {
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_DISPOSITION = "Content-Disposition";
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MinimalField.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
similarity index 92%
rename from httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MinimalField.java
rename to httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
index c1eef24..3b2c681 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MinimalField.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MimeField.java
@@ -38,13 +38,13 @@ import org.apache.hc.core5.http.NameValuePair;
*
* @since 4.0
*/
-public class MinimalField {
+public class MimeField {
private final String name;
private final String value;
private final List<NameValuePair> parameters;
- public MinimalField(final String name, final String value) {
+ public MimeField(final String name, final String value) {
super();
this.name = name;
this.value = value;
@@ -54,14 +54,14 @@ public class MinimalField {
/**
* @since 4.6
*/
- public MinimalField(final String name, final String value, final List<NameValuePair> parameters) {
+ public MimeField(final String name, final String value, final List<NameValuePair> parameters) {
this.name = name;
this.value = value;
this.parameters = parameters != null ?
Collections.unmodifiableList(new ArrayList<>(parameters)) : Collections.<NameValuePair>emptyList();
}
- public MinimalField(final MinimalField from) {
+ public MimeField(final MimeField from) {
this(from.name, from.value, from.parameters);
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPart.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPart.java
index 05ebf77..af87776 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPart.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPart.java
@@ -54,10 +54,10 @@ public class MultipartPart {
}
void addField(final String name, final String value) {
- addField(new MinimalField(name, value));
+ addField(new MimeField(name, value));
}
- void addField(final MinimalField field) {
+ void addField(final MimeField field) {
this.header.addField(field);
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPartBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPartBuilder.java
index e5ef448..eeda5cd 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPartBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/MultipartPartBuilder.java
@@ -68,19 +68,19 @@ public class MultipartPartBuilder {
public MultipartPartBuilder addHeader(final String name, final String value, final List<NameValuePair> parameters) {
Args.notNull(name, "Header name");
- this.header.addField(new MinimalField(name, value, parameters));
+ this.header.addField(new MimeField(name, value, parameters));
return this;
}
public MultipartPartBuilder addHeader(final String name, final String value) {
Args.notNull(name, "Header name");
- this.header.addField(new MinimalField(name, value));
+ this.header.addField(new MimeField(name, value));
return this;
}
public MultipartPartBuilder setHeader(final String name, final String value) {
Args.notNull(name, "Header name");
- this.header.setField(new MinimalField(name, value));
+ this.header.setField(new MimeField(name, value));
return this;
}
@@ -93,11 +93,11 @@ public class MultipartPartBuilder {
public MultipartPart build() {
Asserts.notNull(this.body, "Content body");
final Header headerCopy = new Header();
- final List<MinimalField> fields = this.header.getFields();
- for (final MinimalField field: fields) {
+ final List<MimeField> fields = this.header.getFields();
+ for (final MimeField field: fields) {
headerCopy.addField(field);
}
- if (headerCopy.getField(MIME.CONTENT_TYPE) == null) {
+ if (headerCopy.getField(MimeConsts.CONTENT_TYPE) == null) {
final ContentType contentType;
if (body instanceof AbstractContentBody) {
contentType = ((AbstractContentBody) body).getContentType();
@@ -105,7 +105,7 @@ public class MultipartPartBuilder {
contentType = null;
}
if (contentType != null) {
- headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, contentType.toString()));
+ headerCopy.addField(new MimeField(MimeConsts.CONTENT_TYPE, contentType.toString()));
} else {
final StringBuilder buffer = new StringBuilder();
buffer.append(this.body.getMimeType()); // MimeType cannot be null
@@ -113,7 +113,7 @@ public class MultipartPartBuilder {
buffer.append("; charset=");
buffer.append(this.body.getCharset());
}
- headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, buffer.toString()));
+ headerCopy.addField(new MimeField(MimeConsts.CONTENT_TYPE, buffer.toString()));
}
}
return new MultipartPart(this.body, headerCopy);
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestFormBodyPartBuilder.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestFormBodyPartBuilder.java
index ab99a26..3ae24d1 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestFormBodyPartBuilder.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestFormBodyPartBuilder.java
@@ -50,8 +50,8 @@ public class TestFormBodyPartBuilder {
final Header header = bodyPart.getHeader();
Assert.assertNotNull(header);
assertFields(Arrays.asList(
- new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("Content-Disposition", "form-data; name=\"blah\""),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header.getFields());
}
@@ -69,8 +69,8 @@ public class TestFormBodyPartBuilder {
final Header header1 = bodyPart1.getHeader();
Assert.assertNotNull(header1);
assertFields(Arrays.asList(
- new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("Content-Disposition", "form-data; name=\"blah\""),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header1.getFields());
final FileBody fileBody = new FileBody(new File("/path/stuff.bin"), ContentType.DEFAULT_BINARY);
final FormBodyPart bodyPart2 = builder
@@ -84,8 +84,8 @@ public class TestFormBodyPartBuilder {
final Header header2 = bodyPart2.getHeader();
Assert.assertNotNull(header2);
assertFields(Arrays.asList(
- new MinimalField("Content-Disposition", "form-data; name=\"yada\"; filename=\"stuff.bin\""),
- new MinimalField("Content-Type", "application/octet-stream")),
+ new MimeField("Content-Disposition", "form-data; name=\"yada\"; filename=\"stuff.bin\""),
+ new MimeField("Content-Type", "application/octet-stream")),
header2.getFields());
}
@@ -107,14 +107,14 @@ public class TestFormBodyPartBuilder {
Assert.assertNotNull(header1);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("header1", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("Content-Disposition", "form-data; name=\"blah\""),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header1.getFields());
final FormBodyPart bodyPart2 = builder
@@ -127,10 +127,10 @@ public class TestFormBodyPartBuilder {
Assert.assertNotNull(header2);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header2", "yada"),
- new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("header1", "blah"),
+ new MimeField("header2", "yada"),
+ new MimeField("Content-Disposition", "form-data; name=\"blah\""),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header2.getFields());
final FormBodyPart bodyPart3 = builder
@@ -144,21 +144,21 @@ public class TestFormBodyPartBuilder {
Assert.assertNotNull(header3);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header2", "yada"),
- new MinimalField("Content-Disposition", "disposition stuff"),
- new MinimalField("Content-Type", "type stuff"),
- new MinimalField("Content-Transfer-Encoding", "encoding stuff")),
+ new MimeField("header1", "blah"),
+ new MimeField("header2", "yada"),
+ new MimeField("Content-Disposition", "disposition stuff"),
+ new MimeField("Content-Type", "type stuff"),
+ new MimeField("Content-Transfer-Encoding", "encoding stuff")),
header3.getFields());
}
- private static void assertFields(final List<MinimalField> expected, final List<MinimalField> result) {
+ private static void assertFields(final List<MimeField> expected, final List<MimeField> result) {
Assert.assertNotNull(result);
Assert.assertEquals(expected.size(), result.size());
for (int i = 0; i < expected.size(); i++) {
- final MinimalField expectedField = expected.get(i);
- final MinimalField resultField = result.get(i);
+ final MimeField expectedField = expected.get(i);
+ final MimeField resultField = result.get(i);
Assert.assertNotNull(resultField);
Assert.assertEquals(expectedField.getName(), resultField.getName());
Assert.assertEquals(expectedField.getBody(), resultField.getBody());
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartEntityBuilder.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartEntityBuilder.java
index 937a89d..ce6dbf7 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartEntityBuilder.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartEntityBuilder.java
@@ -121,8 +121,8 @@ public class TestMultipartEntityBuilder {
@Test
public void testMultipartWriteTo() throws Exception {
final List<NameValuePair> parameters = new ArrayList<>();
- parameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_NAME, "test"));
- parameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_FILENAME, "hello world"));
+ parameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_NAME, "test"));
+ parameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_FILENAME, "hello world"));
final MultipartFormEntity entity = MultipartEntityBuilder.create()
.setStrictMode()
.setBoundary("xxxxxxxxxxxxxxxxxxxxxxxx")
@@ -147,8 +147,8 @@ public class TestMultipartEntityBuilder {
@Test
public void testMultipartWriteToRFC7578Mode() throws Exception {
final List<NameValuePair> parameters = new ArrayList<>();
- parameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_NAME, "test"));
- parameters.add(new BasicNameValuePair(MIME.FIELD_PARAM_FILENAME, "hello \u03BA\u03CC\u03C3\u03BC\u03B5!%"));
+ parameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_NAME, "test"));
+ parameters.add(new BasicNameValuePair(MimeConsts.FIELD_PARAM_FILENAME, "hello \u03BA\u03CC\u03C3\u03BC\u03B5!%"));
final MultipartFormEntity entity = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.RFC7578)
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartPartBuilder.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartPartBuilder.java
index 6304dd7..2543008 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartPartBuilder.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/mime/TestMultipartPartBuilder.java
@@ -48,7 +48,7 @@ public class TestMultipartPartBuilder {
final Header header = part.getHeader();
Assert.assertNotNull(header);
assertFields(Arrays.asList(
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header.getFields());
}
@@ -64,7 +64,7 @@ public class TestMultipartPartBuilder {
final Header header1 = part1.getHeader();
Assert.assertNotNull(header1);
assertFields(Arrays.asList(
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header1.getFields());
final FileBody fileBody = new FileBody(new File("/path/stuff.bin"), ContentType.DEFAULT_BINARY);
final MultipartPart part2 = builder
@@ -76,7 +76,7 @@ public class TestMultipartPartBuilder {
final Header header2 = part2.getHeader();
Assert.assertNotNull(header2);
assertFields(Arrays.asList(
- new MinimalField("Content-Type", "application/octet-stream")),
+ new MimeField("Content-Type", "application/octet-stream")),
header2.getFields());
}
@@ -98,13 +98,13 @@ public class TestMultipartPartBuilder {
Assert.assertNotNull(header1);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("header3", "blah"),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("header1", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("header3", "blah"),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header1.getFields());
final MultipartPart part2 = builder
@@ -117,9 +117,9 @@ public class TestMultipartPartBuilder {
Assert.assertNotNull(header2);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header2", "yada"),
- new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
+ new MimeField("header1", "blah"),
+ new MimeField("header2", "yada"),
+ new MimeField("Content-Type", "text/plain; charset=ISO-8859-1")),
header2.getFields());
final MultipartPart part3 = builder
@@ -133,21 +133,21 @@ public class TestMultipartPartBuilder {
Assert.assertNotNull(header3);
assertFields(Arrays.asList(
- new MinimalField("header1", "blah"),
- new MinimalField("header2", "yada"),
- new MinimalField("Content-Disposition", "disposition stuff"),
- new MinimalField("Content-Type", "type stuff"),
- new MinimalField("Content-Transfer-Encoding", "encoding stuff")),
+ new MimeField("header1", "blah"),
+ new MimeField("header2", "yada"),
+ new MimeField("Content-Disposition", "disposition stuff"),
+ new MimeField("Content-Type", "type stuff"),
+ new MimeField("Content-Transfer-Encoding", "encoding stuff")),
header3.getFields());
}
- private static void assertFields(final List<MinimalField> expected, final List<MinimalField> result) {
+ private static void assertFields(final List<MimeField> expected, final List<MimeField> result) {
Assert.assertNotNull(result);
Assert.assertEquals(expected.size(), result.size());
for (int i = 0; i < expected.size(); i++) {
- final MinimalField expectedField = expected.get(i);
- final MinimalField resultField = result.get(i);
+ final MimeField expectedField = expected.get(i);
+ final MimeField resultField = result.get(i);
Assert.assertNotNull(resultField);
Assert.assertEquals(expectedField.getName(), resultField.getName());
Assert.assertEquals(expectedField.getBody(), resultField.getBody());