Allow preservation of trailing slashes on TLS redirects via annotation. (#7144)

* allow retaining a trailing slash in a TLS redirect via annotation.

Signed-off-by: mamiller <mamiller@rosettastone.com>

* requested changes

* gofmt
This commit is contained in:
Matt Miller 2021-05-23 11:51:38 -04:00 committed by GitHub
parent f7cba2486c
commit b3dfee6ada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 3 deletions

View file

@ -147,9 +147,11 @@ function _M.rewrite(location_config)
if redirect_to_https(location_config) then
local request_uri = ngx.var.request_uri
-- do not append a trailing slash on redirects
if string.sub(request_uri, -1) == "/" then
request_uri = string.sub(request_uri, 1, -2)
-- do not append a trailing slash on redirects unless enabled by annotations
if location_config.preserve_trailing_slash == false then
if string.byte(request_uri, -1, -1) == string.byte('/') then
request_uri = string.sub(request_uri, 1, -2)
end
end
local uri = string_format("https://%s%s", redirect_host(), request_uri)