Written by

Question omer · Jan 15, 2025

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

Comments

Oliver Wilms · Jan 15, 2025

Did you try to use Postman to call your CSP?

0
omer  Jan 15, 2025 to Oliver Wilms

Yes but that's not what I am after, I want to access the data im about to send in my code, so i can modify it, and run additional code on it.

0
Robert Barbiaux · Jan 16, 2025

To see the content, the CSP Gateway has an HTTP trace facility, see  documentation.

To access the response just before it is sent back to client, override methods of %CSP.Page

0
omer  Jan 16, 2025 to Robert Barbiaux

I have tried overriding several of the Methods of CSP.Page, But it seems that %response comes empty.

0
omer  Jan 20, 2025 to Robert Barbiaux

The Traces won't do for me as i need to access the data before it is sent back to the client, Seeing the trace afterwards is not what im looking for...
Also I couldn't find any method on the CSP.Page that provide the data i am looking for..

0
Robert Cemper · Jan 20, 2025

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

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

Docs for StreamServer

That's where your stream is dumped to browser

0
omer  Jan 22, 2025 to Robert Cemper

and at what point will i be able to see the actual data? 
I checked the stream on the Post/Pre hyperEvent/Http functions on the CSP page class but couldn't get to the stream itself, 
it seems i need to find the exact point where the stream is loaded?

0
Enrico Parisi · Jan 22, 2025

There is no such a stream you are looking for.

Data is sent to the browser (via WEB Gateway and WEB Server) as you write it from your CSP page/application, IS NOT held in a stream and sent "at the end" (what's the end BTW?).

0
Robert Barbiaux · Jan 24, 2025

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%Strings sc = $$$OKtry {
    
    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 = 32768s 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.AbstractExceptions sc = $$$OKtry {
        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
}
0