Question
Mike Yackanich · May 14

How do you add a HTTP Header within HS.FHIRServer.Interop.HTTPOperation business operation?

I have an interoperability production that functions as a FHIR proxy. I have a need to add an HTTP Header value to the outbound request. I've subclassed HS.FHIRServer.Interop.HTTPOperation, but I cannot find a way to add an HTTP Header to the request. The HTTP class used in HS.FHIRServer.Interop.HTTPOperation is HS.FHIRServer.RestClient.HTTP. That RestClient class does not seem to expose or allow modification of the actual HttpRequest.

I'm used to using %Net.HttpRequest and doing a request.SetHeader(key, value) - but that isn't available - or I can't find it - when using HS.FHIRServer.Interop.HTTPOperation.

I'm practically certain this can be done. What am I overlooking?

Product version: IRIS 2020.4
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2020.4 (Build 524U) Thu Oct 22 2020 13:05:03 EDT
00
1 0 3 78
Log in or sign up to continue

I haven't tested the code below, but in your subclass you can override MakeRequest(), call the original superclass version of MakeRequest() and then you should be able to set the header before returning from your custom method.

Something like this:

Method MakeRequest(pRequestMethod As %String, pPayload, pRequestPath As %String, pQueryString As %String, ByRef pHeaders) As %RegisteredObject
{
    set ..%HttpRequest = ##super(pRequestMethod, pPayload, pRequestPath, pQueryString, .pHeaders)
    do ..%HttpRequest.SetHeader("Some Header Name", "Some Header Value")
    return ..%HttpRequest
}

Hi Marc,

Thanks for the feedback. Would that have the same effect as the following - which I have already tested?

do ..HttpClient.%HttpRequest.SetHeader("x-api-key", ApiKeyToUse)

When I attempt this I get "ObjectScript error: PRIVATE PROPERTY" because within HS.FHIRServer.RestClient.HTTP the HttpRequest object is defined as:

Property %HttpRequest As %Net.HttpRequest [ Private ];

Just to bring closure to this, I opened a WRC, and ISC has acknowledged that it is currently not possible to add an HTTP Header within HS.FHIRServer.Interop.HTTPOperation. Snippet of ISC feedback is below:

"I do not see a built in way to get the desired functionality. From what I can tell, the headers get set in the MakeRequest argument of the HS.FHIRServer.RestClient.HTTP. This field accepts a headers argument of a multidimensional array (header("abc")=123). This method is invoked by the MakeRequestAndInvoke method of HS.FHIRServer.RestClient.Base, which HS.FHIRServer.RestClient.HTTP extends. MakeRequestAndInvoke appears to be the method that we call based upon most if not all requests to finally create the HTTP Request and send it (httpClient.Batch, httpClient.History, httpClient.VRead, etc.). The problem is that the callers (httpClient.Batch, etc.) are called without a way to specify headers for MakeRequestAndInvoke. MakeRequest in HS.FHIRServer.RestClient.HTTP is where the request is finally created and headers are added. MakeRequestAndInvoke is usually a stripped down method that does some error checking and then calls MakeRequest() And Invoke().

Development has reviewed this issue and has added it to their development plan. Once it has a target version date, I will let you know so that you may know around when the change will been added to our product."