spring-webflow
spring-webflow copied to clipboard
restTemplate Multipart Request sends undesired headers for each part. [SWF-1732]
Siavash Arya opened SWF-1732 and commented
I'm sending a Multipart request with RestTemplate and I realized that it include 3 headers for each part:
Forexample:
Content-Disposition: form-data; name="body" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit
My body
This causes problems on the server that I'm trying to call. For some reason the server returns 500 each time I have Content-Type and Content-Transfer-Encoding included in the parts.
For now I solved this like this:
I copied a class from FormHttpMessageConverter and modified the private class MultipartHttpOutputMessage to ignore other headers in the writeHeaders method. private void writeHeaders() throws IOException { if (!this.headersWritten) { for (Map.Entry<String, List<String>> entry : this.headers.entrySet()) { if (!entry.getKey().equals("Content-Disposition")) continue; byte[] headerName = getBytes(entry.getKey()); for (String headerValueString : entry.getValue()) { byte[] headerValue = getBytes(headerValueString); this.outputStream.write(headerName); this.outputStream.write(':'); this.outputStream.write(' '); this.outputStream.write(headerValue); writeNewLine(this.outputStream); } } writeNewLine(this.outputStream); this.headersWritten = true; } }
But there should be a better way.
Affects: 2.1.1