From 1842423297cc8d12e28a014b677c79dfdbaf37db Mon Sep 17 00:00:00 2001 From: zll600 <3400692417@qq.com> Date: Wed, 6 Mar 2024 16:14:31 +0800 Subject: [PATCH] refactor(http3): use http3 instead of quic --- .github/workflows/{quic.yml => http3.yml} | 10 +++++----- apisix/cli/ngx_tpl.lua | 5 ++++- apisix/cli/ops.lua | 20 +++++++++++++------- apisix/cli/schema.lua | 2 +- conf/config-default.yaml | 4 ++-- t/APISIX.pm | 2 +- t/cli/test_main.sh | 8 ++++---- t/{quic => http3}/admin/basic.t | 0 8 files changed, 30 insertions(+), 21 deletions(-) rename .github/workflows/{quic.yml => http3.yml} (97%) rename t/{quic => http3}/admin/basic.t (100%) diff --git a/.github/workflows/quic.yml b/.github/workflows/http3.yml similarity index 97% rename from .github/workflows/quic.yml rename to .github/workflows/http3.yml index abaf39988471..84b450b829ff 100644 --- a/.github/workflows/quic.yml +++ b/.github/workflows/http3.yml @@ -1,4 +1,4 @@ -name: QUIC +name: HTTP/3 on: push: @@ -32,7 +32,7 @@ jobs: - lua-resty-worker-events - lua-resty-events test_dir: - - t/quic/admin + - t/http3/admin runs-on: ${{ matrix.platform }} timeout-minutes: 90 @@ -72,13 +72,13 @@ jobs: id: test_env run: | test_dir="${{ matrix.test_dir }}" - if [[ $test_dir =~ 't/quic/plugin' ]]; then + if [[ $test_dir =~ 't/http3/plugin' ]]; then echo "type=plugin" >>$GITHUB_OUTPUT fi - if [[ $test_dir =~ 't/quic/admin' ]]; then + if [[ $test_dir =~ 't/http3/admin' ]]; then echo "type=first" >>$GITHUB_OUTPUT fi - if [[ $test_dir =~ ' t/quic/xrpc' ]]; then + if [[ $test_dir =~ ' t/http3/xrpc' ]]; then echo "type=last" >>$GITHUB_OUTPUT fi diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index 9642a3605279..8dab5c5a9fca 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -631,12 +631,15 @@ http { {% if enable_http2 then %} http2 on; {% end %} + {% if enable_http3_global then %} + http3 on; + {% end %} {% for _, item in ipairs(node_listen) do %} listen {* item.ip *}:{* item.port *} default_server {% if enable_reuseport then %} reuseport {% end %}; {% end %} {% if ssl.enable then %} {% for _, item in ipairs(ssl.listen) do %} - {% if item.enable_quic then %} + {% if item.enable_http3 then %} listen {* item.ip *}:{* item.port *} quic default_server {% if enable_reuseport then %} reuseport {% end %}; listen {* item.ip *}:{* item.port *} ssl default_server; {% else %} diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua index 73b9c1d1336e..59b3f179b5b9 100644 --- a/apisix/cli/ops.lua +++ b/apisix/cli/ops.lua @@ -380,7 +380,7 @@ Please modify "admin_key" in conf/config.yaml . local ip_port_to_check = {} local function listen_table_insert(listen_table, scheme, ip, port, - enable_http2, enable_quic, enable_ipv6) + enable_http2, enable_http3, enable_ipv6) if type(ip) ~= "string" then util.die(scheme, " listen ip format error, must be string", "\n") end @@ -402,7 +402,7 @@ Please modify "admin_key" in conf/config.yaml . ip = ip, port = port, enable_http2 = enable_http2, - enable_quic = enable_quic + enable_http3 = enable_http3 }) ip_port_to_check[addr] = scheme end @@ -417,7 +417,7 @@ Please modify "admin_key" in conf/config.yaml . ip = ip, port = port, enable_http2 = enable_http2, - enable_quic = enable_quic + enable_http3 = enable_http3 }) ip_port_to_check[addr] = scheme end @@ -466,6 +466,7 @@ Please modify "admin_key" in conf/config.yaml . end yaml_conf.apisix.node_listen = node_listen + local enable_http3_global = false local ssl_listen = {} -- listen in https, support multiple ports, support specific IP for _, value in ipairs(yaml_conf.apisix.ssl.listen) do @@ -473,7 +474,7 @@ Please modify "admin_key" in conf/config.yaml . local port = value.port local enable_ipv6 = false local enable_http2 = value.enable_http2 - local enable_quic = value.enable_quic + local enable_http3 = value.enable_http3 if ip == nil then ip = "0.0.0.0" @@ -493,16 +494,21 @@ Please modify "admin_key" in conf/config.yaml . enable_http2_global = true end - if enable_quic == nil then - enable_quic = false + if enable_http3 == nil then + enable_http3 = false + end + if enable_http3 == true then + enable_http3_global = true end listen_table_insert(ssl_listen, "https", ip, port, - enable_http2, enable_quic, enable_ipv6) + enable_http2, enable_http3, enable_ipv6) end yaml_conf.apisix.ssl.listen = ssl_listen yaml_conf.apisix.enable_http2 = enable_http2_global + yaml_conf.apisix.enable_http3_global = enable_http3_global + if yaml_conf.apisix.ssl.ssl_trusted_certificate ~= nil then local cert_path = yaml_conf.apisix.ssl.ssl_trusted_certificate diff --git a/apisix/cli/schema.lua b/apisix/cli/schema.lua index 3eae5ed75d31..4d1e0470ac74 100644 --- a/apisix/cli/schema.lua +++ b/apisix/cli/schema.lua @@ -221,7 +221,7 @@ local config_schema = { enable_http2 = { type = "boolean", }, - enable_quic = { + enable_http3 = { type = "boolean", }, } diff --git a/conf/config-default.yaml b/conf/config-default.yaml index 7b409a7ba8a0..64bf20b75b00 100755 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -97,11 +97,11 @@ apisix: listen: # APISIX listening port for HTTPS traffic. - port: 9443 enable_http2: true - enable_quic: false # Enable QUIC or HTTP/3. If not set default to `false`. + enable_http3: false # Enable HTTP/3 (with QUIC). If not set default to `false`. # - ip: 127.0.0.3 # If not set, default to `0.0.0.0`. # port: 9445 # enable_http2: true - # enable_quic: true + # enable_http3: true # ssl_trusted_certificate: /path/to/ca-cert # Set the path to CA certificates used to verify client # certificates in the PEM format. ssl_protocols: TLSv1.2 TLSv1.3 # TLS versions supported. diff --git a/t/APISIX.pm b/t/APISIX.pm index 5e61dcf76dec..616057c4bf7b 100644 --- a/t/APISIX.pm +++ b/t/APISIX.pm @@ -671,7 +671,6 @@ _EOC_ $a6_ngx_directives server { - listen 1983 quic reuseport; listen 1983 ssl; ssl_certificate cert/apisix.crt; ssl_certificate_key cert/apisix.key; @@ -730,6 +729,7 @@ _EOC_ listen 1994 quic reuseport; listen 1994 ssl; http2 on; + http3 on; ssl_certificate cert/apisix.crt; ssl_certificate_key cert/apisix.key; lua_ssl_trusted_certificate cert/apisix.crt; diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh index 7248b2c7f527..c18d233ba995 100755 --- a/t/cli/test_main.sh +++ b/t/cli/test_main.sh @@ -142,7 +142,7 @@ apisix: - ip: 127.0.0.4 port: 9445 enable_http2: true - enable_quic: true + enable_http3: true " > conf/config.yaml make init @@ -171,9 +171,9 @@ if [ $count_https_specific_ip_and_enable_http2 -ne 1 ]; then exit 1 fi -count_https_specific_ip_and_enable_quic=`grep -c "listen 127.0.0..:944. quic" conf/nginx.conf || true` -if [ $count_https_specific_ip_and_enable_quic -ne 1 ]; then - echo "failed: failed to support specific IP and enable quic listen in https" +count_https_specific_ip_and_enable_http3=`grep -c "listen 127.0.0..:944. quic" conf/nginx.conf || true` +if [ $count_https_specific_ip_and_enable_http3 -ne 1 ]; then + echo "failed: failed to support specific IP and enable http3 listen in https" exit 1 fi diff --git a/t/quic/admin/basic.t b/t/http3/admin/basic.t similarity index 100% rename from t/quic/admin/basic.t rename to t/http3/admin/basic.t