Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js HTTP triggered function cannot return XML #942

Closed
dprothero opened this issue Nov 17, 2016 · 1 comment
Closed

Node.js HTTP triggered function cannot return XML #942

dprothero opened this issue Nov 17, 2016 · 1 comment

Comments

@dprothero
Copy link

When you set the Content-Type header to 'text/xml' and the body to some valid XML, the actual response of the function is <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">[escaped xml here]</string>

Repro steps

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    context.res.set('Content-Type', 'text/xml');
    context.res.body = '<?xml version="1.0" encoding="UTF-8"?><Response><Message>Hi there!' + 
        '</Message></Response>';
    context.done();
};

function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "disabled": false
}

Expected behavior

I would expect the Content-Type header to be text/xml and the body of the response to contain my XML and nothing else.

Actual behavior

The actual response of the function is <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">[escaped xml here]</string>

Known workarounds

If I set the Content-Type to 'text/html', it leaves my XML body unmolested. The content type isn't right, but Twilio will accept text/html. Other use cases requiring XML output may not have this workaround.

@paulbatum
Copy link
Member

See #965. This scenario is enabled by using the isRaw flag. Sample from the linked issue:

  context.res = {
            status: 200,
            body: '<root>body</root>',
            headers: {
                'Content-Type': 'text/xml'
            },
            isRaw: true
        }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants