It seems HeaderFlushedOutputStream is writing headers to response every time. This is the reason why resteasy.plugins.providers.InputStreamProvider is writing headers before every single byte with multipart/form-data output media type. Imho HeaderFlushedOutputStream should write headers only once.
Suggested fix: add a flag to HeaderFlushedOutputStream
<pre>
private MultivaluedMap<String, Object> headers;
+ private boolean headersFlushed;
private OutputStream stream;
/* ... */
protected void flushHeaders() throws IOException
{
+ if (headersFlushed)
+ return;
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
for (String key : headers.keySet())
{
List<Object> objs = headers.get(key);
for (Object obj : objs)
{
String value;
RuntimeDelegate.HeaderDelegate headerDelegate = delegate.createHeaderDelegate(obj.getClass());
if (headerDelegate != null)
else
{ value = obj.toString(); } stream.write(key.getBytes());
stream.write(": ".getBytes());
stream.write(value.getBytes());
stream.write("\r\n".getBytes());
}
}
stream.write("\r\n".getBytes());
+ headersFlushed = true;
}
</pre>
The issue came up with the following example.
POJO:
<pre>
public class MyBean {
@FormParam("someBinary")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private InputStream someBinary;
/* ... */
}
</pre>
Service:
<pre>
@GET
@Produces(MediaType.MULTIPART_FORM_DATA)
public @MultipartForm
MyBean createMyBean()
</pre>
part of output:
--f231sldkxx11
Content-Length: -1
Content-Disposition: form-data; name="someBinary"
Content-Type: application/octet-stream
bContent-Length: -1
Content-Disposition: form-data; name="someBinary"
Content-Type: application/octet-stream
lContent-Length: -1
Content-Disposition: form-data; name="someBinary"
Content-Type: application/octet-stream
a
As you can see "bla" is written in 3 parts with full headers of every byte. With the above mentioned fix the result get to normal:
--f231sldkxx11
Content-Length: -1
Content-Disposition: form-data; name="someBinary"
Content-Type: application/octet-stream
bla