You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by st...@apache.org on 2021/05/28 10:07:39 UTC

[apisix] branch master updated: chore: support custom charset parameters in config.yaml (#4331)

This is an automated email from the ASF dual-hosted git repository.

starsz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 7e4ff98  chore: support custom charset parameters in config.yaml (#4331)
7e4ff98 is described below

commit 7e4ff9880db64362675de0436139513585646ef5
Author: Yuelin Zheng <yu...@gmail.com>
AuthorDate: Fri May 28 18:07:30 2021 +0800

    chore: support custom charset parameters in config.yaml (#4331)
---
 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 8de3bd1..71c3e80 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 a48f916..fbccd79 100644
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -195,6 +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, 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 9be93f0..0c01a7e 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: gbk
+' > conf/config.yaml
+
+make init
+
+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 gbk;' in nginx.conf"