Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Preventing chunked encoding?

Hi,

On Sat, Apr 25, 2015 at 11:26 AM, Guus der Kinderen
<guus.der.kinderen@xxxxxxxxx> wrote:
> Hi,
>
> I'm using WriteListener to send data from a Jetty 9.2.9 based Servlet in a
> response. Chunked encoding must be prevented. To do so, the buffer size of
> the response is set to match the length of the data. This appears to work
> for smaller packets, but larger packets (larger dan 20-something kilobytes)
> cause chunked encoding to re-appear. How do I prevent this?
>
> static class WriteListenerImpl implements WriteListener {
>
>     private final AsyncContext context;
>     private final byte[] data;
>
>     public WriteListenerImpl(AsyncContext context, byte[] data) {
>         this.context = context;
>         this.data = data;
>     }
>
>     @Override
>     public void onWritePossible() throws IOException {
>         context.getResponse().setBufferSize(data.length);
>         context.getResponse().getOutputStream().write(data);
>         context.complete();
>     }
> }

Calling response.setContentLength(data.length) should do it.

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.


Back to the top