Skip to content

Commit

Permalink
fix for rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Huanle Han committed Jan 11, 2021
1 parent 0ffc278 commit 8f14057
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,15 @@ func enforceRegexModifier(input interface{}) bool {

// buildLocation produces the location string, if the ingress has redirects
// (specified through the nginx.ingress.kubernetes.io/rewrite-target annotation)
func buildLocation(input interface{}, enforceRegex bool) string {
func buildLocation(input interface{}, allEnforceRegex bool) string {
location, ok := input.(*ingress.Location)
if !ok {
klog.Errorf("expected an '*ingress.Location' type but %T was returned", input)
return slash
}

enforceRegex := needsRewrite(location) || location.Rewrite.UseRegex

path := location.Path
if enforceRegex {
return fmt.Sprintf(`~* "^%s"`, path)
Expand All @@ -410,8 +412,14 @@ func buildLocation(input interface{}, enforceRegex bool) string {
if location.PathType != nil && *location.PathType == networkingv1beta1.PathTypeExact {
return fmt.Sprintf(`= %s`, path)
}
prefix := ""
if allEnforceRegex {
// if some location other than this is regex, then use "^~ ". so that has a high priority.
prefix = "^~ "

}

return path
return prefix + path
}

func buildAuthLocation(input interface{}, globalExternalAuthURL string) string {
Expand Down

0 comments on commit 8f14057

Please sign in to comment.