Sébastien Demoustiez · Dec 14, 2017

Get a custom response server header with Cache


I'm using Cache 2016.

I try to get a property set in my server response header.

I tried to get it in %request and %response but without success ...

Some one have an idea ?

Here an example of what i try to get :

Thank you


0 868
Discussion (6)0
Log in or sign up to continue

To set any response header, you should overwrite OnPreHTTP method in your CSP Page class.

Class User.Page Extends %CSP.Page

ClassMethod OnPage() As %Status
  ; To do...
  Quit $$$OK

/// Event handler for <b>PreHTTP</b> event: this is invoked before
/// the HTTP headers for a CSP page have been sent. All changes to the
/// <class>%CSP.Response</class> class, such as adding cookies, HTTP headers,
/// setting the content type etc. must be made from within the OnPreHTTP() method.
/// Also changes to the state of the CSP application such as changing
/// %session.EndSession or %session.AppTimeout must be made within the OnPreHTTP() method.
/// It is prefered that changes to %session.Preserve are also made in the OnPreHTTP() method
/// as this is more efficient, although it is supported in any section of the page.
/// Return <b>0</b> to prevent <method>OnPage</method> from being called.
ClassMethod OnPreHTTP() As %Boolean [ ServerOnly = 1 ]
  Do %response.SetHeader("X-MyHeader", "some info")
  quit 1


Hello Dimitry,


You right I can access some response header in the OnPreHTTP with GetHeader.


But apparently i cant access to all my header variable, in my case I add a custom variable named SSLDN (server side) but I cant see it in %response ...





i'm with the same problem,

i receive a response in rest and want to take information from the response header. to imput information on request header ok, but to take the information from the response header is the problem.

Hi Sébastien,

i think the folowing will resolve your problem.

    set tSC = ..Adapter.Post(.httpResponse,,input.%ToJSON())
    quit:$$$ISERR(tSC) tSC

    set response = ##class(Drag.MSG.IdentificacaoResp).%New()
    set response.token= httpResponse.GetHeader("AUTH-TOKEN")

this way, you can get the property of header.