Please provide the following:
Provide the steps required to reproduce the problem:
module.exports = (ctx, req) => {
ctx.res = {
headers: {
'Access-Control-Allow-Origin': req.headers.origin,
// ... Set other Access-Control headers
},
status: 204,
//body: '' <-- Adding this results in expected behaviour
};
ctx.done();
};
Response has status 204 and Access-Control headers
Response has status 200, no Access-Control headers and the following JSON encoded body:
{
"headers": { "Access-Control-Allow-Origin": "..." },
"status": 204
}
If I add a body property to ctx.res with an empty string value, I get the expected result.
I see this when running locally using the preview version of the cli on OSX.
Weird. I wonder if we somehow have a code path that if there is no body returned just assumes there was no response. I'll check into this.
Something like this has existed for awhile,
e.g. Slightly different, but very similar:
https://stackoverflow.com/questions/41709910/azure-functions-nodejs-http-response-renders-as-xml-rather-than-http-response/41709911#41709911
Nice, two repros is helpful.
Could be the root cause of https://github.com/Azure/azure-functions-host/issues/2578 as well, where using v2.1.2 of node-fetch appears to return the wrong body (some bad assumption is being made).
Root cause of this issue is https://github.com/Azure/azure-functions-host/issues/997
To summarize, an http response is created in two ways:
context.res = bodyValue; // res is interpreted as 200 with body bodyValuecontext.res = { body: bodyValue, headers: ..., status: ... } // res is fully specified objectCode assumes that a context.res object without a "body" property = bodyValue