Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Can't change content-type in REST response

Question
James Westley-F... · Dec 7, 2021

Can't change content-type in REST response

I've never had a problem changing the content-type on a response using either %CSP.Page or %CSP.REST until now. No matter where I put the line to set the content-type to "application/json", it stubbornly emits a content-type of "text/html".

In OnPreHTTP: (I tried one at a time)
either
    do %response.SetHeader("content-type", "application/json") // didn't work
or

    set %response.ContentType = "text/plain" // didn't work

The same lines in OnProcessInput() didn't change the output content-type, either.

The class signature is 
Class HS.Local.VA.HS.DocRepo.Prefetch.Service.RESTService Extends (Ens.BusinessService, %CSP.REST)

I get the data I'm looking for back in JSON format the way I expected. My consuming app doesn't like the fact that content-type is always text/html.

I've written tons of CSP and never had a problem changing content-type. Not sure what's going on here.

Thanks in advance!!

Bill

#CSP #REST API #HealthShare
Product version: HealthShare 2019.1
$ZV: Cache for Windows (x86-64) 2018.1.2 (Build 309_5_19491U) Tue Dec 10 2019 17:30:27 EST

Source URL:https://community.intersystems.com/post/cant-change-content-type-rest-response