Merge remote-tracking branch 'origin/jetty-8'
This commit is contained in:
commit
4befd6395b
|
@ -464,7 +464,11 @@ public class MultiPartInputStream
|
|||
if (!_tmpDir.exists())
|
||||
_tmpDir.mkdirs();
|
||||
|
||||
String boundary="--"+QuotedStringTokenizer.unquote(value(_contentType.substring(_contentType.indexOf("boundary=")), true).trim());
|
||||
String contentTypeBoundary = "";
|
||||
if (_contentType.indexOf("boundary=") >= 0)
|
||||
contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(_contentType.indexOf("boundary=")), true).trim());
|
||||
|
||||
String boundary="--"+contentTypeBoundary;
|
||||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
||||
|
||||
// Get first boundary
|
||||
|
|
|
@ -35,6 +35,8 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
|
@ -90,6 +92,66 @@ public class MultiPartInputStreamTest
|
|||
}
|
||||
|
||||
|
||||
public void testNoBoundaryRequest()
|
||||
throws Exception
|
||||
{
|
||||
String str = "--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"fileName\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"abc\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"desc\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"123\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"title\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"ttt\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"datafile5239138112980980385.txt\"; filename=\"datafile5239138112980980385.txt\"\r\n"+
|
||||
"Content-Type: application/octet-stream; charset=ISO-8859-1\r\n"+
|
||||
"Content-Transfer-Encoding: binary\r\n"+
|
||||
"\r\n"+
|
||||
"000\r\n"+
|
||||
"----\r\n";
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStream mpis = new MultiPartInputStream(new ByteArrayInputStream(str.getBytes()),
|
||||
"multipart/form-data",
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
Collection<Part> parts = mpis.getParts();
|
||||
assertThat(parts.size(), is(4));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Part fileName = mpis.getPart("fileName");
|
||||
assertThat(fileName, notNullValue());
|
||||
assertThat(fileName.getSize(), is(3L));
|
||||
IO.copy(fileName.getInputStream(), baos);
|
||||
assertThat(baos.toString("US-ASCII"), is("abc"));
|
||||
|
||||
baos = new ByteArrayOutputStream();
|
||||
Part desc = mpis.getPart("desc");
|
||||
assertThat(desc, notNullValue());
|
||||
assertThat(desc.getSize(), is(3L));
|
||||
IO.copy(desc.getInputStream(), baos);
|
||||
assertThat(baos.toString("US-ASCII"), is("123"));
|
||||
|
||||
baos = new ByteArrayOutputStream();
|
||||
Part title = mpis.getPart("title");
|
||||
assertThat(title, notNullValue());
|
||||
assertThat(title.getSize(), is(3L));
|
||||
IO.copy(title.getInputStream(), baos);
|
||||
assertThat(baos.toString("US-ASCII"), is("ttt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonMultiPartRequest()
|
||||
throws Exception
|
||||
|
|
Loading…
Reference in New Issue