comparison src/http/ngx_http_variables.c @ 6561:28c76d9d75b7

Added the $proxy_protocol_port variable.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 23 May 2016 18:44:21 +0300
parents 59f8f2dd8b31
children b3b7e33083ac
comparison
equal deleted inserted replaced
6560:c90cf79d0e1d 6561:28c76d9d75b7
55 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r, 55 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
56 ngx_http_variable_value_t *v, uintptr_t data); 56 ngx_http_variable_value_t *v, uintptr_t data);
57 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r, 57 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r,
58 ngx_http_variable_value_t *v, uintptr_t data); 58 ngx_http_variable_value_t *v, uintptr_t data);
59 static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r, 59 static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
60 ngx_http_variable_value_t *v, uintptr_t data);
61 static ngx_int_t ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
60 ngx_http_variable_value_t *v, uintptr_t data); 62 ngx_http_variable_value_t *v, uintptr_t data);
61 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r, 63 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,
62 ngx_http_variable_value_t *v, uintptr_t data); 64 ngx_http_variable_value_t *v, uintptr_t data);
63 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r, 65 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,
64 ngx_http_variable_value_t *v, uintptr_t data); 66 ngx_http_variable_value_t *v, uintptr_t data);
192 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 }, 194 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 },
193 195
194 { ngx_string("proxy_protocol_addr"), NULL, 196 { ngx_string("proxy_protocol_addr"), NULL,
195 ngx_http_variable_proxy_protocol_addr, 0, 0, 0 }, 197 ngx_http_variable_proxy_protocol_addr, 0, 0, 0 },
196 198
199 { ngx_string("proxy_protocol_port"), NULL,
200 ngx_http_variable_proxy_protocol_port, 0, 0, 0 },
201
197 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 }, 202 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 },
198 203
199 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 }, 204 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 },
200 205
201 { ngx_string("server_protocol"), NULL, ngx_http_variable_request, 206 { ngx_string("server_protocol"), NULL, ngx_http_variable_request,
1248 v->len = r->connection->proxy_protocol_addr.len; 1253 v->len = r->connection->proxy_protocol_addr.len;
1249 v->valid = 1; 1254 v->valid = 1;
1250 v->no_cacheable = 0; 1255 v->no_cacheable = 0;
1251 v->not_found = 0; 1256 v->not_found = 0;
1252 v->data = r->connection->proxy_protocol_addr.data; 1257 v->data = r->connection->proxy_protocol_addr.data;
1258
1259 return NGX_OK;
1260 }
1261
1262
1263 static ngx_int_t
1264 ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
1265 ngx_http_variable_value_t *v, uintptr_t data)
1266 {
1267 ngx_uint_t port;
1268
1269 v->len = 0;
1270 v->valid = 1;
1271 v->no_cacheable = 0;
1272 v->not_found = 0;
1273
1274 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
1275 if (v->data == NULL) {
1276 return NGX_ERROR;
1277 }
1278
1279 port = r->connection->proxy_protocol_port;
1280
1281 if (port > 0 && port < 65536) {
1282 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
1283 }
1253 1284
1254 return NGX_OK; 1285 return NGX_OK;
1255 } 1286 }
1256 1287
1257 1288