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,
|
||||
"buildInfluxDB": buildInfluxDB,
|
||||
"enforceRegexModifier": enforceRegexModifier,
|
||||
"stripLocationModifer": stripLocationModifer,
|
||||
"buildCustomErrorDeps": buildCustomErrorDeps,
|
||||
"buildCustomErrorLocationsPerServer": buildCustomErrorLocationsPerServer,
|
||||
"shouldLoadModSecurityModule": shouldLoadModSecurityModule,
|
||||
|
@ -373,10 +372,6 @@ func needsRewrite(location *ingress.Location) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func stripLocationModifer(path string) string {
|
||||
return strings.TrimLeft(path, "~* ")
|
||||
}
|
||||
|
||||
// enforceRegexModifier checks if the "rewrite-target" or "use-regex" annotation
|
||||
// is used on any location path within a server
|
||||
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) {
|
||||
// ### Invalid argument type tests ###
|
||||
// The first tests should return false.
|
||||
|
|
|
@ -1136,12 +1136,6 @@ stream {
|
|||
|
||||
{{ 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 }}
|
||||
client_max_body_size {{ $location.Proxy.BodySize }};
|
||||
{{ end }}
|
||||
|
@ -1267,6 +1261,10 @@ stream {
|
|||
fastcgi_param {{ $k }} {{ $v | quote }};
|
||||
{{ end }}
|
||||
|
||||
{{ if not (empty $location.Redirect.URL) }}
|
||||
return {{ $location.Redirect.Code }} {{ $location.Redirect.URL }};
|
||||
{{ end }}
|
||||
|
||||
{{ buildProxyPass $server.Hostname $all.Backends $location }}
|
||||
{{ if (or (eq $location.Proxy.ProxyRedirectFrom "default") (eq $location.Proxy.ProxyRedirectFrom "off")) }}
|
||||
proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }};
|
||||
|
|
|
@ -46,8 +46,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
|
||||
strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
|
||||
return strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
|
||||
})
|
||||
|
||||
ginkgo.By("sending request to redirected URL path")
|
||||
|
@ -77,8 +76,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) &&
|
||||
strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
|
||||
return strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
|
||||
})
|
||||
|
||||
ginkgo.By("sending request to redirected URL path")
|
||||
|
|
Loading…
Reference in a new issue