Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restTemplate Multipart Request sends undesired headers for each part. [SWF-1732] #907

Open
spring-operator opened this issue Dec 12, 2018 · 0 comments
Labels
in: integration status: waiting-for-triage We need additional information before we can continue

Comments

@spring-operator
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: integration status: waiting-for-triage We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

1 participant