PDA

View Full Version : Using Deflate with HttpService


mdoubledragon
11-16-2009, 09:43 AM
Hi Guys,

My problem is not that something is not working. My problem is that something is working and I dont know why.

I am developing a flex app that fetches XML data from my servlet. I decided to use compression to reduce the message size and used deflate in the servlet. I also set the response content-type header to deflate.

On the flex side, I put in code to uncompress incoming data but kept getting exceptions. In a debugging session I found out that the incoming data (ResultEvent data) was coming as XML instead of binary which I expected.

I thought maybe my servlet deflate code is not correct, but running a test case using same code to save a file at local disk, I found out that it was indeed compressing data by more than 50%.

What I cannot figure out is if FlashPlayer reading the Deflate header and uncompressing incoming data before its populated in ResultEvent object or does FlashPlayer internally use browser request functionality and hence browser is uncompressing incoming data before sending it to FlashPlayer.

Doesn't make much sense asking this as long as things are working but I need to know whats happening here and if I have any dependency on the browser that I am using.

wvxvw
11-16-2009, 10:46 AM
Maybe your browser thinks it's g-zipped, and thus unzipping it even before it gets to Falsh? Best way to find that out - use either URLLoader or URLStream and see if that's not some framework feature. Because if it is, I'm not aware it :)

mdoubledragon
11-21-2009, 12:27 PM
It turns out that what I suspected was right. The browser indeed interferes if it sees that the incoming stream is compressed using a technology it supports (eg. DEFLATE). This could have been a useful feature except for the fact that it was working fine on Firefox but was giving errors in IE, plunging me back into the cross browser compatibility never ending war to escape which I started using Flex in the first place.

As the post above suggested, the best way to avoid this is to use URLLoader so that the data that reaches you is exactly what the server is sending you. Then you can uncompress it, which is a one-line task in AS3 for DEFLATE, and use it wherever you want.

Found this post helpful in my hunt for the answer:

http://www.ultrashock.com/forums/data-communication/gzip-compression-flash-player-ie6-nightmare-122911.html