From 5f23d5909f18ecc5d0af12cdbb1aee44dccf89ca Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Thu, 2 Jan 2020 13:44:05 +0100 Subject: 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) --- dhall/functions.dhall | 1 - dhall/server/service/plugin/functions.dhall | 1 + dhall/server/service/plugin/http2httpsRedirect.dhall | 15 +++++++++++++++ dhall/types.dhall | 13 ------------- 4 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 dhall/functions.dhall create mode 100644 dhall/server/service/plugin/http2httpsRedirect.dhall delete mode 100644 dhall/types.dhall (limited to 'dhall') 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 -} -- cgit v1.2.3