HTTPCLIENT-2065: Simplify additon of content type parameters in MultipartEntityBuilder
This closes #320
This commit is contained in:
parent
af2cc82e82
commit
d2c59fd5e4
|
@ -112,6 +112,17 @@ public class MultipartEntityBuilder {
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Add parameter to the current {@link ContentType}.
|
||||||
|
*
|
||||||
|
* @param parameter The name-value pair parameter to add to the {@link ContentType}.
|
||||||
|
* @return the {@link MultipartEntityBuilder} instance.
|
||||||
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
public MultipartEntityBuilder addParameter(final BasicNameValuePair parameter) {
|
||||||
|
this.contentType = contentType.withParameters(parameter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MultipartEntityBuilder setCharset(final Charset charset) {
|
public MultipartEntityBuilder setCharset(final Charset charset) {
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
|
|
|
@ -120,6 +120,20 @@ public class TestMultipartEntityBuilder {
|
||||||
entity.getContentType());
|
entity.getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMultipartCustomContentTypeUsingAddParameter() {
|
||||||
|
final MultipartEntityBuilder eb = MultipartEntityBuilder.create();
|
||||||
|
eb.setMimeSubtype("related");
|
||||||
|
eb.addParameter(new BasicNameValuePair("boundary", "yada-yada"));
|
||||||
|
eb.addParameter(new BasicNameValuePair("charset", "ascii"));
|
||||||
|
eb.addParameter(new BasicNameValuePair("my", "stuff"));
|
||||||
|
eb.buildEntity();
|
||||||
|
final MultipartFormEntity entity = eb.buildEntity();
|
||||||
|
Assert.assertNotNull(entity);
|
||||||
|
Assert.assertEquals("multipart/related; boundary=yada-yada; charset=US-ASCII; my=stuff",
|
||||||
|
entity.getContentType());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipartWriteTo() throws Exception {
|
public void testMultipartWriteTo() throws Exception {
|
||||||
final String helloWorld = "hello world";
|
final String helloWorld = "hello world";
|
||||||
|
|
Loading…
Reference in New Issue