]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/blobdiff - dhall/server/service/plugin/http2httpsRedirect.dhall
config(dhall): add a pre-function lua definition for HTTPS redirects
[github/fretlink/ansible-kong-app.git] / dhall / server / service / plugin / http2httpsRedirect.dhall
diff --git a/dhall/server/service/plugin/http2httpsRedirect.dhall b/dhall/server/service/plugin/http2httpsRedirect.dhall
new file mode 100644 (file)
index 0000000..faa6d79
--- /dev/null
@@ -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 ]