* Note that if this is application/x-www-form-urlencoded, it will come out as
* params, whereas if it is multipart/form-data it will be separated into buckets.
*/
private void parseMultiPartData() throws IOException {
InputStream is = null;
LineReadingInputStream lis = null;
OutputStream bucketos = null;
try {
if(data == null)
return;
String ctype = this.headers.get("content-type");
if(ctype == null)
return;
if(logMINOR)
Logger.minor(this, "Uploaded content-type: " + ctype);
String[] ctypeparts = ctype.split(";");
if(ctypeparts[0].equalsIgnoreCase("application/x-www-form-urlencoded")) {
// Completely different encoding, but easy to handle
if(data.size() > 1024 * 1024)
throw new IOException("Too big");
byte[] buf = BucketTools.toByteArray(data);
String s = new String(buf, "us-ascii");
parseRequestParameters(s, true, true);
}
if(!ctypeparts[0].trim().equalsIgnoreCase("multipart/form-data") || (ctypeparts.length < 2))
return;
String boundary = null;
for(String ctypepart: ctypeparts) {
String[] subparts = ctypepart.split("=");
if((subparts.length == 2) && subparts[0].trim().equalsIgnoreCase("boundary"))
boundary = subparts[1];
}
if((boundary == null) || (boundary.length() == 0))
return;
if(boundary.charAt(0) == '"')
boundary = boundary.substring(1);
if(boundary.charAt(boundary.length() - 1) == '"')
boundary = boundary.substring(0, boundary.length() - 1);
boundary = "--" + boundary;
if(logMINOR)
Logger.minor(this, "Boundary is: " + boundary);
is = this.data.getInputStream();
lis = new LineReadingInputStream(is);
String line;
line = lis.readLine(100, 100, false); // really it's US-ASCII, but ISO-8859-1 is close enough.
while((is.available() > 0) && !line.equals(boundary)) {
line = lis.readLine(100, 100, false);
}
boundary = "\r\n" + boundary;
RandomAccessBucket filedata = null;
String name = null;
String filename = null;
String contentType = null;
while(is.available() > 0) {
name = null;
filename = null;
contentType = null;
// chomp headers
while((line = lis.readLine(200, 200, true)) /* should be UTF-8 as we told the browser to send UTF-8 */ != null) {
if(line.length() == 0)
break;
String[] lineparts = line.split(":");
if(lineparts == null || lineparts.length == 0)