Azure Function golang customHandler HTTP redirect not sent back to client

Rocco Corsi 1 Reputation point
2021-04-23T19:04:00.82+00:00

We are developing a Golang REST API server and have been testing it out in an Azure Function with a customHandler with httpTrigger. Everything was working very well until recently, when we wanted to add authentication when a client was lacking a token (or has invalid token) and want to respond to the client to redirect (with a 302) them back to a Keycloak server (running in a Azure App Service) to make them login.

This golang server is working relatively well outside of Azure Function App, but what appears to be happening is that the redirect is being acted upon in the Function Host that sits in front of our customHandler. We have no logs indicating this is occurring, but we get a 404 Site Not Found when our golang server is 302 redirecting to the Keycloak server.

As a test tried a 302 redirect to https://www.google.com and got a 500 response.

Keycloak server is in a different Azure region from the golang server and has a https://*.azurewebsites.net URL.

We are not using custom domain.

Did attempt to use proxy configuration, but that only appeared to redirect internally and not back to the client. Doesn't appear to be what we want.

We have set to true enableForwardingHttpRequest.

Do Function Apps support this use case?

What are we doing wrong?

Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2021-04-26T15:30:09.317+00:00

    @Rocco Corsi I believe your last comment is spot on after looking at the code in this file - specifically lines #29 and #120. This class is just creating a new HttpClient instance which would use the default HttpClientHandler having AllowAutoRedirect set to true, explaining the behavior that you are seeing. It would be best to raise an issue on the repo to address this.

    In the meantime, you could go with having enableForwardingHttpRequest set to false but would require you to transform between the request and response payload formats (an extra middleware to do this would be simple).


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.