managing keep-alive http connection inside servlet

2019-08-20 09:56发布

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

1条回答
2楼-- · 2019-08-20 10:21

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.

查看更多
登录 后发表回答