diff src/http/v3/ngx_http_v3_module.c @ 9081:c851a2ed5ce8 quic

HTTP/3: "quic" parameter of "listen" directive. Now "listen" directve has a new "quic" parameter which enables QUIC protocol for the address. Further, to enable HTTP/3, a new directive "http3" is introduced. The hq-interop protocol is enabled by "http3_hq" as before. Now application protocol is chosen by ALPN. Previously used "http3" parameter of "listen" is deprecated.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 27 Feb 2023 14:00:56 +0400
parents b0c2234aaa9f
children b9230e37b8a1
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_module.c
+++ b/src/http/v3/ngx_http_v3_module.c
@@ -32,6 +32,20 @@ static ngx_conf_post_t  ngx_http_quic_mt
 
 static ngx_command_t  ngx_http_v3_commands[] = {
 
+    { ngx_string("http3"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_SRV_CONF_OFFSET,
+      offsetof(ngx_http_v3_srv_conf_t, enable),
+      NULL },
+
+    { ngx_string("http3_hq"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_SRV_CONF_OFFSET,
+      offsetof(ngx_http_v3_srv_conf_t, enable_hq),
+      NULL },
+
     { ngx_string("http3_max_concurrent_pushes"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_num_slot,
@@ -46,15 +60,6 @@ static ngx_command_t  ngx_http_v3_comman
       offsetof(ngx_http_v3_srv_conf_t, max_concurrent_streams),
       NULL },
 
-#if (NGX_HTTP_V3_HQ)
-    { ngx_string("http3_hq"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
-      ngx_conf_set_flag_slot,
-      NGX_HTTP_SRV_CONF_OFFSET,
-      offsetof(ngx_http_v3_srv_conf_t, hq),
-      NULL },
-#endif
-
     { ngx_string("http3_push"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
       ngx_http_v3_push,
@@ -160,14 +165,12 @@ static ngx_int_t
 ngx_http_v3_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)
 {
-    if (r->connection->quic) {
-#if (NGX_HTTP_V3_HQ)
+    ngx_http_v3_session_t  *h3c;
 
-        ngx_http_v3_srv_conf_t  *h3scf;
+    if (r->connection->quic) {
+        h3c = ngx_http_v3_get_session(r->connection);
 
-        h3scf = ngx_http_get_module_srv_conf(r, ngx_http_v3_module);
-
-        if (h3scf->hq) {
+        if (h3c->hq) {
             v->len = sizeof("hq") - 1;
             v->valid = 1;
             v->no_cacheable = 0;
@@ -177,8 +180,6 @@ ngx_http_v3_variable(ngx_http_request_t 
             return NGX_OK;
         }
 
-#endif
-
         v->len = sizeof("h3") - 1;
         v->valid = 1;
         v->no_cacheable = 0;
@@ -232,12 +233,12 @@ ngx_http_v3_create_srv_conf(ngx_conf_t *
      *     h3scf->quic.timeout = 0;
      *     h3scf->max_blocked_streams = 0;
      */
+
+    h3scf->enable = NGX_CONF_UNSET;
+    h3scf->enable_hq = NGX_CONF_UNSET;
     h3scf->max_table_capacity = NGX_HTTP_V3_MAX_TABLE_CAPACITY;
     h3scf->max_concurrent_pushes = NGX_CONF_UNSET_UINT;
     h3scf->max_concurrent_streams = NGX_CONF_UNSET_UINT;
-#if (NGX_HTTP_V3_HQ)
-    h3scf->hq = NGX_CONF_UNSET;
-#endif
 
     h3scf->quic.mtu = NGX_CONF_UNSET_SIZE;
     h3scf->quic.stream_buffer_size = NGX_CONF_UNSET_SIZE;
@@ -264,6 +265,10 @@ ngx_http_v3_merge_srv_conf(ngx_conf_t *c
 
     ngx_http_ssl_srv_conf_t  *sscf;
 
+    ngx_conf_merge_value(conf->enable, prev->enable, 1);
+
+    ngx_conf_merge_value(conf->enable_hq, prev->enable_hq, 0);
+
     ngx_conf_merge_uint_value(conf->max_concurrent_pushes,
                               prev->max_concurrent_pushes, 10);
 
@@ -272,11 +277,6 @@ ngx_http_v3_merge_srv_conf(ngx_conf_t *c
 
     conf->max_blocked_streams = conf->max_concurrent_streams;
 
-#if (NGX_HTTP_V3_HQ)
-    ngx_conf_merge_value(conf->hq, prev->hq, 0);
-#endif
-
-
     ngx_conf_merge_size_value(conf->quic.mtu, prev->quic.mtu,
                               NGX_QUIC_MAX_UDP_PAYLOAD_SIZE);