http return content-length header and the Transfer-Encoding: chunked problem doubts

First talk about the background of the problem: the
        company's server and mobile client interaction, client requests a dynamically generated XML file, http response headers in view when using firebug, sometimes found in content-length attribute, sometimes you do not have this property , replaced Transfer-Encoding: chunked property. Because the client mandates, the server must return content-length, otherwise, the client will not be resolved. So the test found that when the XML file is very small when there is a content-length attribute, to reach a value, it becomes Tansfer-Encoding: chunked.

And then quote a paragraph, explain Transfer-Encoding: chunked this property sense:
        usually, HTTP protocol using the Content-Length inform the head length of the data. Then, in the course of the downlink data, Content-Length way to pre-cache all data on the server, then all the data and then children will fall to the client.
    If you want to generate the data side, the side to the client, WEB server will need to use the "Transfer-Encoding: chunked" in such a way to replace the Content-Length.

Finally talk about their own understanding and solution:
        By all indications, I concluded that, JSP page has a cache size, when the length of the output data did not reach this size, the server is to know the total length of the data, so The server output content-length header. However, if more than the size of the cache, then a cache is full, you have to output the content server to the client, therefore, can not determine the size of the entire contents, then return Transfer-Encoding: chunked this header information.
        Solution is: join the code, response.setBufferSize (402800) in the JSP page; 40820 ie 400K, in fact, as long as this value is greater than the size of the data that you returned on the line. How many specific settings, you can according to the actual situation, the rational allocation. Also to say, to join in the page directive buffer = "400kb", but to no avail, I tested the situation is this.

Guess you like

Origin www.cnblogs.com/Koaler/p/12045412.html