Skip to content

Calculate max capacity for locations slice #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ func createLocations(pathRules []state.PathRule, listenerPort int) []http.Locati
return []http.Location{createDefaultRootLocation()}
}

locs := make([]http.Location, 0, lenPathRules) // FIXME(pleshakov): expand with rule.Routes
// To calculate the maximum number of locations, we need to take into account the following:
// 1. Each match rule for a path rule will have one location.
// 2. Each path rule may have an additional location if it contains non-path-only matches.
// 3. There may be an additional location for the default root path.
maxLocs := 1
for _, rules := range pathRules {
maxLocs += len(rules.MatchRules) + 1
}

locs := make([]http.Location, 0, maxLocs)

rootPathExists := false

Expand Down