Mercurial > hg > nginx-quic
changeset 7714:abb7c1a4c9d5 quic
Adedd the http "quic" variable.
The value is literal "quic" for requests passed over HTTP/3, and empty string
otherwise.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Fri, 20 Mar 2020 12:44:45 +0300 |
parents | e9891e8ee975 |
children | 3f4b407fa0b8 |
files | src/http/v3/ngx_http_v3_module.c |
diffstat | 1 files changed, 52 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/v3/ngx_http_v3_module.c +++ b/src/http/v3/ngx_http_v3_module.c @@ -100,13 +100,16 @@ static ngx_command_t ngx_http_v3_comman }; +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) {