DataPower

 View Only
Expand all | Collapse all

I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from Response sent to client

  • 1.  I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from Response sent to client

    Posted Tue March 14, 2023 04:18 PM

    I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from the response for a service.

    I tried the following methods in the assembly but they didnt work. 

    Javascript :

    hm.current.remove('Access-Control-Allow-Origin');

    XSLT:

    <dp:remove-http-response-header name="Access-Control-Allow-Origin"/>



    ------------------------------
    Kshitij Khanna
    ------------------------------


  • 2.  RE: I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from Response sent to client

    IBM Champion
    Posted Tue March 14, 2023 06:19 PM

    Have you tried in GWS:

          

    
    

    var apim = require('./apim.custom.js');

    ....

    apim.setvariable('message.headers.Access-Control-Allow-Origin', 'null', 'clear');



    ------------------------------
    Joseph Morgan
    ------------------------------



  • 3.  RE: I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from Response sent to client

    Posted Fri March 17, 2023 02:55 PM

    Hi 2 things: can I ask why you would need to remove those headers?

    Also, i am not sure if that is possible in the apigw but if necessary you could remove them using a proxy mpgw sitting between the apigw & the client.



    ------------------------------
    Matthias Siebler
    MA
    ------------------------------



  • 4.  RE: I want to remove the CORS Headers - Access-Control-Allow-Origin & Access-Control-Allow-Methods from Response sent to client

    IBM Champion
    Posted Mon March 20, 2023 08:40 AM

    Hi,

    I have always thought that the easiest way to strip headers is to use Header suppression config under Headers tab. This goes for Multiprotocol Gateway, XML Firewall and Web Service Gateway. If you are using API Gateway, then Joseph and Matthias had some ideas on how to solve the issue.



    ------------------------------
    Hermanni Pernaa
    ------------------------------