GionJh
GionJh

Reputation: 2884

managing keep-alive http connection inside servlet

Suppose a browser makes a request
asking for the server to keep the connection alive
(connection: keep-alive).

And this request requires the invocation of a servlet.

Inside my servlet should I care to choose the best way to send data (chunked or indicating
the lenght of the body ) ??

if the server does that for me , why , inside my servlet ,
I'm able to modyfy headers like:
content-length
and transfer encoding ?

thanks

Upvotes: 0

Views: 2031

Answers (1)

irreputable
irreputable

Reputation: 45433

If you know the body length up front, you should set Content-Length header before writing body.

Otherwise do nothing; the servlet container should be able to automatically add Transfer-Encoding, and chunk-ify your body. That is subject to client/request version and Connection header.

Upvotes: 2

Related Questions