我正在尝试将自定义 HTTP header 添加到我的 Azure Functions 的所有响应中 - 我们将其称为 X-Custom。然后我将这样的 proxies.json 文件添加到我的函数项目中:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"add-custom-header-to-response": {
"matchCondition": {
"route": "/{*restOfPath}"
},
"responseOverrides": {
"response.headers.X-Custom": "Custom value"
}
}
}
}
这按预期工作,我确实得到了 X-Custom header ,但我的响应内容丢失了。 proxies.json 文件中缺少什么?
更新
感谢 Baskar,我找到了解决方案(我缺少 backendUri):
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"add-custom-header-to-response": {
"matchCondition": {
"route": "/api/1/{*restOfPath}"
},
"backendUri": "https://localhost/api/1/{restOfPath}",
"responseOverrides": {
"response.headers.X-Custom": "Custom value"
}
}
}
}
另请参阅:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies#reference-localhost https://learn.microsoft.com/en-us/azure/azure-functions/functions-proxies#route-template-parameters
最佳答案
刚刚使用“测试”路由测试了我的 azure 功能,并且我已经覆盖了我的响应状态代码和状态描述并添加了自定义 header 。您的 proxies.json 缺少函数后端 url。
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"test": {
"matchCondition": {
"route": "test"
},
"backendUri": "https://testbasenewtest.azurewebsites.net/api/HttpTrigger1",
"responseOverrides": {
"response.statusCode": "200",
"response.statusReason": "Successful Response",
"response.headers.API_Login": "custom"
}
}
}
}
关于azure - 在 proxies.json 中使用 Azure Function 设置自定义响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52928268/