Lua: Extract external auth into file. (#12250)
Co-authored-by: Marco Ebert <marco_ebert@icloud.com>
This commit is contained in:
parent
6608eb23b0
commit
7356c4f40f
5 changed files with 40 additions and 28 deletions
|
|
@ -602,17 +602,12 @@ func buildAuthResponseHeaders(proxySetHeader string, headers []string, lua bool)
|
|||
return res
|
||||
}
|
||||
|
||||
func buildAuthUpstreamLuaHeaders(headers []string) []string {
|
||||
res := []string{}
|
||||
|
||||
func buildAuthUpstreamLuaHeaders(headers []string) string {
|
||||
if len(headers) == 0 {
|
||||
return res
|
||||
return ""
|
||||
}
|
||||
|
||||
for i, h := range headers {
|
||||
res = append(res, fmt.Sprintf("ngx.var.authHeader%d = res.header['%s']", i, h))
|
||||
}
|
||||
return res
|
||||
return strings.Join(headers, ",")
|
||||
}
|
||||
|
||||
func buildAuthProxySetHeaders(headers map[string]string) []string {
|
||||
|
|
|
|||
|
|
@ -537,10 +537,7 @@ func TestBuildAuthResponseHeaders(t *testing.T) {
|
|||
|
||||
func TestBuildAuthResponseLua(t *testing.T) {
|
||||
externalAuthResponseHeaders := []string{"h1", "H-With-Caps-And-Dashes"}
|
||||
expected := []string{
|
||||
"ngx.var.authHeader0 = res.header['h1']",
|
||||
"ngx.var.authHeader1 = res.header['H-With-Caps-And-Dashes']",
|
||||
}
|
||||
expected := "h1,H-With-Caps-And-Dashes"
|
||||
|
||||
headers := buildAuthUpstreamLuaHeaders(externalAuthResponseHeaders)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue