From eedc8ed92f8c8054cbd4e57da7495277c97bf20a Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Fri, 28 May 2021 15:02:03 +0800 Subject: [PATCH 1/2] chore: support custom charset parameters in config.yaml close #4302 --- apisix/cli/ngx_tpl.lua | 2 +- conf/config-default.yaml | 2 ++ t/cli/test_main.sh | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index 8de3bd1a1309..71c3e80c3642 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -217,7 +217,7 @@ http { server_tokens off; include mime.types; - charset utf-8; + charset {* http.charset *}; # error_page error_page 500 @50x.html; diff --git a/conf/config-default.yaml b/conf/config-default.yaml index a48f91611048..f65274332cc1 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -196,6 +196,8 @@ nginx_config: # config for render the template to generate n # After the maximum number of requests is made, the connection is closed. keepalive_timeout: 60s # Sets a timeout during which an idle keepalive connection to an upstream server will stay open. + charset: utf-8 # Adds the specified charset to the "Content-Type" response header field. + etcd: host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. - "http://127.0.0.1:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme, diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh index 9be93f029edf..626e35ab73b5 100755 --- a/t/cli/test_main.sh +++ b/t/cli/test_main.sh @@ -621,3 +621,21 @@ if ! grep "keepalive_timeout 6s;" conf/nginx.conf > /dev/null; then fi echo "passed: found the keepalive related parameter in nginx.conf" + +# check the charset setting +git checkout conf/config.yaml + +echo ' +nginx_config: + http: + charset: utf-8 +' > conf/config.yaml + +make init + +if ! grep "charset utf-8;" conf/nginx.conf > /dev/null; then + echo "failed: 'charset utf-8;' not in nginx.conf" + exit 1 +fi + +echo "passed: found the 'charset utf-8;' in nginx.conf" From 3375ba44801ddff4be54dd2be95b594a7aafc4e9 Mon Sep 17 00:00:00 2001 From: Firstsawyou Date: Fri, 28 May 2021 15:42:13 +0800 Subject: [PATCH 2/2] update test and add link --- conf/config-default.yaml | 4 ++-- t/cli/test_main.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/config-default.yaml b/conf/config-default.yaml index f65274332cc1..fbccd79ae3ab 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -195,8 +195,8 @@ nginx_config: # config for render the template to generate n keepalive_requests: 1000 # Sets the maximum number of requests that can be served through one keepalive connection. # After the maximum number of requests is made, the connection is closed. keepalive_timeout: 60s # Sets a timeout during which an idle keepalive connection to an upstream server will stay open. - - charset: utf-8 # Adds the specified charset to the "Content-Type" response header field. + charset: utf-8 # Adds the specified charset to the "Content-Type" response header field, see + # http://nginx.org/en/docs/http/ngx_http_charset_module.html#charset etcd: host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh index 626e35ab73b5..0c01a7ee46bc 100755 --- a/t/cli/test_main.sh +++ b/t/cli/test_main.sh @@ -628,14 +628,14 @@ git checkout conf/config.yaml echo ' nginx_config: http: - charset: utf-8 + charset: gbk ' > conf/config.yaml make init -if ! grep "charset utf-8;" conf/nginx.conf > /dev/null; then - echo "failed: 'charset utf-8;' not in nginx.conf" +if ! grep "charset gbk;" conf/nginx.conf > /dev/null; then + echo "failed: 'charset gbk;' not in nginx.conf" exit 1 fi -echo "passed: found the 'charset utf-8;' in nginx.conf" +echo "passed: found the 'charset gbk;' in nginx.conf"