-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Jose,
On 2/27/14, 1:29 PM, Jose María Zaragoza wrote: > 2014-02-27 17:24 GMT+01:00 Konstantin Kolinko > <knst.koli...@gmail.com>: >> 2014-02-27 18:31 GMT+04:00 Jose María Zaragoza >> <demablo...@gmail.com>: >>> >>> And what do you recommend to me for forcing to return a >>> Content-Type ? Some weird clients require it >>> >>> If I cannot do it with a Filter , where can I do it ? >>> >> >> You can do it in a Filter. >> >> As I said, 1. The header must be set before writing anything to >> the output stream. That is per HTTP/1.1 protocol. 2. The header >> must have correct value. >> >> How to implement that is up to you (do not expect me to teach you >> java programming, but maybe others here will do). >> >> If you do not know the length before response is generated, a >> solution can be to buffer the response before writing it out. >> >> Buffering can be done by writing an adapter around servlet >> response that replaces default output stream with a buffered one. >> The adapter can be implemented by extending >> javax.servlet.http.HttpServletResponseWrapper class. Some >> caching frameworks have filters that perform such buffering and >> caching. > > > Thanks. Finally, I did it with a servlet and it works > > I tried with a Filter and a HttpServletResponseWrapper. Long time > before asking here. And I wrapped the response output stream into a > FilterOutputStream , so I could count every byte written I got the > right content length . All OK and I was happy. But , when I tried > set the header with wrapper.setHeader("Content-Length", count ) , > and as you told me before, the response headers had already been > flushed ( i checked isCommited() ) I could modify output stream > data but I couldn't modify response headers. I don't understand but > it is Don't forget that you actually need to buffer the data. You can't just wrap the container's OutputStream (or Writer) in a FilterOutputStream - -- the bytes will flow through your stream (writer) back to the client while you are counting them. If you aren't using a big byte array (or something similar), then you aren't buffering. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJTD56OAAoJEBzwKT+lPKRYQ2EP/2FySYxzV177T3YB6Mf+7+ss a9DGruZmfJ8EsD21qOO+qjnNOs7pc6sBHGjpCFRDzVut7hhAUzNJVXsVr/bUKzVg fzrwFCEb+EDmE2fNdVjpDeP16HPOqzfBGwgSltNpYg40q0XXXwDdnZA8xDwUHwib Iqdz7CJnZj6+5jiSMKOwFunEbC4d3U706/8AbgpUfScNQF9K+sNjwQfgEPQWtudb IMF2n48Fm4MTfid+UQgQI5XGM9xFhLf+owPYTWyb+bO13ooLyCL8YFMBAKTSumfm 9HSojPOGz7cNOtUZjwIdCNtrcog6sZFoiAJ27Kxgs5qNPH8wMYkkrXMN28sI44A+ MG+8EICHcjRqP+e4Vb8wgb5jJwwK7Sqt5/DqFtNn/xv1m8ISCIe0pl9rgqYAfd5d QtoNDhjW/V9aG+uhaYCHxEwSrVgscnuun04T49NK/Z4QsswerHmsDHSs79JXr8YW iRjRj3GWpet5NTZ/k6WvO/5aw24uuk9OD+GMWpFAk3zmYOIh0CVE1WeVbHUXjUyo mFZm4wxU3ccmQk2vqCoXqX5RVuaApMmc2M1wl+A5jzAqxwPWyBkPrQNg/k0SZ0/2 MSYG+qftA8sqF1v1Ydpb4U+hfNUXCKeatQY38rn43wXmEVkw/UOPtJQ8f3fAUFuL 7OHvXmOo/R3gE9cndILK =pOC4 -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org