2
votes

I am trying to add a custom HTTP header to all of my responses of my Azure Functions - lets call it X-Custom. Then I add a proxies.json file like this to my functions project:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "add-custom-header-to-response": {
      "matchCondition": {
        "route": "/{*restOfPath}"
      },
      "responseOverrides": {
        "response.headers.X-Custom": "Custom value"
      }
    }
  }
}

And this works as expected, I do get the X-Custom header, but my response content has gone missing. What am I missing in the proxies.json file?

Update

Thanks to Baskar I came to the solution (I was missing 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"
      }
    }
  }
}

Also see:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-proxies#reference-localhost https://docs.microsoft.com/en-us/azure/azure-functions/functions-proxies#route-template-parameters

1

1 Answers

2
votes

Just tested my azure function with the route as "test" and I have overriden my response status code and status description and added custom header. Your proxies.json is missing a function backend 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"
            }
        }
    }
}