comparison src/http/v3/ngx_http_v3_module.c @ 8712:651cc905b7c2 quic

HTTP/3: $http3 variable. A new variable $http3 is added. The variable equals to "h3" for HTTP/3 connections, "hq" for hq connections and is an empty string otherwise. The variable $quic is eliminated. The new variable is similar to $http2 variable.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 01 Dec 2021 11:02:17 +0300
parents be08b858086a
children d6ef13c5fd8e
comparison
equal deleted inserted replaced
8711:be08b858086a 8712:651cc905b7c2
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 11
12 12
13 static ngx_int_t ngx_http_v3_variable_quic(ngx_http_request_t *r, 13 static ngx_int_t ngx_http_v3_variable(ngx_http_request_t *r,
14 ngx_http_variable_value_t *v, uintptr_t data); 14 ngx_http_variable_value_t *v, uintptr_t data);
15 static ngx_int_t ngx_http_v3_add_variables(ngx_conf_t *cf); 15 static ngx_int_t ngx_http_v3_add_variables(ngx_conf_t *cf);
16 static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf); 16 static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf);
17 static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, 17 static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent,
18 void *child); 18 void *child);
233 }; 233 };
234 234
235 235
236 static ngx_http_variable_t ngx_http_v3_vars[] = { 236 static ngx_http_variable_t ngx_http_v3_vars[] = {
237 237
238 { ngx_string("quic"), NULL, ngx_http_v3_variable_quic, 0, 0, 0 }, 238 { ngx_string("http3"), NULL, ngx_http_v3_variable, 0, 0, 0 },
239 239
240 ngx_http_null_variable 240 ngx_http_null_variable
241 }; 241 };
242 242
243 static ngx_str_t ngx_http_quic_salt = ngx_string("ngx_quic"); 243 static ngx_str_t ngx_http_quic_salt = ngx_string("ngx_quic");
244 244
245 245
246 static ngx_int_t 246 static ngx_int_t
247 ngx_http_v3_variable_quic(ngx_http_request_t *r, 247 ngx_http_v3_variable(ngx_http_request_t *r,
248 ngx_http_variable_value_t *v, uintptr_t data) 248 ngx_http_variable_value_t *v, uintptr_t data)
249 { 249 {
250 if (r->connection->quic) { 250 if (r->connection->quic) {
251 251 #if (NGX_HTTP_V3_HQ)
252 v->len = 4; 252
253 ngx_http_v3_srv_conf_t *h3scf;
254
255 h3scf = ngx_http_get_module_srv_conf(r, ngx_http_v3_module);
256
257 if (h3scf->hq) {
258 v->len = sizeof("hq") - 1;
259 v->valid = 1;
260 v->no_cacheable = 0;
261 v->not_found = 0;
262 v->data = (u_char *) "hq";
263
264 return NGX_OK;
265 }
266
267 #endif
268
269 v->len = sizeof("h3") - 1;
253 v->valid = 1; 270 v->valid = 1;
254 v->no_cacheable = 1; 271 v->no_cacheable = 0;
255 v->not_found = 0; 272 v->not_found = 0;
256 v->data = (u_char *) "quic"; 273 v->data = (u_char *) "h3";
274
257 return NGX_OK; 275 return NGX_OK;
258 } 276 }
259 277
260 v->not_found = 1; 278 *v = ngx_http_variable_null_value;
261 279
262 return NGX_OK; 280 return NGX_OK;
263 } 281 }
264 282
265 283