Fog Creek Software
Discussion Board

Question:Intercept Response object

---- Plain old ASP on IIS 5.0 . 
Anyone having a good idea on how to intercept the Response ( it is buffered of course) and do some pos-processing before sending the stream to the user agent ?

I know I can do that (anything !) in a filter, but I would like not to. No filters... Any ideas ?
Thanks !

Joe Desperado
Friday, May 7, 2004

Do you want to post-process the output for each "packet" you send at
the client or for the whole page? For the whole page, it's quite
trivial, just concatenate a String with your output and use
Response.Write at the end with your concatened String. In the other
case, here is a code that might do it. My ASP is rusty, but that could
help you...

' ---------------------- BEGIN USUAL WAY ------------------------------
Dim I
While ( I < 1000 ) Then
  Response.Write "1234567890"
  I = I + 1
'----------------------- END USUAL WAY --------------------------------


' ---------------------- BEGIN YOUR WAY -------------------------------
Function PostProcessingFunction(DaString)
  PostProcessingFunction = foo(DaString)
End Function

Class ResponseIntercepter
  Dim str
  Dim countToBuff

  Sub Class_Initialize
    str = ""
    countToBuff = 0
  End Sub

  Sub Class_Finalize
    Response.Write str
  End Sub

  Sub Write(DaString)
    str = str & DaString
    countToBuff = countToBuff + Len(DaString)
    If (countToBuff > 1024) Then
      Response.Write PostProcessingFunction(str)
      str = ""
      countToBuff = 0
    End If
  End Sub
End Class

Dim I
Dim DaResponseIntercepter
Set DaResponseIntercepter = New ResponseIntercepter

I = 0
While (I < 1000 )
  DaResponseIntercepter.Write "1234567890"
  I = I + 1
Set DaResponseIntercepter = Nothing
'----------------------- END YOUR WAY ---------------------------------

Saturday, May 8, 2004

Thank you, Anonymouche !

Yes, I want to "churn" the whole content, but ...
I don't think I asked the question clearly enough though: I don't want to break the encapsulation at all ... The scripts that produce the content are to be a black box.
What I want to do is to apply some transformation after the content has been generated.
+------------+                              +------------------------+
|  Adaptor |  ---- invoke ------> | Content Generator|
+------------+                              +------------------------+

Where previoulsy, the Content Generator was shipping directly to the browser.
After playing a bit wih all the approaches I found 2 possible ways of doing this:

1. use an HTTP client of any sort to query C.G., grab the  content, "churn"  and ship back.

2. With a Server.Execute (CG.asp)

Still have to polish both of these two to figure I do the right job :-)

Joe Desperado
Saturday, May 8, 2004

*  Recent Topics

*  Fog Creek Home