Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,791 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a simple function that should return the headers, and the headers are empty no matter what I do or try. I've used ChatGPT and Google, and the former is out of ideas, and the latter didn't turn anything up.
Here's the json output:
{
"headers": {}
}
Here's the function.json
:
{
"bindings": [
{
"dataType": "binary",
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"route": "download"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Here's the packages in package.json:
"dependencies": {
"@azure/functions": "^4.0.1",
"@azure/storage-blob": "^12.16.0"
},
Here's the code:
const { app } = require("@azure/functions");
async function download(request, context) {
return {
status: 200,
jsonBody: {
headers: request.headers
}
};
}
app.http(
'download',
{
route: "download",
methods: ['GET'],
authLevel: 'anonymous',
handler: download
}
);
module.exports = download;
@Xavier Hererra The behavior you see if expected and is because the headers
object is not a simple JS object.
You would need to construct a JSON object from it and return that instead. This code should work for you
const headers = Object.fromEntries(request.headers.entries());
return {
jsonBody: {
headers
}
};