Last post Dec 24, 2008 08:55 PM by mbanavige
Dec 24, 2008 04:40 PM|Yovav|LINK
I'm working on a HTTP compression module and I wonder how can I detect the size of the page content befiore I compress it,
So for example - I can choose to only compress pages with content smaller than 5Kb
Any ideas ?
Dec 24, 2008 05:39 PM|mbanavige|LINK
it could be done with a Filter
check this thread: http://forums.asp.net/t/1052902.aspx
Dec 24, 2008 06:02 PM|Yovav|LINK
Thanks for the reference,
However, I'm using HttpApplication.PostReleaseRequestState to compress
(its too late to do it on EndRequest)
I also prefer not to read the whole response before deciding if I should compress it or not,
Was hoping to find a way to read the length from a pointer to the response (or something :-)
Dec 24, 2008 08:05 PM|mbanavige|LINK
The HttpResponseStream does not support a length and will throw an exception if you try to access its length property. Using the technique i linked to, you should be able to check the amount of data that's been written to the response stream [so far] at
any point in the page lifecycle.
I'll assume that you meant in your first post that you were going to try to avoid compressing very small files? Before you add this extra step (and the overhead it entails) to your compression process, you might want to see if you can find a way to determine
if it will actually provide you with any benefit.
Also, there are some compression modules available for download. The most common one i've seen is the one from Ben Lowery:
This might be a usefull read for you as well:
Dec 24, 2008 08:47 PM|Yovav|LINK
Yes, I saw that one - its very nice but I like to make mine even better supporting the following features:
Anyway, it would be nice also to only compress streams bigger than X instead of including all the smaller files,
I guess I'll add that once I figure this out (dont wanna read the whole stream to detrmine its size...)
Dec 24, 2008 08:55 PM|mbanavige|LINK
dont wanna read the whole stream to detrmine its size...
since the response stream does not have a size, the only way to know its current size is to track what's been written to it so far.