Skip to content

Commit 587a344

Browse files
authored
Merge pull request #1335 from auhlig/requestbuffering
Configurable proxy_request_buffering per location..
2 parents a5084d1 + aa191c8 commit 587a344

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

controllers/nginx/configuration.md

+3
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ log-format-upstream: '{ "time": "$time_iso8601", "remote_addr": "$proxy_protocol
395395

396396
**proxy-next-upstream:** Specifies in [which cases](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream) a request should be passed to the next server.
397397

398+
**proxy-request-buffering:** Enables or disables [buffering of a client request body](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering).
399+
398400
**retry-non-idempotent:** Since 1.9.13 NGINX will not retry non-idempotent requests (POST, LOCK, PATCH) in case of an error in the upstream server.
399401

400402
The previous behavior can be restored using the value "true".
@@ -510,6 +512,7 @@ The following table shows the options, the default value and a description.
510512
|max-worker-connections|"16384"|
511513
|proxy-body-size|same as body-size|
512514
|proxy-buffer-size|"4k"|
515+
|proxy-request-buffering|"on"|
513516
|proxy-connect-timeout|"5"|
514517
|proxy-cookie-domain|"off"|
515518
|proxy-cookie-path|"off"|

controllers/nginx/pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ func NewDefault() Configuration {
422422
ProxyCookieDomain: "off",
423423
ProxyCookiePath: "off",
424424
ProxyNextUpstream: "error timeout invalid_header http_502 http_503 http_504",
425+
ProxyRequestBuffering: "on",
425426
SSLRedirect: true,
426427
CustomHTTPErrors: []int{},
427428
WhitelistSourceRange: []string{},

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ stream {
741741
proxy_buffering off;
742742
proxy_buffer_size "{{ $location.Proxy.BufferSize }}";
743743
proxy_buffers 4 "{{ $location.Proxy.BufferSize }}";
744+
proxy_request_buffering "{{ $location.Proxy.RequestBuffering }}";
744745

745746
proxy_http_version 1.1;
746747

core/pkg/ingress/annotations/proxy/main.go

+30-19
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@ import (
2424
)
2525

2626
const (
27-
bodySize = "ingress.kubernetes.io/proxy-body-size"
28-
connect = "ingress.kubernetes.io/proxy-connect-timeout"
29-
send = "ingress.kubernetes.io/proxy-send-timeout"
30-
read = "ingress.kubernetes.io/proxy-read-timeout"
31-
bufferSize = "ingress.kubernetes.io/proxy-buffer-size"
32-
cookiePath = "ingress.kubernetes.io/proxy-cookie-path"
33-
cookieDomain = "ingress.kubernetes.io/proxy-cookie-domain"
34-
nextUpstream = "ingress.kubernetes.io/proxy-next-upstream"
35-
passParams = "ingress.kubernetes.io/proxy-pass-params"
27+
bodySize = "ingress.kubernetes.io/proxy-body-size"
28+
connect = "ingress.kubernetes.io/proxy-connect-timeout"
29+
send = "ingress.kubernetes.io/proxy-send-timeout"
30+
read = "ingress.kubernetes.io/proxy-read-timeout"
31+
bufferSize = "ingress.kubernetes.io/proxy-buffer-size"
32+
cookiePath = "ingress.kubernetes.io/proxy-cookie-path"
33+
cookieDomain = "ingress.kubernetes.io/proxy-cookie-domain"
34+
nextUpstream = "ingress.kubernetes.io/proxy-next-upstream"
35+
passParams = "ingress.kubernetes.io/proxy-pass-params"
36+
requestBuffering = "ingress.kubernetes.io/proxy-request-buffering"
3637
)
3738

3839
// Configuration returns the proxy timeout to use in the upstream server/s
3940
type Configuration struct {
40-
BodySize string `json:"bodySize"`
41-
ConnectTimeout int `json:"conectTimeout"`
42-
SendTimeout int `json:"sendTimeout"`
43-
ReadTimeout int `json:"readTimeout"`
44-
BufferSize string `json:"bufferSize"`
45-
CookieDomain string `json:"cookieDomain"`
46-
CookiePath string `json:"cookiePath"`
47-
NextUpstream string `json:"nextUpstream"`
48-
PassParams string `json:"passParams"`
41+
BodySize string `json:"bodySize"`
42+
ConnectTimeout int `json:"connectTimeout"`
43+
SendTimeout int `json:"sendTimeout"`
44+
ReadTimeout int `json:"readTimeout"`
45+
BufferSize string `json:"bufferSize"`
46+
CookieDomain string `json:"cookieDomain"`
47+
CookiePath string `json:"cookiePath"`
48+
NextUpstream string `json:"nextUpstream"`
49+
PassParams string `json:"passParams"`
50+
RequestBuffering string `json:"requestBuffering"`
4951
}
5052

5153
// Equal tests for equality between two Configuration types
@@ -84,6 +86,10 @@ func (l1 *Configuration) Equal(l2 *Configuration) bool {
8486
return false
8587
}
8688

89+
if l1.RequestBuffering != l2.RequestBuffering {
90+
return false
91+
}
92+
8793
return true
8894
}
8995

@@ -145,5 +151,10 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
145151
pp = defBackend.ProxyPassParams
146152
}
147153

148-
return &Configuration{bs, ct, st, rt, bufs, cd, cp, nu, pp}, nil
154+
rb, err := parser.GetStringAnnotation(requestBuffering, ing)
155+
if err != nil || rb == "" {
156+
rb = defBackend.ProxyRequestBuffering
157+
}
158+
159+
return &Configuration{bs, ct, st, rt, bufs, cd, cp, nu, pp, rb}, nil
149160
}

core/pkg/ingress/annotations/proxy/main_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
7575
ProxyBodySize: "3k",
7676
ProxyNextUpstream: "error",
7777
ProxyPassParams: "nocanon keepalive=On",
78+
ProxyRequestBuffering: "on",
7879
}
7980
}
8081

@@ -89,6 +90,7 @@ func TestProxy(t *testing.T) {
8990
data[bodySize] = "2k"
9091
data[nextUpstream] = "off"
9192
data[passParams] = "smax=5 max=10"
93+
data[requestBuffering] = "off"
9294
ing.SetAnnotations(data)
9395

9496
i, err := NewParser(mockBackend{}).Parse(ing)
@@ -120,6 +122,9 @@ func TestProxy(t *testing.T) {
120122
if p.PassParams != "smax=5 max=10" {
121123
t.Errorf("expected \"smax=5 max=10\" as pass-params but returned \"%v\"", p.PassParams)
122124
}
125+
if p.RequestBuffering != "off" {
126+
t.Errorf("expected off as request-buffering but returned %v", p.RequestBuffering)
127+
}
123128
}
124129

125130
func TestProxyWithNoAnnotation(t *testing.T) {
@@ -157,4 +162,7 @@ func TestProxyWithNoAnnotation(t *testing.T) {
157162
if p.PassParams != "nocanon keepalive=On" {
158163
t.Errorf("expected \"nocanon keepalive=On\" as pass-params but returned \"%v\"", p.PassParams)
159164
}
165+
if p.RequestBuffering != "on" {
166+
t.Errorf("expected on as request-buffering but returned %v", p.RequestBuffering)
167+
}
160168
}

core/pkg/ingress/defaults/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ type Backend struct {
5656
// Parameters for proxy-pass directive (eg. Apache web server).
5757
ProxyPassParams string `json:"proxy-pass-params"`
5858

59+
// Enables or disables buffering of a client request body.
60+
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering
61+
ProxyRequestBuffering string `json:"proxy-request-buffering"`
62+
5963
// Name server/s used to resolve names of upstream servers into IP addresses.
6064
// The file /etc/resolv.conf is used as DNS resolution configuration.
6165
Resolver []net.IP

0 commit comments

Comments
 (0)