Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions internal/configs/version2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ type Distribution struct {

// InternalRedirectLocation defines a location for internally redirecting requests to named locations.
type InternalRedirectLocation struct {
Path string
Destination string
Path string
Destination string
ClientMaxBodySize string
}

// Map defines a map.
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ server {

{{- range $l := $s.InternalRedirectLocations }}
location {{ $l.Path }} {
{{- if $l.ClientMaxBodySize }}
client_max_body_size {{ $l.ClientMaxBodySize }};
{{- end }}
rewrite ^ {{ $l.Destination }} last;
}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ server {

{{- range $l := $s.InternalRedirectLocations }}
location {{ $l.Path }} {
{{- if $l.ClientMaxBodySize }}
client_max_body_size {{ $l.ClientMaxBodySize }};
{{- end }}
rewrite ^ {{ $l.Destination }} last;
}
{{- end }}
Expand Down
15 changes: 13 additions & 2 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3067,10 +3067,21 @@ func generateMatchesConfig(route conf_v1.Route, upstreamNamer *upstreamNamer, cr
}
}

// Find any locations with a clientMaxBodySize defined to populate the parent rewrite/redirect location
// See issue #7332 for why this needs to exist on the InternalRedirectLocation struct
var clientMaxBodySize string
for _, l := range locations {
if l.ClientMaxBodySize != "" {
clientMaxBodySize = l.ClientMaxBodySize
break
}
}

// Generate an InternalRedirectLocation to the location defined by the main map variable
irl := version2.InternalRedirectLocation{
Path: route.Path,
Destination: variable,
Path: route.Path,
Destination: variable,
ClientMaxBodySize: clientMaxBodySize,
}

return routingCfg{
Expand Down
71 changes: 71 additions & 0 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,77 @@ func vsEx() VirtualServerEx {
}
}

// TestUpstreamClientMaxBodySizeInInternalRedirect validates that clientMaxBodySize from upstream is present in the InternalRedirectLocation after config generation.
func TestUpstreamClientMaxBodySizeInInternalRedirect(t *testing.T) {
t.Parallel()

vse := VirtualServerEx{
VirtualServer: &conf_v1.VirtualServer{
ObjectMeta: meta_v1.ObjectMeta{
Name: "cafe",
Namespace: "default",
},
Spec: conf_v1.VirtualServerSpec{
Host: "cafe.example.com",
Upstreams: []conf_v1.Upstream{
{
Name: "tea",
Service: "tea-svc",
Port: 80,
ClientMaxBodySize: "7m",
},
},
Routes: []conf_v1.Route{
{
Path: "/tea",
Matches: []conf_v1.Match{
{
Conditions: []conf_v1.Condition{
{
Variable: "$request_method",
Value: "POST",
},
},
Action: &conf_v1.Action{
Proxy: &conf_v1.ActionProxy{
Upstream: "tea",
},
},
},
},
Action: &conf_v1.Action{
Return: &conf_v1.ActionReturn{
Code: 200,
Body: "Hello from cafe",
},
},
},
},
},
},
}

vsc := newVirtualServerConfigurator(&baseCfgParams, true, false, &StaticConfigParams{TLSPassthrough: true}, false, &fakeBV)
vsConfig, warnings := vsc.GenerateVirtualServerConfig(&vse, nil, nil)
if len(warnings) > 0 {
t.Fatalf("unexpected warnings: %v", warnings)
}

// Check InternalRedirectLocations for /tea and validate ClientMaxBodySize
foundIR := false
for _, ir := range vsConfig.Server.InternalRedirectLocations {
if ir.Path == "/tea" {
foundIR = true
if ir.ClientMaxBodySize != "7m" {
t.Errorf("expected InternalRedirectLocation.ClientMaxBodySize to be '7m', got '%s'", ir.ClientMaxBodySize)
}
}
}
if !foundIR {
t.Fatalf("InternalRedirectLocation for /tea not found in generated config")
}
}

func TestGenerateVirtualServerConfigWithBackupForNGINXPlus(t *testing.T) {
t.Parallel()

Expand Down