0

I have an Azure Function that sits behind a proxy. If an update occurs to the objects that get returned we want to deprecate the Function after a period of time. I'm trying to create a response with the expected content from an HTTP Header by using what was provided in this solution.

Warning: 299 - "Deprecated API"

I try to append the Azure Function like so:

 [FunctionName("MyAPI")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function,
        "post", Route = null)]
        HttpRequestMessage req,
        TraceWriter log)
    {            
        object response = await someService.Get();
        if (settingsService.IsDeprecated)
        {
            var httpresponse = req.CreateResponse(HttpStatusCode.OK, response, "application/json");
            httpresponse.Content.Headers.Add("Warning", "299 - Deprecated API");
            return httpresponse;
        }
        return req.CreateResponse(HttpStatusCode.OK, response, "application/json");
    }

I get the Exception

Exception while executing function: MyAPI -> Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

How do I append the "Deprecated" status warning in my API Http Response?

1 Answer 1

2

Change your line to

httpresponse.Headers.Add("Warning", "299 - \"Deprecated API\"");

The quotes seem to be important there to adhere to the format requirement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.