summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_variables.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2012-07-02 16:53:36 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2012-07-02 16:53:36 +0000
commitc7fcd1e78a0af29d8242ba47a54b3651eeacf0e8 (patch)
tree100bb69bd4e9a5e1cecbab9a1edb65330fdb8549 /src/http/ngx_http_variables.c
parent7138ca1704831157e6cea929c3f87185016e0d17 (diff)
downloadnginx-c7fcd1e78a0af29d8242ba47a54b3651eeacf0e8.tar.gz
nginx-c7fcd1e78a0af29d8242ba47a54b3651eeacf0e8.tar.bz2
Merge of r4686, r4687: $status variable.
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 '')
-rw-r--r--src/http/ngx_http_variables.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index d9633990c..76b292553 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -77,6 +77,8 @@ static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
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);
@@ -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)
{