Merge pull request #5340 from artemlive/fix/remove-unnecessary-if-in-redirect
fix: remove unnecessary if statement when redirect annotation is defined
This commit is contained in:
commit
55052c0e3d
4 changed files with 6 additions and 24 deletions
|
@ -171,7 +171,6 @@ var (
|
||||||
"proxySetHeader": proxySetHeader,
|
"proxySetHeader": proxySetHeader,
|
||||||
"buildInfluxDB": buildInfluxDB,
|
"buildInfluxDB": buildInfluxDB,
|
||||||
"enforceRegexModifier": enforceRegexModifier,
|
"enforceRegexModifier": enforceRegexModifier,
|
||||||
"stripLocationModifer": stripLocationModifer,
|
|
||||||
"buildCustomErrorDeps": buildCustomErrorDeps,
|
"buildCustomErrorDeps": buildCustomErrorDeps,
|
||||||
"buildCustomErrorLocationsPerServer": buildCustomErrorLocationsPerServer,
|
"buildCustomErrorLocationsPerServer": buildCustomErrorLocationsPerServer,
|
||||||
"shouldLoadModSecurityModule": shouldLoadModSecurityModule,
|
"shouldLoadModSecurityModule": shouldLoadModSecurityModule,
|
||||||
|
@ -373,10 +372,6 @@ func needsRewrite(location *ingress.Location) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripLocationModifer(path string) string {
|
|
||||||
return strings.TrimLeft(path, "~* ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// enforceRegexModifier checks if the "rewrite-target" or "use-regex" annotation
|
// enforceRegexModifier checks if the "rewrite-target" or "use-regex" annotation
|
||||||
// is used on any location path within a server
|
// is used on any location path within a server
|
||||||
func enforceRegexModifier(input interface{}) bool {
|
func enforceRegexModifier(input interface{}) bool {
|
||||||
|
|
|
@ -1221,15 +1221,6 @@ func TestEnforceRegexModifier(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStripLocationModifer(t *testing.T) {
|
|
||||||
expected := "ok.com"
|
|
||||||
actual := stripLocationModifer("~*ok.com")
|
|
||||||
|
|
||||||
if expected != actual {
|
|
||||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestShouldLoadModSecurityModule(t *testing.T) {
|
func TestShouldLoadModSecurityModule(t *testing.T) {
|
||||||
// ### Invalid argument type tests ###
|
// ### Invalid argument type tests ###
|
||||||
// The first tests should return false.
|
// The first tests should return false.
|
||||||
|
|
|
@ -1136,12 +1136,6 @@ stream {
|
||||||
|
|
||||||
{{ buildInfluxDB $location.InfluxDB }}
|
{{ buildInfluxDB $location.InfluxDB }}
|
||||||
|
|
||||||
{{ if not (empty $location.Redirect.URL) }}
|
|
||||||
if ($uri ~* {{ stripLocationModifer $path }}) {
|
|
||||||
return {{ $location.Redirect.Code }} {{ $location.Redirect.URL }};
|
|
||||||
}
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ if isValidByteSize $location.Proxy.BodySize true }}
|
{{ if isValidByteSize $location.Proxy.BodySize true }}
|
||||||
client_max_body_size {{ $location.Proxy.BodySize }};
|
client_max_body_size {{ $location.Proxy.BodySize }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -1267,6 +1261,10 @@ stream {
|
||||||
fastcgi_param {{ $k }} {{ $v | quote }};
|
fastcgi_param {{ $k }} {{ $v | quote }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if not (empty $location.Redirect.URL) }}
|
||||||
|
return {{ $location.Redirect.Code }} {{ $location.Redirect.URL }};
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ buildProxyPass $server.Hostname $all.Backends $location }}
|
{{ buildProxyPass $server.Hostname $all.Backends $location }}
|
||||||
{{ if (or (eq $location.Proxy.ProxyRedirectFrom "default") (eq $location.Proxy.ProxyRedirectFrom "off")) }}
|
{{ if (or (eq $location.Proxy.ProxyRedirectFrom "default") (eq $location.Proxy.ProxyRedirectFrom "off")) }}
|
||||||
proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }};
|
proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }};
|
||||||
|
|
|
@ -46,8 +46,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
|
||||||
|
|
||||||
f.WaitForNginxServer(host,
|
f.WaitForNginxServer(host,
|
||||||
func(server string) bool {
|
func(server string) bool {
|
||||||
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
|
return strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
|
||||||
strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.By("sending request to redirected URL path")
|
ginkgo.By("sending request to redirected URL path")
|
||||||
|
@ -77,8 +76,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
|
||||||
|
|
||||||
f.WaitForNginxServer(host,
|
f.WaitForNginxServer(host,
|
||||||
func(server string) bool {
|
func(server string) bool {
|
||||||
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
|
return strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
|
||||||
strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.By("sending request to redirected URL path")
|
ginkgo.By("sending request to redirected URL path")
|
||||||
|
|
Loading…
Reference in a new issue