views:

29

answers:

1

I have written an Http Module that hooks onto the Response.Filter property of the current request and does various replacements within the HTML before it is sent to the client.

All the work is done in the Write method which is overriding Write in the base class Stream.

The Write method is called multiple times for a single response - the HTML seems to be written to the output stream in chunks. My problem is that I don't have an efficient & reliable way of telling if the current chunk is the last chunk (for why I want to know this see below). The only way I have come up with is to check if the chunk contains a closing html tag - but this is not very efficient or reliable.

The reason this is needed is that the module must add the "Refresh" HTTP header to the response, but only if the HTML fulfills certain conditions (and there are certain conditions that mean the header must not be added). So, only when the last chunk has been seen does the code know if the header can be added or not. So, I either need a test for the last chunk, or on each call to Write I add the header if the current block of HTML passes the test (if it has not already been added) or remove the header if the current block of HTML fails the test (if it has already been added).

So, is there a better way to test for the last chuck OR is there a way to test for a particular header being in the response and delete it (there doesn't seem to be a way to do this - only to append headers)?

Thanks

A: 

If you can figure out the total number of bytes to be written from your html source, then just count the bytes as you call Write() to figure out when you are writing the last chunk.

Also, you can't add headers after sending content to the browser. I think that if you avoid calling Flush() to actually send your output, you will be ok to add a header after writing your content.

Ray
Unfortunately I can't see a way to figure out the total bytes of content. All I can see in my Write method is the bytes of the current chunk.FYI, I have no problem adding a header.
Laurence
Does the source stream provide a length property?
Ray
Yes it does, however the stream is write-only and throws an exception as soon as you try to call any of the read methods. Should have mentioned this!I am not really sure why it is write-only (I am copying the idea for this module from some o/s code).
Laurence
The output stream is probably write-only, but what about eh input (source)? Where is the html coming from?
Ray