0

Azure Functions 代理支持在 backendUri 中使用 AppSettings,在 requestOverrides 中使用 request.headers。

{
   "$schema": "http://json.schemastore.org/proxies",
   "proxies": {
      "myProxyName": {
         "matchCondition": {
            "route": "/"
         },
         "backendUri": "%MY_APP_SETTING%",
         "requestOverrides": {
            "backend.request.headers.myCustomHeader":"request.headers.host"
         } 
      }
   }
}

问题:是否可以在 backendUri 中使用 request.header 值?

{
   "$schema": "http://json.schemastore.org/proxies",
   "proxies": {
      "myProxyName": {
         "matchCondition": {
            "route": "/"
         },
         "backendUri": "%MY_APP_SETTING%/{request.headers.my_header_value}"
      }
   }
}
4

1 回答 1

0

是的,可以在后端 uri 中使用 request.header 值。

下面是带有相关信息的示例代码

"Example show how you can",
                "1. Read headers (request.header.<<header name>>), segements({xyz}) and querystring (request.querystring.<<param name>>) from input request ",
                "2. Set the backend headers (backend.request.header.<<header name>>, querystring (backend.request.querystring.<<param name>>)",
                "3. Set the response headers (repsonse.header.<<header name>>), status (response.status)",
                "4. You can use AppSettings in your proxy definitons by enclosing theam with %% For e.g.%APP_SETTING_NAME%",
                "Sample input: https://<<yourhostname>>/test2/1?operation=posts&version=1.2"
            ],
            "matchCondition": {
                "methods": [
                    "GET"
                ],
                "route": "/test2/{uid}"
            },
            "backendUri": "https://jsonplaceholder.typicode.com/users/{uid}/{request.querystring.operation}",
            "requestOverrides": {
                "backend.request.querystring.newkey": "request.header.me",
                "backend.request.querystring.userId": "{uid}",
                "backend.request.querystring.token": "%MY_CUSTOM_TOKEN%",
                "backend.request.header.appname": "Appname is %CUSTOM_SETTING%",
                "backend.request.header.myheaderv": "request.querystring.version"
            }

还要检查Function ProxyBackend URI以及相关讨论。

于 2021-09-16T11:41:34.483 回答