Content-type and file name is not set when media-Type is text/plain in Restlet framework

31 Views Asked by At

We are using Restlet framework. One of our implementation we use multi-part formdata request. While sending request with multipart formdata if the file extension is .txt (text/plain). In this case (text/plain) file name and media-Type is not set in FormDataSet.java class in Restlet framework. Not get javadoc or any reason why this scenario ignored file name and media-Type for (text/plain) ?

write method from FormDataSet.java

@Override
public void write(OutputStream outputStream) throws IOException {
    if (isMultipart()) {
        for (FormData data : getEntries()) {
            // Write the boundary line
            outputStream.write(("--" + getMultipartBoundary()).getBytes());
            HeaderUtils.writeCRLF(outputStream);

            // Write the optional content type header line
            if (MediaType.TEXT_PLAIN.equals(data.getMediaType())) {
                // Write the content disposition header line
                String line = "Content-Disposition: form-data; name=\""
                        + data.getName() + "\"";
                outputStream.write(line.getBytes());
                HeaderUtils.writeCRLF(outputStream);
            } else {
                // Write the content disposition header line
                String line = "Content-Disposition: form-data; name=\""
                        + data.getName() + "\"; filename=\""
                        + data.getFilename() + "\"";
                outputStream.write(line.getBytes());
                HeaderUtils.writeCRLF(outputStream);

                // Write the content type header line
                line = "Content-Type: "
                        + ContentType.writeHeader(data
                                .getValueRepresentation());
                outputStream.write(line.getBytes());
                HeaderUtils.writeCRLF(outputStream);
            }

            // Write the data content
            HeaderUtils.writeCRLF(outputStream);
            data.getValueRepresentation().write(outputStream);
            HeaderUtils.writeCRLF(outputStream);
        }

        // Write the final boundary line
        outputStream.write(("--" + getMultipartBoundary() + "--")
                .getBytes());
        HeaderUtils.writeCRLF(outputStream);
    } else {
        Representation formRep = new StringRepresentation(getQueryString(),
                MediaType.APPLICATION_WWW_FORM, null, CharacterSet.UTF_8);
        formRep.write(outputStream);
    }
}

I try to get any RFC or some detail why this special handling for text/plain, not getting.

It will be great, if I get any input on this why this special handling.

0

There are 0 best solutions below