Skip to content

Commit cac39fa

Browse files
committed
Fixed issue restlet#720, complete the content-type header with the right boundary parameter value when using multipart representations. Reported by xwen97.
1 parent 0982cf2 commit cac39fa

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

modules/org.restlet.ext.html/src/org/restlet/ext/html/FormDataSet.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ public boolean isMultipart() {
263263
*/
264264
public void setMultipart(boolean multipart) {
265265
this.multipart = multipart;
266+
if (this.multipart && getMultipartBoundary() == null) {
267+
this.multipartBoundary = DEFAULT_BOUNDARY;
268+
}
266269
setMediaType(createMultipartMediaType(getMultipartBoundary()));
267270
}
268271

@@ -273,7 +276,13 @@ public void setMultipart(boolean multipart) {
273276
* The boundary separating multipart entries.
274277
*/
275278
public void setMultipartBoundary(String boundary) {
276-
this.multipartBoundary = boundary;
279+
if (boundary != null) {
280+
this.multipartBoundary = boundary;
281+
setMultipart(true);
282+
} else {
283+
this.multipartBoundary = DEFAULT_BOUNDARY;
284+
}
285+
setMediaType(createMultipartMediaType(getMultipartBoundary()));
277286
}
278287

279288
@Override

modules/org.restlet.test/src/org/restlet/test/ext/html/FormTestCase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.io.IOException;
3737

3838
import org.restlet.data.CharacterSet;
39+
import org.restlet.data.MediaType;
3940
import org.restlet.ext.html.FormData;
4041
import org.restlet.ext.html.FormDataSet;
4142
import org.restlet.ext.html.internal.FormReader;
@@ -67,4 +68,33 @@ public void testParsing() throws IOException {
6768

6869
assertEquals(query, newQuery);
6970
}
71+
72+
/**
73+
* Tests the multipart content-type.
74+
*/
75+
public void testContentType() throws IOException {
76+
FormDataSet form = null;
77+
78+
form = new FormDataSet();
79+
form.setMultipart(true);
80+
assertTrue(form.getMediaType().equals(MediaType.MULTIPART_FORM_DATA,
81+
true));
82+
83+
form = new FormDataSet("test");
84+
assertTrue(form.isMultipart());
85+
assertTrue(form.getMediaType().equals(MediaType.MULTIPART_FORM_DATA,
86+
true));
87+
assertEquals(
88+
form.getMediaType().getParameters().getFirstValue("boundary"),
89+
"test");
90+
form = new FormDataSet();
91+
92+
form.setMultipartBoundary("test2");
93+
assertTrue(form.isMultipart());
94+
assertTrue(form.getMediaType().equals(MediaType.MULTIPART_FORM_DATA,
95+
true));
96+
assertEquals(
97+
form.getMediaType().getParameters().getFirstValue("boundary"),
98+
"test2");
99+
}
70100
}

0 commit comments

Comments
 (0)