I'm trying to transform a json response to xml if the request contains Accept=application/xml. Otherwise, the json response should be returned.
Here's my policy:
<policies>
<inbound><base /></inbound>
<backend><base /></backend>
<outbound>
<base />
<json-to-xml apply="content-type-json" consider-accept-header="true" />
</outbound>
<on-error><base /></on-error>
</policies>
When I test this without an Accept header, all is well (200 OK and json is properly returned).
Adding the accept header, however, I get a 406 Not acceptable.
The trace (after adding the header Ocp-Apim-Trace:true), redacted is available at https://gist.github.com/jhgbrt/9df92cb0a140804ea01c. In that trace, you will see the following:
- in the 'inbound' part confirm the request header 'Accept' with value 'application/xml' is present. The
request-executor
block contains a message saying "Request is being forwarded to the backend service." - in the 'outbound' block you already see the 406 not acceptable and the Accept header removed, after which the json-to-xml block fails because of this.
What am I missing?