From: Paul Bonaud Date: Thu, 2 Jan 2020 12:44:05 +0000 (+0100) Subject: config(dhall): add a pre-function lua definition for HTTPS redirects X-Git-Tag: v0.30^2~3 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=5f23d5909f18ecc5d0af12cdbb1aee44dccf89ca;p=github%2Ffretlink%2Fansible-kong-app.git config(dhall): add a pre-function lua definition for HTTPS redirects This PR fixes #12 and takes precedence over #13 (cherry-picked one of #13's commit) --- diff --git a/dhall/functions.dhall b/dhall/functions.dhall deleted file mode 100644 index 6465760..0000000 --- a/dhall/functions.dhall +++ /dev/null @@ -1 +0,0 @@ -{ Server = ./server/functions.dhall } diff --git a/dhall/server/service/plugin/functions.dhall b/dhall/server/service/plugin/functions.dhall index a7b1295..098fba7 100644 --- a/dhall/server/service/plugin/functions.dhall +++ b/dhall/server/service/plugin/functions.dhall @@ -3,4 +3,5 @@ , mkIPRestriction = ./mkIPRestriction.dhall , correlationId = ./correlationId.dhall , mkPreFunction = ./mkPreFunction.dhall +, http2httpsRedirect = ./http2httpsRedirect.dhall } diff --git a/dhall/server/service/plugin/http2httpsRedirect.dhall b/dhall/server/service/plugin/http2httpsRedirect.dhall new file mode 100644 index 0000000..faa6d79 --- /dev/null +++ b/dhall/server/service/plugin/http2httpsRedirect.dhall @@ -0,0 +1,15 @@ +let mkPreFunction = ./mkPreFunction.dhall + +let luaRedirect = + '' + local scheme = kong.request.get_scheme() + if scheme == "http" then + local host = kong.request.get_host() + local query = kong.request.get_path_with_query() + local url = "https://" .. host ..query + kong.response.set_header("Location", url) + return kong.response.exit(301, url) + end + '' + +in mkPreFunction [ luaRedirect ] diff --git a/dhall/types.dhall b/dhall/types.dhall deleted file mode 100644 index 938dc74..0000000 --- a/dhall/types.dhall +++ /dev/null @@ -1,13 +0,0 @@ -{ Vault = - ./Vault.dhall -, Config = - ./Config.dhall -, Server = - ./server/Server.dhall -, Service = - ./server/service/Service.dhall -, Plugin = - ./server/service/plugin/Plugin.dhall -, Route = - ./server/service/route/Route.dhall -}