I'm searching for weeks now to find a solution how to use chunked transfer encoding in a Java client without coding my own myHttpURLConnection
.
The HttpUrlConnection
of Java expects a fixed chunk size, which is not usable for me. The data consists of several messages that are different in size and must be sent in neartime to the server. The system currently (in Prelive/UAT state) works based on having fixed 1024 byte
chunks but since most messages are significantly shorter, this is a waste of band width not acceptable in PROD.
Furthermore, messages larger than 1024 bytes
would be chopped apart so a) the server would need to assemble them again and b) the last part of the message would not be send until enough data is available for filling 1024 bytes
(even worse, not neartime anymore).
Does anybody have an idea how to workaround the restriction of the HttpUrlConnection
of Java (non compliant with RFC2616 as it does not fully implement it) without having to code everything on top of URLConnection
?
I did not find any possibility to hook into the needed funcs for just setting a new chunk size for each heap of data.
My current option: douplicate all HTTPUrlConnection
code and modify the parts dealing with CHUNKED (e.g. having some flush() function to adjust the chunk size and send what's there).