comparison src/http/ngx_http_variables.c @ 454:a8424ffa495c NGINX_0_7_39

nginx 0.7.39 *) Bugfix: large response with SSI might hang, if gzipping was enabled; the bug had appeared in 0.7.28. Thanks to Artem Bokhan. *) Bugfix: a segmentation fault might occur in worker process, if short static variants are used in a "try_files" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 02 Mar 2009 00:00:00 +0300
parents 76a79816b771
children 98143f74eb3d
comparison
equal deleted inserted replaced
453:9ef0e36f3cd5 454:a8424ffa495c
330 330
331 v = cmcf->variables.elts; 331 v = cmcf->variables.elts;
332 332
333 if (v == NULL) { 333 if (v == NULL) {
334 if (ngx_array_init(&cmcf->variables, cf->pool, 4, 334 if (ngx_array_init(&cmcf->variables, cf->pool, 4,
335 sizeof(ngx_http_variable_t)) == NGX_ERROR) 335 sizeof(ngx_http_variable_t))
336 != NGX_OK)
336 { 337 {
337 return NGX_ERROR; 338 return NGX_ERROR;
338 } 339 }
339 340
340 } else { 341 } else {
954 955
955 static ngx_int_t 956 static ngx_int_t
956 ngx_http_variable_server_port(ngx_http_request_t *r, 957 ngx_http_variable_server_port(ngx_http_request_t *r,
957 ngx_http_variable_value_t *v, uintptr_t data) 958 ngx_http_variable_value_t *v, uintptr_t data)
958 { 959 {
959 v->len = r->port_text->len - 1; 960 ngx_uint_t port;
960 v->valid = 1; 961 struct sockaddr_in *sin;
961 v->no_cacheable = 0; 962 #if (NGX_HAVE_INET6)
962 v->not_found = 0; 963 struct sockaddr_in6 *sin6;
963 v->data = r->port_text->data + 1; 964 #endif
965
966 v->len = 0;
967 v->valid = 1;
968 v->no_cacheable = 0;
969 v->not_found = 0;
970
971 if (ngx_http_server_addr(r, NULL) != NGX_OK) {
972 return NGX_ERROR;
973 }
974
975 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
976 if (v->data == NULL) {
977 return NGX_ERROR;
978 }
979
980 switch (r->connection->local_sockaddr->sa_family) {
981
982 #if (NGX_HAVE_INET6)
983 case AF_INET6:
984 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
985 port = ntohs(sin6->sin6_port);
986 break;
987 #endif
988
989 default: /* AF_INET */
990 sin = (struct sockaddr_in *) r->connection->local_sockaddr;
991 port = ntohs(sin->sin_port);
992 break;
993 }
994
995 if (port > 0 && port < 65536) {
996 v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
997 }
964 998
965 return NGX_OK; 999 return NGX_OK;
966 } 1000 }
967 1001
968 1002
1037 == NULL) 1071 == NULL)
1038 { 1072 {
1039 return NGX_ERROR; 1073 return NGX_ERROR;
1040 } 1074 }
1041 1075
1042 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) 1076 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) {
1043 == NGX_ERROR)
1044 {
1045 return NGX_ERROR; 1077 return NGX_ERROR;
1046 } 1078 }
1047 1079
1048 v->len = path.len; 1080 v->len = path.len;
1049 v->valid = 1; 1081 v->valid = 1;
1078 return NGX_ERROR; 1110 return NGX_ERROR;
1079 } 1111 }
1080 1112
1081 path.data[path.len - 1] = '\0'; 1113 path.data[path.len - 1] = '\0';
1082 1114
1083 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) 1115 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) {
1084 == NGX_ERROR)
1085 {
1086 return NGX_ERROR; 1116 return NGX_ERROR;
1087 } 1117 }
1088 } 1118 }
1089 1119
1090 if (ngx_realpath(path.data, real) == NULL) { 1120 if (ngx_realpath(path.data, real) == NULL) {
1284 1314
1285 static ngx_int_t 1315 static ngx_int_t
1286 ngx_http_variable_sent_location(ngx_http_request_t *r, 1316 ngx_http_variable_sent_location(ngx_http_request_t *r,
1287 ngx_http_variable_value_t *v, uintptr_t data) 1317 ngx_http_variable_value_t *v, uintptr_t data)
1288 { 1318 {
1319 ngx_str_t name;
1320
1289 if (r->headers_out.location) { 1321 if (r->headers_out.location) {
1290 v->len = r->headers_out.location->value.len; 1322 v->len = r->headers_out.location->value.len;
1291 v->valid = 1; 1323 v->valid = 1;
1292 v->no_cacheable = 0; 1324 v->no_cacheable = 0;
1293 v->not_found = 0; 1325 v->not_found = 0;
1294 v->data = r->headers_out.location->value.data; 1326 v->data = r->headers_out.location->value.data;
1295 1327
1296 return NGX_OK; 1328 return NGX_OK;
1297 } 1329 }
1298 1330
1299 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, 1331 name.len = sizeof("sent_http_location") - 1;
1332 name.data = (u_char *) "sent_http_location";
1333
1334 return ngx_http_variable_unknown_header(v, &name,
1300 &r->headers_out.headers.part, 1335 &r->headers_out.headers.part,
1301 sizeof("sent_http_") - 1); 1336 sizeof("sent_http_") - 1);
1302 } 1337 }
1303 1338
1304 1339