Last active
June 17, 2022 12:53
-
-
Save tazarov/1d31ef7308de1a49f678677a79c6bc5a to your computer and use it in GitHub Desktop.
Kong pre/post-function collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Problem: sometimes the remote server will return a http:// url and browser gets redirected to a non-https url even though it is accessing https endpoint | |
-- This post-function snippet in Kong helps you overwrite the http part in Location header. | |
if kong.response.get_status() == 302 and kong.response.get_header("location") ~= "^http" then | |
local new_loc = kong.response.get_header("Location"):gsub("http","https") | |
kong.response.set_header("Location",new_loc) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Problem: Some servers don't always redirect you to index.html (e.g. static sites served by non-public s3 bucket) | |
-- This pre-function will redirect the request to index.html when / is accessed | |
if kong.request.get_path() == "/" then | |
kong.service.request.set_path("/index.html") | |
kong.response.set_header("Location","/index.html") | |
return kong.response.exit(301,"/index.html") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment