aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Belov <defan@nginx.com>2012-06-18 13:43:44 +0000
committerAndrey Belov <defan@nginx.com>2012-06-18 13:43:44 +0000
commite91b210b5674709185d77309272331f009ef9aa4 (patch)
treead8073fb610989d1ac702eec7432b78a06c5e17e /src
parent2c49af818bba9559d977731fa20682781a7f69d0 (diff)
downloadnginx-e91b210b5674709185d77309272331f009ef9aa4.tar.gz
nginx-e91b210b5674709185d77309272331f009ef9aa4.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_log_module.c5
-rw-r--r--src/http/ngx_http_variables.c39
2 files changed, 40 insertions, 4 deletions
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index b3c9a1126..edb145992 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -584,10 +584,7 @@ ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
status = r->headers_out.status;
} else if (r->http_version == NGX_HTTP_VERSION_9) {
- *buf++ = '0';
- *buf++ = '0';
- *buf++ = '9';
- return buf;
+ status = 9;
} else {
status = 0;
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index d9633990c..b56161779 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -78,6 +78,8 @@ static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r,
@@ -225,6 +227,10 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
ngx_http_variable_request_body_file,
0, 0, 0 },
+ { ngx_string("status"), NULL,
+ ngx_http_variable_status, 0,
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
{ ngx_string("sent_http_content_type"), NULL,
ngx_http_variable_sent_content_type, 0, 0, 0 },
@@ -1456,6 +1462,39 @@ ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
static ngx_int_t
+ngx_http_variable_status(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_uint_t status;
+
+ v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN);
+ if (v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ if (r->err_status) {
+ status = r->err_status;
+
+ } else if (r->headers_out.status) {
+ status = r->headers_out.status;
+
+ } else if (r->http_version == NGX_HTTP_VERSION_9) {
+ status = 9;
+
+ } else {
+ status = 0;
+ }
+
+ v->len = ngx_sprintf(v->data, "%03ui", status) - v->data;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_http_variable_sent_content_type(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{