Hello All,
We are dealing with CORS based http request ( An Ajax call from the front end web application) so to handle I have written 2 rules :
1) This is to allow only options method and send back expected response headers and loop back without reaching backend.
2) This is the business rule to allow only post method and call the backend . This also goes fine.
But while connecting backend URL I'm seeing the below Errors and the error rule is getting executed for the same :
******************************************************************************************************************
Backside Header ('N/A') failed to parse due to http client /server error URL : *****.com
Error occurred when connecting to URL : ****.com
Http invalid Response returned 400 BAD request from URL : ****.com.
Is this has got something to do with passing CORS based headers to the backend ? . I'm just passing through the request to the back as it is . Could you please let me know incase this has got anything to with CORS based request / headers .
------------------------------
Nikhil Bachu
------------------------------
Original Message:
Sent: Tue February 12, 2019 12:34 PM
From: Babu K
Subject: Can datapower handle preflight or CORS request ?
I added this stylesheet for CORS in my flow. wherever it is needed error or response
<xsl:template match="/">
<dp:set-http-response-header name="'Access-Control-Allow-Origin'" value="'*'"/>
<dp:set-http-response-header name="'Access-Control-Allow-Credentials'" value="'true'"/>
<xsl:if test="normalize-space(dp:variable('var://service/protocol-method')) = 'OPTIONS'">
<dp:set-http-response-header name="'Access-Control-Allow-Methods'" value="'POST,GET,PUT,OPTIONS'"/>
<dp:set-http-response-header name="'Access-Control-Allow-Headers'" value="dp:http-request-header('Access-Control-Request-Headers')"/>
<dp:set-variable name="'var://service/error-protocol-response'" value="'200'"/>
<dp:set-variable name="'var://service/error-protocol-reason-phrase'" value="'OK'"/>
</xsl:if>
</xsl:template>
------------------------------
Babu K
------------------------------