I have a requirement where:
- A service opens an HTTP connection to Tomcat 10.x
- Sends a stream of bytes using Chunked Transfer Encoding (cannot change this behavior)
- The Tomcat application reads the stream in chunks, saving each chunk and its size separately, using CoyoteInputStrean
However, the current Chunked Transfer Encoding Tomcat implementation handles the whole decoding, discarding the chunk size, which I want to have access to.
I haven't found a way to override the default Chunked Transfer Encoding algorithm in Tomcat, in a way to have access to each chunk size and its bytes manually.
Exploring Tomcat source code, I found that:
- ChunkedInputFilter class handles the Chunked Transfer Encoding algorithm
- That class doesn't allow to access the chunk size somehow
- Http11Processor creates the ChunkedInputFilter class and adds it to its filter array
- AbstractHttp11Protocol creates the Http11Processor
From there, seems like I might be able to extend AbstractHttp11Protocol, create my own Processor, and somehow override the filter array, including my own version of ChunkedIinputFilter, similar to IdentityInputFilter, which seems not doing any special treatment to the byte stream, just returning as it is, keeping the data about chunk size.
The final expectation is Tomcat not processing the chunked transfer encoding, but my own code, upstream, using CoyoteInputStream, doing the processing, or somehow, Tomcat provides the chunk size of each chunk in the stream.
Is there any better option?