Skip to content

Commit 4c86ee2

Browse files
authored
Add flag --client_body_timeout (#765)
1 parent 026dc53 commit 4c86ee2

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

start_esp/nginx-auto.conf.template

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ http {
5151
server_tokens off;
5252
client_max_body_size ${client_max_body_size};
5353
client_body_buffer_size ${client_body_buffer_size};
54+
% if client_body_timeout:
55+
client_body_timeout ${client_body_timeout};
56+
% endif
5457
% if large_client_header_buffers:
5558
large_client_header_buffers ${large_client_header_buffers};
5659
% endif

start_esp/start_esp.py

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def write_nginx_conf(ingress, nginx_conf, args):
150150
enable_backend_routing=args.enable_backend_routing,
151151
client_max_body_size=args.client_max_body_size,
152152
client_body_buffer_size=args.client_body_buffer_size,
153+
client_body_timeout=args.client_body_timeout,
153154
large_client_header_buffers=args.large_client_header_buffers,
154155
keepalive_timeout=args.keepalive_timeout,
155156
worker_processes=args.worker_processes,
@@ -649,6 +650,11 @@ def make_argparser():
649650
http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout.
650651
''')
651652

653+
parser.add_argument('--client_body_timeout', default=None, help='''
654+
Sets the timeout for reading client request body. This flag will pass to Nginx config directly.
655+
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout.
656+
''')
657+
652658
parser.add_argument('--rewrite', action='append', help=
653659
'''Internally redirect the request uri with a pair of pattern and
654660
replacement. Pattern and replacement should be separated by whitespace.

start_esp/test/start_esp_test.py

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def test_keepalive_timeout_output_is_as_expected(self):
153153
config_generator = self.basic_config_generator + " --keepalive_timeout=600s"
154154
self.run_test_with_expectation(expected_config_file, self.generated_nginx_config_file, config_generator)
155155

156+
def test_client_body_timeout_output_is_as_expected(self):
157+
expected_config_file = "./start_esp/test/testdata/expected_client_body_timeout_nginx.conf"
158+
config_generator = self.basic_config_generator + " --client_body_timeout=86600s"
159+
self.run_test_with_expectation(expected_config_file, self.generated_nginx_config_file, config_generator)
160+
156161
def test_allow_invalid_headers_arg_output_is_as_expected(self):
157162
expected_config_file = "./start_esp/test/testdata/expected_allow_invalid_headers_nginx.conf"
158163
config_generator = self.basic_config_generator + " --allow_invalid_headers"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Auto-generated by start_esp
2+
# Copyright (C) Extensible Service Proxy Authors
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
# 1. Redistributions of source code must retain the above copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
# SUCH DAMAGE.
25+
26+
daemon off;
27+
28+
user nginx nginx;
29+
30+
pid ./start_esp/test/pid_file;
31+
32+
# Worker/connection processing limits
33+
worker_processes 1;
34+
worker_rlimit_nofile 10240;
35+
events { worker_connections 10240; }
36+
37+
# Logging to stderr enables better integration with Docker and GKE/Kubernetes.
38+
error_log stderr warn;
39+
40+
http {
41+
include /etc/nginx/mime.types;
42+
include /etc/nginx/conf/*.conf;
43+
server_tokens off;
44+
client_max_body_size 32m;
45+
client_body_buffer_size 128k;
46+
client_body_timeout 86600s;
47+
48+
# HTTP subrequests
49+
endpoints_resolver 8.8.8.8;
50+
endpoints_certificates /etc/nginx/trusted-ca-certificates.crt;
51+
52+
upstream app_server0 {
53+
server 127.0.0.1:8081;
54+
keepalive 128;
55+
}
56+
57+
set_real_ip_from 0.0.0.0/0;
58+
set_real_ip_from 0::/0;
59+
real_ip_header X-Forwarded-For;
60+
real_ip_recursive on;
61+
62+
63+
server {
64+
server_name "";
65+
resolver 8.8.8.8;
66+
67+
68+
listen 8080 backlog=16384;
69+
70+
access_log /dev/stdout;
71+
72+
73+
74+
75+
location / {
76+
# Begin Endpoints v2 Support
77+
endpoints {
78+
on;
79+
server_config /etc/nginx/server_config.pb.txt;
80+
google_authentication_secret key;
81+
metadata_server http://169.254.169.254;
82+
}
83+
# End Endpoints v2 Support
84+
85+
86+
87+
proxy_pass http://app_server0;
88+
proxy_redirect off;
89+
proxy_set_header Host $host;
90+
proxy_set_header X-Real-IP $remote_addr;
91+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
92+
proxy_set_header X-Forwarded-Host $server_name;
93+
proxy_set_header X-Google-Real-IP $remote_addr;
94+
95+
# Enable the upstream persistent connection
96+
proxy_http_version 1.1;
97+
proxy_set_header Connection "";
98+
99+
# 86400 seconds (24 hours) is the maximum a server is allowed.
100+
proxy_send_timeout 86400s;
101+
proxy_read_timeout 86400s;
102+
}
103+
104+
include /var/lib/nginx/extra/*.conf;
105+
}
106+
107+
server {
108+
# expose /nginx_status and /endpoints_status but on a different port to
109+
# avoid external visibility / conflicts with the app.
110+
listen 8090;
111+
location /nginx_status {
112+
stub_status on;
113+
access_log off;
114+
}
115+
location /endpoints_status {
116+
endpoints_status;
117+
access_log off;
118+
}
119+
location /healthz {
120+
return 200;
121+
access_log off;
122+
}
123+
location / {
124+
root /dev/null;
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)