public void parseArguments(String queryString) {
String[] parts = JOrphanUtils.split(queryString, "--" + getBoundary()); //$NON-NLS-1$
for (int i = 0; i < parts.length; i++) {
String contentDisposition = getHeaderValue("Content-disposition", parts[i]); //$NON-NLS-1$
String contentType = getHeaderValue("Content-type", parts[i]); //$NON-NLS-1$
// Check if it is form data
if (contentDisposition != null && contentDisposition.indexOf("form-data") > -1) { //$NON-NLS-1$
// Get the form field name
final String namePrefix = "name=\""; //$NON-NLS-1$
int index = contentDisposition.indexOf(namePrefix) + namePrefix.length();
String name = contentDisposition.substring(index, contentDisposition.indexOf("\"", index)); //$NON-NLS-1$
// Check if it is a file being uploaded
final String filenamePrefix = "filename=\""; //$NON-NLS-1$
if (contentDisposition.indexOf(filenamePrefix) > -1) {
// Get the filename
index = contentDisposition.indexOf(filenamePrefix) + filenamePrefix.length();
String path = contentDisposition.substring(index, contentDisposition.indexOf("\"", index)); //$NON-NLS-1$
if(path != null && path.length() > 0) {
// Set the values retrieved for the file upload
files.addHTTPFileArg(path, name, contentType);
}
}
else {
// Find the first empty line of the multipart, it signals end of headers for multipart
int indexEmptyLfCrLfLinePos = parts[i].indexOf("\n\r\n"); //$NON-NLS-1$
int indexEmptyLfLfLinePos = parts[i].indexOf("\n\n"); //$NON-NLS-1$
String value = null;
if(indexEmptyLfCrLfLinePos > -1) {
value = parts[i].substring(indexEmptyLfCrLfLinePos).trim();
}
else if(indexEmptyLfLfLinePos > -1) {
value = parts[i].substring(indexEmptyLfLfLinePos).trim();
}
this.addNonEncodedArgument(name, value);
}
}
}
}
This method allows a proxy server to send over the raw text from a
browser's output stream to be parsed and stored correctly into the
UrlConfig object. |