Question
· Jan 15

Where and How can i see the Stream that contains the response back to the client of a CSP application

Hey, So the title pretty much describes the question:
Where and How can i see the Stream that contains the response back to the client of a CSP application.

When the request is being processed and finished we return a response to the client - We do that by writing the data to a stream and that stream is sent back to the client.
I wanted to know how i can access the point right before that Data is actually written to the client back (meaning the place where the response is actually being send back, the last point of contact).
And was not able to find about it in the DOCS so would love to get a reference to it if you know where.

Product version: IRIS 2020.3
Discussion (9)2
Log in or sign up to continue

As you refer to CSP combined with a Steam I assume
you have some similar sequence in you CSP page

<p align="center">
<!-- The trick is the use the encrypted oid of the stream as the STREAMOID parameter to the stream server -->
<image src="%25CSP.StreamServer.cls?STREAMOID=#(..Encrypt(oid))#">
</p>

Docs for StreamServer

That's where your stream is dumped to browser

You can override the Page() method of %CSP.Page and redirect output to a stream, process the resulting stream and write it to the original device the page is using to send data back to client.

Here is a quick and dirty example, using IO-Redirect package available on OpenExchange.

The redirecting page : 

Class test.src.RedirectedPage Extends %CSP.Page
{

ClassMethod Page(skipHeader As %Boolean = 1) As %Status [ ServerOnly = 1 ]
{
    #dim sc as %Status
    #dim ex as %Exception.AbstractException
    #dim pageStream,processedPageStream As %Stream.Object
    #dim len as %Integer
    #dim buffer as %String
    
    s sc = $$$OK
    try {
    
    Set pageStream = ##class(%Stream.GlobalCharacter).%New()
    Do ##class(IORedirect.Redirect).ToStream(pageStream)
    $$$TOE(sc,##super(skipHeader))
    Do ##class(IORedirect.Redirect).RestoreIO()
    Set pageStream = ##class(IORedirect.Redirect).Get()
    $$$TOE(sc,..ProcessPageStream(pageStream,.processedPageStream))
    while 'processedPageStream.AtEnd {
        s len = 32768
        s buffer = processedPageStream.Read(.len,.sc)
        $$$TOE(sc,sc)
        write buffer
    }
    } catch (ex) {
      s sc = ex.AsStatus()
    }
    return sc
}

ClassMethod ProcessPageStream(pageStream As %Stream.Object, Output processedPageStream As %Stream.Object) As %Status
{
    #dim sc as %Status
    #dim ex as %Exception.AbstractException
    s sc = $$$OK
    try {
        s processedPageStream = ##class(%Stream.TmpCharacter).%New()
        $$$TOE(sc,processedPageStream.CopyFrom(pageStream))
        d processedPageStream.Write("<div><span>original page had "_pageStream.Size_" bytes </span></div>")
    } catch (ex) {
      s sc = ex.AsStatus()
    }
    return sc
}

}

The original page :

Class test.src.OriginalPage Extends test.src.RedirectedPage
{

ClassMethod OnPage() As %Status [ ServerOnly = 1 ]
{
    &html<
        <div>
         <span>Hello, world, again</span>
        </div>
    >
    return $$$OK
}