fix: give higher priority to authorizer url

This commit is contained in:
Lakhan Samani 2022-06-05 22:13:10 +05:30
parent 7ac6252aac
commit c6add0cca6

View File

@ -4,9 +4,10 @@ import (
"net/url"
"strings"
"github.com/gin-gonic/gin"
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/memorystore"
"github.com/gin-gonic/gin"
)
// GetHost returns hostname from request context
@ -14,15 +15,15 @@ import (
// if EnvKeyAuthorizerURL is set it is given second highest priority.
// if above 2 are not set the requesting host name is used
func GetHost(c *gin.Context) string {
authorizerURL := c.Request.Header.Get("X-Authorizer-URL")
authorizerURL, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAuthorizerURL)
if err != nil {
authorizerURL = ""
}
if authorizerURL != "" {
return authorizerURL
}
authorizerURL, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyAuthorizerURL)
if err == nil {
authorizerURL = ""
}
authorizerURL = c.Request.Header.Get("X-Authorizer-URL")
if authorizerURL != "" {
return authorizerURL
}