IBM Support

IBM WebSphere DataPower SOA Appliances injects Content-Type as "text/xml" if the client or server does not set this header which may cause unexpected behavior

Technote (troubleshooting)


Problem(Abstract)

When a request or response message header does not contain the Content-Type header, IBM WebSphere DataPower SOA Appliances adds "text/xml" as the Content-Type header. If the message does not match the content type, the front end client or back end server may fail to process the message as expected.

Symptom

The following is an example of this issue:

  • A Multi-Protocol Gateway service is used.
  • A back end server returns a html file to be displayed by a browser.
  • The response message does not contain a Content-Type header.
  • The Multi-Protocol Gateway Policy contains a response rule with a Results action.
  • When processing the Result action, IBM WebSphere DataPower SOA Appliances injects a Content-Type with a value of "text/xml" due to the missing Content-Type header.
  • The browser is unable to successfully display the html file due to the Content-Type setting of "text/xml". The source of the html file is displayed instead.

Cause

It is considered a best practice for applications to ensure the correct Content-Type value is set in the message header.
The IBM WebSphere DataPower SOA Appliance Result action is designed to inject "text/xml" as the Content-Type if the Content-Type is not provided.


Resolving the problem

If the information provided does not help resolve your issue, or you have any questions regarding this information, please contact IBM WebSphere DataPower SOA Appliances Support for assistance.

When it is not possible for your application to set the Content-Type, the following are possible options to prevent IBM WebSphere DataPower SOA Appliances from injecting the Content-Type of "text/xml".

The example, using a Multi-Protocol Gateway service, where a back end server returns a message without a Content-Type header, and the payload is a html file to be displayed by a browser, is used when explaining some of the options below.

  • In the Multi-Protocol Gateway Policy's rule, if the Result action is not needed, remove it.
  • In the Multi-Protocol Gateway, if the response or request message does not need to be changed, change the Response Type or Request Type to Pass-Thru. For the example provided, the Response Type is set to Pass-Thru to resolve this issue.
  • In the Multi-Protocol Gateway, use the HTTP Header Injection tab to inject a Content-Type header with the value that is needed by the front end or back end. For the example provided, the following are the values used for the header injection:
    • Direction: Client
    • Header Name: content-type
    • Header Value: text/html
  • In the Multi-Protocol Gateway Policy's rule, if there is a Transform action before the Result action, and the output of the Transform action can be set to PIPE, add the following line to the Transform action's XSLT:

      <xsl:output method="html"/>

    after the

      <xsl:stylesheet>

    root element. For example:


         <xsl:stylesheet version="1.0"
           .                                                              
           .
           <xsl:output method="html" />                                    
             <xsl:template match="/">                                      
             .                                                            
             .
  • In the Multi-Protocol Gateway Policy's rule, add a Set Variable action to the rule before the Result action. For the example provided, the variable is set to:

      var://service/set-response-header/content-type

    and the value is set to:

      text/html

  • In the Multi-Protocol Gateway Policy's rule, set the content type explicitly on that context before the Result action. If the options provided above do not work for your scenario, you could use a stylesheet that only injects the header if none exists. At a high level, for the example provided, the stylesheet would:
    1. Use the dp:response-header("Content-Type") function to get the incoming response header Content-Type.
    2. Test if the value is equal to zero.
    3. Use the dp:set-response-header()function to inject the content-type with a value text/html if the value is not specified.
    Note: Setting the Result action's Output Type to Binary has no bearing on whether the "text/xml" Content-Type header is injected or not.


    Refer to the library page and search in the product documentation for more information on HTTP Header Injection or the response-header and set-response-header functions.

    Again, if the information provided does not help resolve your issue, or you have any questions regarding this information, please Contact IBM WebSphere DataPower SOA Appliances Support for assistance.

    Document information

    More support for: IBM DataPower Gateways
    General

    Software version: 4.0.1, 4.0.2, 5.0.0, 6.0.0

    Operating system(s): Firmware

    Reference #: 1470992

    Modified date: 28 February 2012