Adedd the http "quic" variable.

The value is literal "quic" for requests passed over HTTP/3, and empty string
otherwise.
This commit is contained in:
Vladimir Homutov 2020-03-20 12:44:45 +03:00
parent 30de0ca52d
commit 4096676897

View File

@ -100,13 +100,16 @@ static ngx_command_t ngx_http_v3_commands[] = {
};
static ngx_int_t ngx_http_variable_quic(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_v3_add_variables(ngx_conf_t *cf);
static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf,
void *parent, void *child);
static ngx_http_module_t ngx_http_v3_module_ctx = {
NULL, /* preconfiguration */
ngx_http_v3_add_variables, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
@ -136,6 +139,54 @@ ngx_module_t ngx_http_v3_module = {
};
static ngx_http_variable_t ngx_http_v3_vars[] = {
{ ngx_string("quic"), NULL, ngx_http_variable_quic,
0, 0, 0 },
ngx_http_null_variable
};
static ngx_int_t
ngx_http_variable_quic(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
if (r->connection->qs) {
v->len = 4;
v->valid = 1;
v->no_cacheable = 1;
v->not_found = 0;
v->data = (u_char *) "quic";
return NGX_OK;
}
v->not_found = 1;
return NGX_OK;
}
static ngx_int_t
ngx_http_v3_add_variables(ngx_conf_t *cf)
{
ngx_http_variable_t *var, *v;
for (v = ngx_http_v3_vars; v->name.len; v++) {
var = ngx_http_add_variable(cf, &v->name, v->flags);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = v->get_handler;
var->data = v->data;
}
return NGX_OK;
}
static void *
ngx_http_v3_create_srv_conf(ngx_conf_t *cf)
{