comparison src/http/ngx_http_variables.c @ 7590:06b01840bd42

Core: moved PROXY protocol fields out of ngx_connection_t. Now a new structure ngx_proxy_protocol_t holds these fields. This allows to add more PROXY protocol fields in the future without modifying the connection structure.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 21 Oct 2019 18:06:19 +0300
parents c19ca381b2e6
children 89adf49fe76a
comparison
equal deleted inserted replaced
7589:486d2e0b1b6f 7590:06b01840bd42
1291 1291
1292 static ngx_int_t 1292 static ngx_int_t
1293 ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r, 1293 ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
1294 ngx_http_variable_value_t *v, uintptr_t data) 1294 ngx_http_variable_value_t *v, uintptr_t data)
1295 { 1295 {
1296 v->len = r->connection->proxy_protocol_addr.len; 1296 ngx_proxy_protocol_t *pp;
1297 v->valid = 1; 1297
1298 v->no_cacheable = 0; 1298 pp = r->connection->proxy_protocol;
1299 v->not_found = 0; 1299 if (pp == NULL) {
1300 v->data = r->connection->proxy_protocol_addr.data; 1300 v->not_found = 1;
1301 return NGX_OK;
1302 }
1303
1304 v->len = pp->src_addr.len;
1305 v->valid = 1;
1306 v->no_cacheable = 0;
1307 v->not_found = 0;
1308 v->data = pp->src_addr.data;
1301 1309
1302 return NGX_OK; 1310 return NGX_OK;
1303 } 1311 }
1304 1312
1305 1313
1306 static ngx_int_t 1314 static ngx_int_t
1307 ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r, 1315 ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
1308 ngx_http_variable_value_t *v, uintptr_t data) 1316 ngx_http_variable_value_t *v, uintptr_t data)
1309 { 1317 {
1310 ngx_uint_t port; 1318 ngx_uint_t port;
1319 ngx_proxy_protocol_t *pp;
1320
1321 pp = r->connection->proxy_protocol;
1322 if (pp == NULL) {
1323 v->not_found = 1;
1324 return NGX_OK;
1325 }
1311 1326
1312 v->len = 0; 1327 v->len = 0;
1313 v->valid = 1; 1328 v->valid = 1;
1314 v->no_cacheable = 0; 1329 v->no_cacheable = 0;
1315 v->not_found = 0; 1330 v->not_found = 0;
1317 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); 1332 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
1318 if (v->data == NULL) { 1333 if (v->data == NULL) {
1319 return NGX_ERROR; 1334 return NGX_ERROR;
1320 } 1335 }
1321 1336
1322 port = r->connection->proxy_protocol_port; 1337 port = pp->src_port;
1323 1338
1324 if (port > 0 && port < 65536) { 1339 if (port > 0 && port < 65536) {
1325 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; 1340 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
1326 } 1341 }
1327 1342