comparison src/http/ngx_http_variables.c @ 4685:956edecaedeb

New core variable: $status. Contains response status code as a 3-digit integer (with leading zeroes if necessary), or one of the following values: 000 - response status code has not yet been assigned 009 - HTTP/0.9 request is being processed
author Andrey Belov <defan@nginx.com>
date Mon, 18 Jun 2012 13:43:44 +0000
parents 045bb3ef3ffc
children 631eff4a0188
comparison
equal deleted inserted replaced
4684:f5c2c9d656f9 4685:956edecaedeb
76 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r, 76 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
77 ngx_http_variable_value_t *v, uintptr_t data); 77 ngx_http_variable_value_t *v, uintptr_t data);
78 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r, 78 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
79 ngx_http_variable_value_t *v, uintptr_t data); 79 ngx_http_variable_value_t *v, uintptr_t data);
80 80
81 static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,
82 ngx_http_variable_value_t *v, uintptr_t data);
81 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, 83 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
82 ngx_http_variable_value_t *v, uintptr_t data); 84 ngx_http_variable_value_t *v, uintptr_t data);
83 static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r, 85 static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r,
84 ngx_http_variable_value_t *v, uintptr_t data); 86 ngx_http_variable_value_t *v, uintptr_t data);
85 static ngx_int_t ngx_http_variable_sent_location(ngx_http_request_t *r, 87 static ngx_int_t ngx_http_variable_sent_location(ngx_http_request_t *r,
223 225
224 { ngx_string("request_body_file"), NULL, 226 { ngx_string("request_body_file"), NULL,
225 ngx_http_variable_request_body_file, 227 ngx_http_variable_request_body_file,
226 0, 0, 0 }, 228 0, 0, 0 },
227 229
230 { ngx_string("status"), NULL,
231 ngx_http_variable_status, 0,
232 NGX_HTTP_VAR_NOCACHEABLE, 0 },
233
228 { ngx_string("sent_http_content_type"), NULL, 234 { ngx_string("sent_http_content_type"), NULL,
229 ngx_http_variable_sent_content_type, 0, 0, 0 }, 235 ngx_http_variable_sent_content_type, 0, 0, 0 },
230 236
231 { ngx_string("sent_http_content_length"), NULL, 237 { ngx_string("sent_http_content_length"), NULL,
232 ngx_http_variable_sent_content_length, 0, 0, 0 }, 238 ngx_http_variable_sent_content_length, 0, 0, 0 },
1448 v->len = ngx_sprintf(p, "%O", sent) - p; 1454 v->len = ngx_sprintf(p, "%O", sent) - p;
1449 v->valid = 1; 1455 v->valid = 1;
1450 v->no_cacheable = 0; 1456 v->no_cacheable = 0;
1451 v->not_found = 0; 1457 v->not_found = 0;
1452 v->data = p; 1458 v->data = p;
1459
1460 return NGX_OK;
1461 }
1462
1463
1464 static ngx_int_t
1465 ngx_http_variable_status(ngx_http_request_t *r,
1466 ngx_http_variable_value_t *v, uintptr_t data)
1467 {
1468 ngx_uint_t status;
1469
1470 v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN);
1471 if (v->data == NULL) {
1472 return NGX_ERROR;
1473 }
1474
1475 if (r->err_status) {
1476 status = r->err_status;
1477
1478 } else if (r->headers_out.status) {
1479 status = r->headers_out.status;
1480
1481 } else if (r->http_version == NGX_HTTP_VERSION_9) {
1482 status = 9;
1483
1484 } else {
1485 status = 0;
1486 }
1487
1488 v->len = ngx_sprintf(v->data, "%03ui", status) - v->data;
1489 v->valid = 1;
1490 v->no_cacheable = 0;
1491 v->not_found = 0;
1453 1492
1454 return NGX_OK; 1493 return NGX_OK;
1455 } 1494 }
1456 1495
1457 1496