-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jose,

On 2/27/14, 3:22 PM, Christopher Schultz wrote:
> 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.

You may be interested in this thread from 2009:
http://markmail.org/thread/fumpfuspt7a3nesz

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTD58JAAoJEBzwKT+lPKRYFeEP/RYqIt/69O/nBEI807rWvVKC
OGF2Cc41TwGpI2FG8H5BEvFUQNYBm3+Jjh7keN1kOdfvmKsGGpATFcVg3qnaDr22
qdT//2cUfARaCG3YrEyV02YTGH5aFuVPY9bM5qG4we2KSYwxeUlB150jWu/wRPLt
8VZnJmAuxUWkNqX0HnzT6P8k53npQhK7kT8Dj+pbHIfKfnJeU98BCUsDvbRHPCgJ
WRlDsEqzfOmSLM8pWKXv2NTu+cNcCf9mfEuNMyFFb35ySNnbq0Mo9ndCIRIUTKQL
jRhzLuKrpWDY+XnTADvT+IBkw6rSg9GWfchdfGi5m/RtNVpz09YdpFp4KcIPUdrb
okf4hPyCbdPGm1Rm0YDTiwxjZOtNjClnIQ+WEWuOxR49C1BYhAIclYNzJ87sWnwk
iQRteRTU+fcMLMvG1azS53jiiQsmndFIzQFJ53szIDmU8F08oybJG14IQI7nJP1l
wmQCf4yTTDKJijw1lO9z79mpi7CRaZr6vgPWV7y9+d/H9KyRXutjSafABG+iUB7I
9vTF+85AI0FX1OV5CA6te7eBqNrvwrzSreCSyXLuEJvqprhXtb+3XQApj8N3ml90
g6h7GfRnP8xwuiIs2MmMowoZ3JdtK44IjRkI/gKNwNvXlmKCSAM8m6tF5g32Bkuf
geCSTdZxgOTq/2NpUFfA
=XcJc
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to