comparison src/http/v3/ngx_http_v3_module.c @ 8248: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 d45325e90221
comparison
equal deleted inserted replaced
8247:e9891e8ee975 8248:abb7c1a4c9d5
98 98
99 ngx_null_command 99 ngx_null_command
100 }; 100 };
101 101
102 102
103 static ngx_int_t ngx_http_variable_quic(ngx_http_request_t *r,
104 ngx_http_variable_value_t *v, uintptr_t data);
105 static ngx_int_t ngx_http_v3_add_variables(ngx_conf_t *cf);
103 static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf); 106 static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf);
104 static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, 107 static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf,
105 void *parent, void *child); 108 void *parent, void *child);
106 109
107 110
108 static ngx_http_module_t ngx_http_v3_module_ctx = { 111 static ngx_http_module_t ngx_http_v3_module_ctx = {
109 NULL, /* preconfiguration */ 112 ngx_http_v3_add_variables, /* preconfiguration */
110 NULL, /* postconfiguration */ 113 NULL, /* postconfiguration */
111 114
112 NULL, /* create main configuration */ 115 NULL, /* create main configuration */
113 NULL, /* init main configuration */ 116 NULL, /* init main configuration */
114 117
134 NULL, /* exit master */ 137 NULL, /* exit master */
135 NGX_MODULE_V1_PADDING 138 NGX_MODULE_V1_PADDING
136 }; 139 };
137 140
138 141
142 static ngx_http_variable_t ngx_http_v3_vars[] = {
143 { ngx_string("quic"), NULL, ngx_http_variable_quic,
144 0, 0, 0 },
145
146 ngx_http_null_variable
147 };
148
149
150 static ngx_int_t
151 ngx_http_variable_quic(ngx_http_request_t *r,
152 ngx_http_variable_value_t *v, uintptr_t data)
153 {
154 if (r->connection->qs) {
155
156 v->len = 4;
157 v->valid = 1;
158 v->no_cacheable = 1;
159 v->not_found = 0;
160 v->data = (u_char *) "quic";
161 return NGX_OK;
162 }
163
164 v->not_found = 1;
165
166 return NGX_OK;
167 }
168
169
170 static ngx_int_t
171 ngx_http_v3_add_variables(ngx_conf_t *cf)
172 {
173 ngx_http_variable_t *var, *v;
174
175 for (v = ngx_http_v3_vars; v->name.len; v++) {
176 var = ngx_http_add_variable(cf, &v->name, v->flags);
177 if (var == NULL) {
178 return NGX_ERROR;
179 }
180
181 var->get_handler = v->get_handler;
182 var->data = v->data;
183 }
184
185 return NGX_OK;
186 }
187
188
189
139 static void * 190 static void *
140 ngx_http_v3_create_srv_conf(ngx_conf_t *cf) 191 ngx_http_v3_create_srv_conf(ngx_conf_t *cf)
141 { 192 {
142 ngx_http_v3_srv_conf_t *v3cf; 193 ngx_http_v3_srv_conf_t *v3cf;
143 194