Deprecated Content-Transfer-Encoding field in MIME body parts per RFC 7578, section 4.7

This commit is contained in:
Oleg Kalnichevski 2017-09-30 23:35:41 +02:00
parent a424709d89
commit f959d44ec7
8 changed files with 13 additions and 35 deletions

View File

@ -87,6 +87,7 @@ public String getCharset() {
} }
@Override @Override
@Deprecated
public String getTransferEncoding() { public String getTransferEncoding() {
return MIME.ENC_BINARY; return MIME.ENC_BINARY;
} }

View File

@ -76,7 +76,10 @@ public interface ContentDescriptor {
* Returns the body descriptors transfer encoding. * Returns the body descriptors transfer encoding.
* @return The transfer encoding. Must not be null, but "7bit", * @return The transfer encoding. Must not be null, but "7bit",
* if no transfer-encoding was specified. * if no transfer-encoding was specified.
*
* @deprecated Deprecated per RFC 7578, section 4.7. Do not use
*/ */
@Deprecated
String getTransferEncoding(); String getTransferEncoding();
/** /**

View File

@ -137,10 +137,6 @@ public FormBodyPart build() {
headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, buffer.toString())); headerCopy.addField(new MinimalField(MIME.CONTENT_TYPE, buffer.toString()));
} }
} }
if (headerCopy.getField(MIME.CONTENT_TRANSFER_ENC) == null) {
// TE cannot be null
headerCopy.addField(new MinimalField(MIME.CONTENT_TRANSFER_ENC, body.getTransferEncoding()));
}
return new FormBodyPart(this.name, this.body, headerCopy); return new FormBodyPart(this.name, this.body, headerCopy);
} }

View File

@ -34,6 +34,10 @@
public final class MIME { public final class MIME {
public static final String CONTENT_TYPE = "Content-Type"; public static final String CONTENT_TYPE = "Content-Type";
/**
* @deprecated Deprecated per RFC 7578, section 4.7. Do not use
*/
@Deprecated
public static final String CONTENT_TRANSFER_ENC = "Content-Transfer-Encoding"; public static final String CONTENT_TRANSFER_ENC = "Content-Transfer-Encoding";
public static final String CONTENT_DISPOSITION = "Content-Disposition"; public static final String CONTENT_DISPOSITION = "Content-Disposition";

View File

@ -51,8 +51,7 @@ public void testBuildBodyPartBasics() throws Exception {
Assert.assertNotNull(header); Assert.assertNotNull(header);
assertFields(Arrays.asList( assertFields(Arrays.asList(
new MinimalField("Content-Disposition", "form-data; name=\"blah\""), new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1"), new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
new MinimalField("Content-Transfer-Encoding", "8bit")),
header.getFields()); header.getFields());
} }
@ -71,8 +70,7 @@ public void testBuildBodyPartMultipleBuilds() throws Exception {
Assert.assertNotNull(header1); Assert.assertNotNull(header1);
assertFields(Arrays.asList( assertFields(Arrays.asList(
new MinimalField("Content-Disposition", "form-data; name=\"blah\""), new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1"), new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
new MinimalField("Content-Transfer-Encoding", "8bit")),
header1.getFields()); header1.getFields());
final FileBody fileBody = new FileBody(new File("/path/stuff.bin"), ContentType.DEFAULT_BINARY); final FileBody fileBody = new FileBody(new File("/path/stuff.bin"), ContentType.DEFAULT_BINARY);
final FormBodyPart bodyPart2 = builder final FormBodyPart bodyPart2 = builder
@ -87,8 +85,7 @@ public void testBuildBodyPartMultipleBuilds() throws Exception {
Assert.assertNotNull(header2); Assert.assertNotNull(header2);
assertFields(Arrays.asList( assertFields(Arrays.asList(
new MinimalField("Content-Disposition", "form-data; name=\"yada\"; filename=\"stuff.bin\""), new MinimalField("Content-Disposition", "form-data; name=\"yada\"; filename=\"stuff.bin\""),
new MinimalField("Content-Type", "application/octet-stream"), new MinimalField("Content-Type", "application/octet-stream")),
new MinimalField("Content-Transfer-Encoding", "binary")),
header2.getFields()); header2.getFields());
} }
@ -117,8 +114,7 @@ public void testBuildBodyPartCustomHeaders() throws Exception {
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-Disposition", "form-data; name=\"blah\""),
new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1"), new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
new MinimalField("Content-Transfer-Encoding", "8bit")),
header1.getFields()); header1.getFields());
final FormBodyPart bodyPart2 = builder final FormBodyPart bodyPart2 = builder
@ -134,8 +130,7 @@ public void testBuildBodyPartCustomHeaders() throws Exception {
new MinimalField("header1", "blah"), new MinimalField("header1", "blah"),
new MinimalField("header2", "yada"), new MinimalField("header2", "yada"),
new MinimalField("Content-Disposition", "form-data; name=\"blah\""), new MinimalField("Content-Disposition", "form-data; name=\"blah\""),
new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1"), new MinimalField("Content-Type", "text/plain; charset=ISO-8859-1")),
new MinimalField("Content-Transfer-Encoding", "8bit")),
header2.getFields()); header2.getFields());
final FormBodyPart bodyPart3 = builder final FormBodyPart bodyPart3 = builder

View File

@ -85,8 +85,6 @@ public void testInputStreamBody() throws Exception {
Assert.assertEquals("application", b1.getMediaType()); Assert.assertEquals("application", b1.getMediaType());
Assert.assertEquals("octet-stream", b1.getSubType()); Assert.assertEquals("octet-stream", b1.getSubType());
Assert.assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());
final InputStreamBody b2 = new InputStreamBody( final InputStreamBody b2 = new InputStreamBody(
new ByteArrayInputStream(stuff), ContentType.create("some/stuff"), "stuff"); new ByteArrayInputStream(stuff), ContentType.create("some/stuff"), "stuff");
Assert.assertEquals(-1, b2.getContentLength()); Assert.assertEquals(-1, b2.getContentLength());
@ -95,8 +93,6 @@ public void testInputStreamBody() throws Exception {
Assert.assertEquals("some/stuff", b2.getMimeType()); Assert.assertEquals("some/stuff", b2.getMimeType());
Assert.assertEquals("some", b2.getMediaType()); Assert.assertEquals("some", b2.getMediaType());
Assert.assertEquals("stuff", b2.getSubType()); Assert.assertEquals("stuff", b2.getSubType());
Assert.assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
} }
} }

View File

@ -140,7 +140,6 @@ public void testMultipartWriteTo() throws Exception {
Assert.assertEquals("--xxxxxxxxxxxxxxxxxxxxxxxx\r\n" + Assert.assertEquals("--xxxxxxxxxxxxxxxxxxxxxxxx\r\n" +
"Content-Disposition: multipart/form-data; name=\"test\"; filename=\"hello world\"\r\n" + "Content-Disposition: multipart/form-data; name=\"test\"; filename=\"hello world\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"hello world\r\n" + "hello world\r\n" +
"--xxxxxxxxxxxxxxxxxxxxxxxx--\r\n", out.toString(StandardCharsets.US_ASCII.name())); "--xxxxxxxxxxxxxxxxxxxxxxxx--\r\n", out.toString(StandardCharsets.US_ASCII.name()));
@ -167,7 +166,6 @@ public void testMultipartWriteToRFC7578Mode() throws Exception {
Assert.assertEquals("--xxxxxxxxxxxxxxxxxxxxxxxx\r\n" + Assert.assertEquals("--xxxxxxxxxxxxxxxxxxxxxxxx\r\n" +
"Content-Disposition: multipart/form-data; name=\"test\"; filename=\"hello%20%CE%BA%CF%8C%CF%83%CE%BC%CE%B5!%25\"\r\n" + "Content-Disposition: multipart/form-data; name=\"test\"; filename=\"hello%20%CE%BA%CF%8C%CF%83%CE%BC%CE%B5!%25\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"hello world\r\n" + "hello world\r\n" +
"--xxxxxxxxxxxxxxxxxxxxxxxx--\r\n", out.toString(StandardCharsets.US_ASCII.name())); "--xxxxxxxxxxxxxxxxxxxxxxxx--\r\n", out.toString(StandardCharsets.US_ASCII.name()));

View File

@ -75,19 +75,16 @@ public void testMultipartFormStringParts() throws Exception {
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field1\"\r\n" + "Content-Disposition: form-data; name=\"field1\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"this stuff\r\n" + "this stuff\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"\r\n" + "Content-Disposition: form-data; name=\"field2\"\r\n" +
"Content-Type: text/plain; charset=UTF-8\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"that stuff\r\n" + "that stuff\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field3\"\r\n" + "Content-Disposition: form-data; name=\"field3\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"all kind of stuff\r\n" + "all kind of stuff\r\n" +
"--foo--\r\n"; "--foo--\r\n";
@ -115,13 +112,11 @@ public void testMultipartFormCustomContentType() throws Exception {
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field1\"\r\n" + "Content-Disposition: form-data; name=\"field1\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"this stuff\r\n" + "this stuff\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"\r\n" + "Content-Disposition: form-data; name=\"field2\"\r\n" +
"Content-Type: stuff/plain; param=value\r\n" + "Content-Type: stuff/plain; param=value\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" + "\r\n" +
"that stuff\r\n" + "that stuff\r\n" +
"--foo--\r\n"; "--foo--\r\n";
@ -156,14 +151,12 @@ public void testMultipartFormBinaryParts() throws Exception {
"Content-Disposition: form-data; name=\"field1\"; " + "Content-Disposition: form-data; name=\"field1\"; " +
"filename=\"" + tmpfile.getName() + "\"\r\n" + "filename=\"" + tmpfile.getName() + "\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"; " + "Content-Disposition: form-data; name=\"field2\"; " +
"filename=\"file.tmp\"\r\n" + "filename=\"file.tmp\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo--\r\n"; "--foo--\r\n";
@ -201,21 +194,18 @@ public void testMultipartFormStrict() throws Exception {
"Content-Disposition: form-data; name=\"field1\"; " + "Content-Disposition: form-data; name=\"field1\"; " +
"filename=\"" + tmpfile.getName() + "\"\r\n" + "filename=\"" + tmpfile.getName() + "\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"; " + "Content-Disposition: form-data; name=\"field2\"; " +
"filename=\"test-file\"\r\n" + "filename=\"test-file\"\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" + "Content-Type: text/plain; charset=US-ASCII\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field3\"; " + "Content-Disposition: form-data; name=\"field3\"; " +
"filename=\"file.tmp\"\r\n" + "filename=\"file.tmp\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo--\r\n"; "--foo--\r\n";
@ -253,21 +243,18 @@ public void testMultipartFormRFC6532() throws Exception {
"Content-Disposition: form-data; name=\"field1\u0414\"; " + "Content-Disposition: form-data; name=\"field1\u0414\"; " +
"filename=\"" + tmpfile.getName() + "\"\r\n" + "filename=\"" + tmpfile.getName() + "\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"; " + "Content-Disposition: form-data; name=\"field2\"; " +
"filename=\"test-file\"\r\n" + "filename=\"test-file\"\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" + "Content-Type: text/plain; charset=US-ASCII\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field3\"; " + "Content-Disposition: form-data; name=\"field3\"; " +
"filename=\"file.tmp\"\r\n" + "filename=\"file.tmp\"\r\n" +
"Content-Type: application/octet-stream\r\n" + "Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n" + "\r\n" +
"some random whatever\r\n" + "some random whatever\r\n" +
"--foo--\r\n"; "--foo--\r\n";
@ -364,14 +351,12 @@ public void testMultipartFormStringPartsMultiCharsets() throws Exception {
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field1\"\r\n" + "Content-Disposition: form-data; name=\"field1\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n").getBytes(StandardCharsets.US_ASCII)); "\r\n").getBytes(StandardCharsets.US_ASCII));
out2.write(s1.getBytes(StandardCharsets.ISO_8859_1)); out2.write(s1.getBytes(StandardCharsets.ISO_8859_1));
out2.write(("\r\n" + out2.write(("\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"\r\n" + "Content-Disposition: form-data; name=\"field2\"\r\n" +
"Content-Type: text/plain; charset=KOI8-R\r\n" + "Content-Type: text/plain; charset=KOI8-R\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n").getBytes(StandardCharsets.US_ASCII)); "\r\n").getBytes(StandardCharsets.US_ASCII));
out2.write(s2.getBytes(Charset.forName("KOI8-R"))); out2.write(s2.getBytes(Charset.forName("KOI8-R")));
out2.write(("\r\n" + out2.write(("\r\n" +