azure - 在 proxies.json 中使用 Azure Function 设置自定义响应 header

标签 azure azure-functions azure-function-app-proxy

我正在尝试将自定义 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/

相关文章:

c# - 在 Visual Studio 中开发 Azure Function 时存储帐户无效

c# - Azure Function 无法从设置加载 CRON 计时器

azure - 无法从 Web 门户在 Function 应用程序 UI 中看到 Azure Function

azure - 我们如何在具有相同入站和出站 IP 地址的一个网络中托管所有 Azure 资源?

azure-functions - Azure 函数代理返回错误 500

azure - 将旧的 azure 函数 API 迁移到新的 azure 函数而不更改 url

Azure Serverless SQL - 对非分区列性能进行过滤

c# - 无法加载文件或程序集 'XXX' 或其依赖项之一。该系统找不到指定的文件

azure - 如何防止基于存储访问策略的 Azure 存储共享访问签名缓存在浏览器中

c# - 是否可以列出上次修改日期 > 某个日期的 Azure Blob