Determine page size via HttpModule

It’s easy for you here:

I am currently registering a request for a request duration with an HttpModule, and I would like to know the number of bytes on each page.

HttpContext.Current.Response.OutputStream.Length throws a NotSupportedException .

What is an easy way to do this?

+4
source share
1 answer

I have an HttpModule that implements a rewrite stream. This comes from the Stream class. In my HttpModule, I have the following code:

 void app_PreRequestHandlerExecute(object sender, EventArgs e) { HttpResponse response = HttpContext.Current.Response; response.Filter = new MyRewriterStream(response.Filter); } 

In the stream class, I have the following code that overrides the default recording method:

 public override void Write(byte[] buffer, int offset, int count) { string outStr; outStr = UTF8Encoding.UTF8.GetString(buffer, offset, count); //Do useful stuff and write back to the stream } 

You can just take the length of the string at the second point

+3
source

Source: https://habr.com/ru/post/1276611/


All Articles